-
Notifications
You must be signed in to change notification settings - Fork 67
117 lines (111 loc) · 4.34 KB
/
qualityGateCommentPR.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
name: quality_gate_comment_pr
on:
workflow_run:
workflows: ["quality_gate"]
types:
- completed
permissions:
pull-requests: write
env:
REPORT_1_ARTIFACT: qualityGateReports_file1
REPORT_2_ARTIFACT: qualityGateReports_file2
REPORT_CONCATENATED: qualityGateReports_concat
PR_NUM_ARTIFACT: qualityGateReports_pr
COMMENT_AUTHOR: 'github-actions[bot]'
COMMENT_TAG: '<!--- This comment was added by: qualityGateCommentPR.yml -->'
jobs:
quality_gate_comment_pr:
runs-on: ubuntu-latest
if: >
github.event.workflow_run.event == 'pull_request'
steps:
#
# Find artifacts
#
- name: 'Download the artifacts'
uses: actions/github-script@v7
with:
script: |
var ARTIFACT_NAMES = [
'${{ env.REPORT_1_ARTIFACT }}',
'${{ env.REPORT_2_ARTIFACT }}',
'${{ env.PR_NUM_ARTIFACT }}'
];
var artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{ github.event.workflow_run.id }},
});
async function downloadArt(artName) {
var fs = require('fs');
var matchArtifact = artifacts.data.artifacts.find((artifact) => {
return artName === artifact.name;
});
if (matchArtifact) {
var download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
fs.writeFileSync('${{github.workspace}}/' + artName + '.zip', Buffer.from(download.data));
return true;
} else {
core.setFailed('Unable to find artifact: ' + artName);
return false;
}
}
await Promise.all(ARTIFACT_NAMES.map((artName) => downloadArt(artName)));
#
# Unzip artifacts
#
- name: Unzip report 1
run: |
unzip -p ${{ env.REPORT_1_ARTIFACT }}.zip > ./${{ env.REPORT_1_ARTIFACT }}
- name: Unzip report 2
run: |
unzip -p ${{ env.REPORT_2_ARTIFACT }}.zip > ./${{ env.REPORT_2_ARTIFACT }}
- name: Unzip PR number
run: |
unzip -p ${{ env.PR_NUM_ARTIFACT }}.zip > ./${{ env.PR_NUM_ARTIFACT }}
#
#
#
#
- name: Read PR number from ${{ env.PR_NUM_ARTIFACT }}
uses: actions/github-script@v7
id: readPrNumber
with:
script: |
return Number(require('fs').readFileSync('./${{ env.PR_NUM_ARTIFACT }}').toString());
#
#
#
- name: Concatenate reports
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const SEPARATOR = "\n\n---\n";
const contentArr = [
fs.readFileSync('./${{ env.REPORT_1_ARTIFACT }}'),
fs.readFileSync('./${{ env.REPORT_2_ARTIFACT }}'),
];
const concatenated = contentArr.join(SEPARATOR);
const commentContent = concatenated + '\n' + '${{ env.COMMENT_TAG }}';
fs.writeFileSync('./${{ env.REPORT_CONCATENATED }}', commentContent);
#
# Update comment: track-bundle-size
#
- id: prevCommentId
uses: peter-evans/find-comment@v2
with:
issue-number: ${{ steps.readPrNumber.outputs.result }}
comment-author: '${{env.COMMENT_AUTHOR}}'
body-includes: '${{env.COMMENT_TAG}}'
- uses: peter-evans/create-or-update-comment@v3
with:
comment-id: ${{ steps.prevCommentId.outputs.comment-id }}
issue-number: ${{ steps.readPrNumber.outputs.result }}
body-path: ${{ env.REPORT_CONCATENATED }}
edit-mode: replace