-
-
Notifications
You must be signed in to change notification settings - Fork 3k
101 lines (90 loc) · 3.93 KB
/
write_failure_comment.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
name: Write test failure comment
on:
workflow_run:
workflows: [🧪 QGIS tests]
types:
- completed
permissions:
contents: read
jobs:
on-failure:
strategy:
matrix:
qt-version: [ 5, 6 ]
permissions:
pull-requests: write
runs-on: ubuntu-latest
steps:
- name: 'Download artifact'
id: download_artifact
uses: actions/github-script@v7
with:
script: |
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.payload.workflow_run.id,
});
let matchArtifacts = allArtifacts.data.artifacts.filter((artifact) => {
return artifact.name == "test-results-qt${{ matrix.qt-version }}"
});
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));
core.setOutput('artifact_id', matchArtifacts[0].id);
}
else
{
core.setOutput('artifact_id', 0);
}
- name: 'Unzip artifact'
if: fromJSON(steps.download_artifact.outputs.artifact_id) > 0
run: unzip -j test-results-qt${{ matrix.qt-version }}.zip *.md pr_number git_commit || ( e=$? && if [ $e -ne 11 ]; then exit $e; fi )
- name: 'Post test report markdown summary as comment on PR'
if: fromJSON(steps.download_artifact.outputs.artifact_id) > 0
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
let fs = require('fs');
if (fs.existsSync('./summary.md'))
{
const issue_number = Number(fs.readFileSync('./pr_number'));
const git_sha = String(fs.readFileSync('./git_commit')).trim();
const prComments = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue_number,
});
const PREFIX = "# Tests failed for Qt ${{ matrix.qt-version }}";
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
});
}
}