2023-10-11 10:55:51 +10:00
name : Write test failure comment
2024-01-21 15:20:21 +01:00
concurrency :
group : ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress : true
2023-10-11 10:55:51 +10:00
on :
workflow_run :
workflows : [ 🧪 QGIS tests]
types :
- completed
2023-12-05 07:16:50 +10:00
branches-ignore :
- 'master'
- 'release*'
2023-10-11 10:55:51 +10:00
2024-01-21 15:35:52 +01:00
permissions :
contents : read
2023-10-11 10:55:51 +10:00
jobs :
on-failure :
2023-10-25 09:53:53 +08:00
strategy :
matrix :
qt-version : [ 5 , 6 ]
runs-on : ubuntu-latest
steps :
- name : 'Download artifact'
2023-11-27 19:41:12 +10:00
id : download_artifact
2023-12-01 23:56:37 +00:00
uses : actions/github-script@v7
2023-10-25 09:53:53 +08:00
with :
script : |
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner : context.repo.owner,
repo : context.repo.repo,
run_id : context.payload.workflow_run.id,
});
2023-12-01 17:33:06 +10:00
let matchArtifacts = allArtifacts.data.artifacts.filter((artifact) => {
2023-10-25 09:53:53 +08:00
return artifact.name == "test-results-qt${{ matrix.qt-version }}"
});
2023-12-01 17:33:06 +10:00
if (matchArtifacts.length>0)
{
let download = await github.rest.actions.downloadArtifact({
owner : context.repo.owner,
repo : context.repo.repo,
artifact_id : matchArtifacts[0].id,
archive_format : 'zip' ,
});
let fs = require('fs');
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/test-results-qt${{ matrix.qt-version }}.zip`, Buffer.from(download.data));
2023-12-02 17:13:34 +10:00
core.setOutput('artifact_id', matchArtifacts[0].id);
2023-12-01 17:33:06 +10:00
}
else
{
core.setOutput('artifact_id', 0);
}
2023-10-11 10:55:51 +10:00
2023-10-25 09:53:53 +08:00
- name : 'Unzip artifact'
2023-12-02 19:55:39 +10:00
if : fromJSON(steps.download_artifact.outputs.artifact_id) > 0
2023-12-11 13:55:35 +10:00
run : unzip -j test-results-qt${{ matrix.qt-version }}.zip *.md pr_number git_commit || ( e=$? && if [ $e -ne 11 ]; then exit $e; fi )
2023-10-11 10:55:51 +10:00
2023-10-25 09:53:53 +08:00
- name : 'Post test report markdown summary as comment on PR'
2023-12-02 19:55:39 +10:00
if : fromJSON(steps.download_artifact.outputs.artifact_id) > 0
2023-12-01 23:56:37 +00:00
uses : actions/github-script@v7
2023-10-25 09:53:53 +08:00
with :
github-token : ${{ secrets.GITHUB_TOKEN }}
script : |
let fs = require('fs');
2023-12-03 06:49:58 +10:00
if (fs.existsSync('./summary.md'))
{
2023-12-08 09:17:40 +10:00
const issue_number = Number(fs.readFileSync('./pr_number'));
const git_sha = String(fs.readFileSync('./git_commit')).trim();
const prComments = await github.rest.issues.listComments({
2023-12-03 06:49:58 +10:00
owner : context.repo.owner,
repo : context.repo.repo,
issue_number : issue_number,
});
2023-12-08 09:17:40 +10:00
2023-12-08 12:21:56 +10:00
const PREFIX = "# Tests failed for Qt ${{ matrix.qt-version }}";
2023-12-08 09:17:40 +10:00
let body = PREFIX + "\n\n";
body += "*One or more tests failed using the build from commit " + git_sha + "*\n\n";
body += String(fs.readFileSync('./summary.md')) +
"\n\n**The full test report (included comparison of rendered vs expected images) can be found [here](https://github.com/qgis/QGIS/suites/" + context.payload.workflow_run.check_suite_id + "/artifacts/${{steps.download_artifact.outputs.artifact_id}}).**\n\n" +
"Further documentation on the QGIS test infrastructure can be found in the [Developer's Guide](https://docs.qgis.org/latest/en/docs/developers_guide/unittesting.html)." ;
const failureComment = prComments.data?.find(c => c.body.startsWith(PREFIX));
if (!!failureComment) {
// update the existing comment
await github.rest.issues.updateComment({
owner : context.repo.owner,
repo : context.repo.repo,
comment_id : failureComment.id,
body : body
});
} else {
// submit a new comment
await github.rest.issues.createComment({
owner : context.repo.owner,
repo : context.repo.repo,
issue_number : issue_number,
body : body
});
}
2023-12-03 09:30:49 +10:00
}