forked from canonical/snapd
-
Notifications
You must be signed in to change notification settings - Fork 0
137 lines (121 loc) · 5.32 KB
/
spread-results-reporter.yaml
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
name: Spread tests results PR commenter
on:
workflow_run:
workflows: [Tests]
types:
- completed
jobs:
report-spread-failures:
if: ${{ github.event.workflow_run.event == 'pull_request' }}
runs-on: ubuntu-latest
permissions:
pull-requests: write
env:
GH_TOKEN: ${{ github.token }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Get PR number
uses: actions/github-script@v6
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 matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
return artifact.name == "pr_number"
})[0];
let download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
let fs = require('fs');
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/pr_number.zip`, Buffer.from(download.data));
- name: Unzip PR number
run: unzip pr_number.zip
- name: Get generated data
uses: actions/github-script@v6
with:
script: |
let page = 1;
let per_page = 100;
let allArtifacts = [];
let response;
do {
response = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.payload.workflow_run.id,
per_page: per_page,
page: page
});
allArtifacts = allArtifacts.concat(response.data.artifacts);
page++;
} while (response.data.artifacts.length === per_page);
let matchingArtifacts = allArtifacts.filter((artifact) => {
return artifact.name.startsWith(`spread-json-${context.payload.workflow_run.id}-${context.payload.workflow_run.run_attempt}`);
});
for (let artifact of matchingArtifacts) {
let download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: artifact.id,
archive_format: 'zip',
});
let fs = require('fs');
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/${artifact.name}.zip`, Buffer.from(download.data));
console.log(`Downloaded artifact: ${artifact.name}.zip`);
}
- name: Unzip spread json files
run: |
find . -name "spread-json-${{ github.event.workflow_run.id }}*.zip" | while read filename; do
dir="${filename%.zip}"
mkdir $dir
unzip $filename -d $dir
done
- name: Echo collected output
run: |
# generate report
(
date
# The 'skip spread' label was added to the pull request
if gh api /repos/${{ github.repository }}/issues/"$(cat pr_number)" | jq '.labels.[].name' | grep -iq '"skip spread"'; then
echo "## Spread tests skipped"
exit 0
fi
echo "The following results are from: https://github.com/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }}"
# There are no logged spread failures
if ! ls spread-json-${{ github.event.workflow_run.id }}-*/*.json &> /dev/null; then
echo '## No spread failures reported'
else
# There are logged spread failures
jq -s 'add' spread-json-${{ github.event.workflow_run.id }}*/*.json > consolidated-report.json
echo "## Failures:"
if [[ $(jq -r '.[] | select( .info_type == "Error" ) | select( .verb == "preparing" )' consolidated-report.json) ]]; then
echo "### Preparing:"
jq -r '.[] | select( .info_type == "Error" ) | select( .verb == "preparing" ) .task' consolidated-report.json |\
awk ' { print "- " $0 }'
fi
if [[ $(jq -r '.[] | select( .info_type == "Error" ) | select( .verb == "executing" )' consolidated-report.json) ]]; then
echo "### Executing:"
jq -r '.[] | select( .info_type == "Error" ) | select( .verb == "executing" ) .task' consolidated-report.json |\
awk ' { print "- " $0 }'
fi
if [[ $(jq -r '.[] | select( .info_type == "Error" ) | select( .verb == "restoring" )' consolidated-report.json) ]]; then
echo "### Restoring:"
jq -r '.[] | select( .info_type == "Error" ) | select( .verb == "restoring" ) .task' consolidated-report.json |\
awk ' { print "- " $0 }'
fi
fi
) > report
# display the report
grep -n '' report
- name: Comment report to PR
run: |
if ! gh pr comment "$(cat pr_number)" --body "$(cat report)" --edit-last; then
gh pr comment "$(cat pr_number)" --body "$(cat report)"
fi