-
Notifications
You must be signed in to change notification settings - Fork 0
164 lines (150 loc) · 5.79 KB
/
feedback-pr.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
name: Validation Feedback
on:
workflow_run:
workflows: [Validate Packages]
types: [completed]
permissions:
actions: read
pull-requests: write
jobs:
feedback:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- run: echo 'The triggering workflow passed'
- name: 'Download pre analysis artifacts'
uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6
with:
script: |
const fs = require('fs');
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-artifacts"
})[0];
let download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/pr-artifacts.zip`, Buffer.from(download.data));
- name: 'Unzip artifacts'
run: unzip pr-artifacts.zip
- name: Retrieve PR number'
id: pr-number
run: |
PR_NUMBER=$(cat pr-number)
echo "$PR_NUMBER"
echo "pr_number=$PR_NUMBER" >> $GITHUB_ENV
- name: Sanitize validation logs
id: sanitize-validate-log
uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6
with:
script: |
const fs = require('fs')
let validateLog = fs.readFileSync('validate.log')
return validateLog.toString()
.replaceAll("`", "")
.replaceAll("~", "")
.replaceAll("<", "")
.replaceAll(">", "")
- name: Publish validation success report
uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6
if: ${{ github.event.workflow_run.conclusion == 'success' }}
env:
PR_NUMBER: ${{ env.pr_number }}
VALIDATE_LOG : ${{ steps.sanitize-validate-log.outputs.result }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { PR_NUMBER, VALIDATE_LOG } = process.env
const VALIDATE_LOG_DISPLAY = VALIDATE_LOG.replaceAll("\\n", "\n")
github.rest.issues.createComment({
issue_number: PR_NUMBER,
owner: context.repo.owner,
repo: context.repo.repo,
body: `:white_check_mark: Packages has been verified and are valid
<details>
<summary>View validation details</summary>
~~~
${VALIDATE_LOG_DISPLAY}
~~~
</details>
`
})
- name: Publish validation error report
uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
env:
PR_NUMBER: ${{ env.pr_number }}
VALIDATE_LOG : ${{ steps.sanitize-validate-log.outputs.result }}
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const { PR_NUMBER, VALIDATE_LOG } = process.env
const VALIDATE_LOG_DISPLAY = VALIDATE_LOG.replaceAll("\\n", "\n")
github.rest.issues.createComment({
issue_number: PR_NUMBER,
owner: context.repo.owner,
repo: context.repo.repo,
body: `:x: Packages has been verified and are flagged as invalid
<details>
<summary>View validation details</summary>
~~~
${VALIDATE_LOG_DISPLAY}
~~~
</details>
`
})
- name: Label success job
uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6
if: ${{ github.event.workflow_run.conclusion == 'success' }}
env:
PR_NUMBER: ${{ env.pr_number }}
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const { PR_NUMBER } = process.env
github.rest.issues.addLabels({
issue_number: PR_NUMBER,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ['Valid', 'Wait-Approval']
}).catch((e) => {})
github.rest.issues.removeLabel({
issue_number: PR_NUMBER,
owner: context.repo.owner,
repo: context.repo.repo,
name: 'Invalid'
}).catch((e) => {})
- name: Label failure job
uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
env:
PR_NUMBER: ${{ env.pr_number }}
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const { PR_NUMBER } = process.env
github.rest.issues.addLabels({
issue_number: PR_NUMBER,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ['Invalid']
}).catch((e) => {})
github.rest.issues.removeLabel({
issue_number: PR_NUMBER,
owner: context.repo.owner,
repo: context.repo.repo,
name: 'Valid'
}).catch((e) => {})
github.rest.issues.removeLabel({
issue_number: PR_NUMBER,
owner: context.repo.owner,
repo: context.repo.repo,
name: 'Wait-Approval'
}).catch((e) => {})