-
Notifications
You must be signed in to change notification settings - Fork 1.8k
301 lines (268 loc) · 11.9 KB
/
pr-checker.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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
name: PR CHECKER
on:
pull_request_target:
branches:
- main
- 'branch*'
types:
- opened
- reopened
- edited
- synchronize
concurrency:
group: PR-CHECKER-${{ github.event.number }}
cancel-in-progress: false
permissions:
checks: write
actions: write
contents: write
deployments: write
discussions: write
issues: write
packages: write
pages: write
pull-requests: write
repository-projects: write
security-events: write
statuses: write
jobs:
sync-checker:
runs-on: ubuntu-latest
if: >
!contains(github.event.pull_request.title, '(sync #') &&
!contains(github.event.pull_request.labels.*.name, 'sync') &&
(!startsWith(github.head_ref, github.base_ref) || !contains(github.head_ref, '-sync-'))
name: SYNC CHECKER
outputs:
BACKPORT_SOURCE_PR: ${{ steps.backport_assign.outputs.ORI_PR }}
steps:
- run: echo "Normal PR."
- name: backport assign
id: backport_assign
if: startsWith(github.head_ref, 'mergify/bp/') && github.event.action == 'opened'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.number }}
REPO: ${{ github.repository }}
PR_TITLE: ${{ github.event.pull_request.title }}
run: |
ORI_PR=$(echo "${PR_TITLE}" | grep -oP '\(backport #\K\d+' | tail -n 1)
author=$(gh pr view ${ORI_PR} -R ${REPO} --json author -q '.author.login')
if [[ ! "${author}" =~ "mergify" ]]; then
gh pr edit ${PR_NUMBER} -R ${REPO} --add-assignee ${author} || true
echo "ORI_PR=${ORI_PR}" >> $GITHUB_OUTPUT
fi
title-check:
runs-on: ubuntu-latest
needs: sync-checker
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.number }}
REPO: ${{ github.repository }}
BACKPORT_SOURCE_PR: ${{ needs.sync-checker.outputs.BACKPORT_SOURCE_PR }}
steps:
- uses: thehanimo/[email protected]
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
pass_on_octokit_error: false
configuration_path: ".github/pr-title-checker-config.json"
- name: update body
if: always() && github.base_ref != 'main' && (github.event.action == 'opened' || github.event.action == 'reopened')
env:
GH_TOKEN: ${{ secrets.PAT }}
run: |
gh pr view ${PR_NUMBER} -R ${REPO} --json body -q .body > body.txt
ori_body=$(cat body.txt)
if [[ "${GITHUB_HEAD_REF}" == "mergify/bp/"* && "${BACKPORT_SOURCE_PR}" != "" ]]; then
gh pr view ${BACKPORT_SOURCE_PR} -R ${REPO} --json body -q .body > source_body.txt
sed -ie '/Bugfix cherry-pick branch check/,$d' source_body.txt
cat body.txt source_body.txt > tmp_body.txt
mv tmp_body.txt body.txt
fi
sed -i "s#\[ \] This is a backport pr#\[x\] This is a backport pr#g" body.txt
if [[ "${ori_body}" != $(cat body.txt) ]]; then
gh pr edit ${PR_NUMBER} -R ${REPO} -F body.txt
fi
- name: check backport pr's title
if: github.base_ref != 'main' && contains(toJson(github.event.pull_request.body), '[x] This is a backport pr')
env:
PR_TITLE: ${{ github.event.pull_request.title }}
run: |
count=$(echo "${PR_TITLE}" | grep -E '\(backport #[0-9]+)$' | wc -l)
if [[ $count -le 0 ]]; then
echo "::error::Backport PR title is not valid. It should end with '(backport #[0-9]+)'"
exit 1
fi
- name: update body
if: >
github.base_ref != 'main' && github.event.action != 'opened' &&
!contains(github.event.pull_request.title, 'Revert') &&
!contains(toJson(github.event.pull_request.body), '[x] This is a backport pr') &&
!contains(toJson(github.event.pull_request.body), '[ ] This is a backport pr')
run: |
echo "::error::Branch PR does not contain the backport option!"
exit 1
backport-check:
needs: title-check
runs-on: ubuntu-latest
if: >
(startsWith(github.event.pull_request.title, '[BugFix]') ||
startsWith(github.event.pull_request.title, '[Enhancement]') ||
startsWith(github.event.pull_request.title, '[Doc]') ||
startsWith(github.event.pull_request.title, '[UT]')) &&
!contains(github.event.pull_request.title, 'cherry-pick') &&
!contains(github.event.pull_request.title, 'backport')
steps:
- name: add branch-3.1 label
if: contains(toJson(github.event.pull_request.body), '[x] 3.1')
uses: actions-ecosystem/action-add-labels@v1
with:
labels: '3.1'
- name: add branch-3.0 label
if: contains(toJson(github.event.pull_request.body), '[x] 3.0')
uses: actions-ecosystem/action-add-labels@v1
with:
labels: '3.0'
- name: add branch-2.5 label
if: contains(toJson(github.event.pull_request.body), '[x] 2.5')
uses: actions-ecosystem/action-add-labels@v1
with:
labels: '2.5'
- name: add branch-2.4 label
if: contains(toJson(github.event.pull_request.body), '[x] 2.4')
uses: actions-ecosystem/action-add-labels@v1
with:
labels: '2.4'
- name: remove branch-3.1 label
if: contains(toJson(github.event.pull_request.body), '[ ] 3.1') && contains(github.event.pull_request.labels.*.name, '3.1')
uses: actions-ecosystem/action-remove-labels@v1
with:
labels: '3.1'
- name: remove branch-3.0 label
if: contains(toJson(github.event.pull_request.body), '[ ] 3.0') && contains(github.event.pull_request.labels.*.name, '3.0')
uses: actions-ecosystem/action-remove-labels@v1
with:
labels: '3.0'
- name: remove branch-2.5 label
if: contains(toJson(github.event.pull_request.body), '[ ] 2.5') && contains(github.event.pull_request.labels.*.name, '2.5')
uses: actions-ecosystem/action-remove-labels@v1
with:
labels: '2.5'
- name: remove branch-2.4 label
if: contains(toJson(github.event.pull_request.body), '[ ] 2.4') && contains(github.event.pull_request.labels.*.name, '2.4')
uses: actions-ecosystem/action-remove-labels@v1
with:
labels: '2.4'
- name: check-done
if: >
(startsWith(github.event.pull_request.title, '[BugFix]') ||
startsWith(github.event.pull_request.title, '[Enhancement]') ||
startsWith(github.event.pull_request.title, '[Doc]') ||
startsWith(github.event.pull_request.title, '[UT]')) &&
!contains(github.event.pull_request.title, 'cherry-pick') &&
!contains(github.event.pull_request.title, 'backport') &&
contains(toJson(github.event.pull_request.body), '[ ] I have checked the version labels')
run: |
echo "::error::You must mark this checkbox - I have checked the version labels which the pr will be auto-backported to the target branch"
exit 1
behavior-check:
runs-on: ubuntu-latest
if: >
!startsWith(github.event.pull_request.title, '[Doc]') &&
(github.base_ref == 'main' || !startsWith(github.head_ref, 'mergify/bp/') || github.event.action != 'opened')
steps:
- name: Format Check
id: check
if: >
(!contains(toJson(github.event.pull_request.body), '[ ] Yes, this PR will result in a change in behavior') &&
!contains(toJson(github.event.pull_request.body), '[x] Yes, this PR will result in a change in behavior')) ||
(!contains(toJson(github.event.pull_request.body), '[ ] No, this PR will not result in a change in behavior') &&
!contains(toJson(github.event.pull_request.body), '[x] No, this PR will not result in a change in behavior')) ||
(contains(toJson(github.event.pull_request.body), '[x] Yes, this PR will result in a change in behavior') &&
contains(toJson(github.event.pull_request.body), '[x] No, this PR will not result in a change in behavior')) ||
(contains(toJson(github.event.pull_request.body), '[ ] Yes, this PR will result in a change in behavior') &&
contains(toJson(github.event.pull_request.body), '[ ] No, this PR will not result in a change in behavior'))
run: |
echo "::error::Please check the format of your pr body about the behavior change checkbox!"
exit 1
- name: Behavior Unchanged Label
id: unchanged
if: >
steps.check.outcome == 'skipped' &&
contains(toJson(github.event.pull_request.body), '[x] No, this PR will not result in a change in behavior')
uses: actions-ecosystem/action-remove-labels@v1
with:
labels: 'behavior_changed'
- name: Behavior Changed Check
id: changed_check
if: >
always() && steps.check.outcome == 'skipped' && steps.unchanged.outcome == 'skipped' &&
contains(toJson(github.event.pull_request.body), '[x] Yes, this PR will result in a change in behavior') &&
contains(toJson(github.event.pull_request.body), '[ ] Interface/UI changes: syntax, type conversion, expression evaluation, display information') &&
contains(toJson(github.event.pull_request.body), '[ ] Parameter changes: default values, similar parameters but with different default values') &&
contains(toJson(github.event.pull_request.body), '[ ] Policy changes: use new policy to replace old one, functionality automatically enabled') &&
contains(toJson(github.event.pull_request.body), '[ ] Feature removed') &&
contains(toJson(github.event.pull_request.body), '[ ] Miscellaneous: upgrade & downgrade compatibility, etc')
run: |
echo "::error::You must specify the type of change!"
exit 1
- name: Behavior Changed Label
if: >
always() &&
steps.check.outcome == 'skipped' &&
steps.unchanged.outcome == 'skipped' &&
steps.changed_check.outcome != 'failure'
uses: actions-ecosystem/action-add-labels@v1
with:
labels: 'behavior_changed'
automerge-check:
runs-on: ubuntu-latest
needs: backport-check
if: >
!failure() &&
github.base_ref != 'main' &&
startsWith(github.head_ref, 'mergify/') &&
(contains(github.event.pull_request.title, 'cherry-pick') ||
contains(github.event.pull_request.title, 'backport'))
steps:
- name: add automerge label
uses: actions-ecosystem/action-add-labels@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
labels: automerge
- name: automerge
uses: peter-evans/enable-pull-request-automerge@v2
with:
token: ${{ secrets.PAT }}
pull-request-number: ${{ github.event.pull_request.number }}
merge-method: squash
feature-label-check:
runs-on: ubuntu-latest
steps:
- name: add feature label
id: add
if: startsWith(github.event.pull_request.title, '[Feature]')
uses: actions-ecosystem/action-add-labels@v1
with:
labels: 'feature'
github_token: ${{ secrets.PAT }}
- name: remove feature label
if: always() && steps.add.outcome == 'skipped'
uses: actions-ecosystem/action-remove-labels@v1
with:
labels: 'feature'
github_token: ${{ secrets.PAT }}
changelist-check:
runs-on: [self-hosted, normal]
if: >
(github.event.action == 'opened' || github.event.action == 'synchronize') &&
!contains(github.event.pull_request.title, 'cherry-pick') &&
!contains(github.event.pull_request.title, 'backport')
env:
PR_NUMBER: ${{ github.event.number }}
GH_TOKEN: ${{ secrets.PAT }}
steps:
- name: CHECK CHANGELIST
run: |
rm -rf ./ci-tool && cp -rf /var/lib/ci-tool ./ci-tool && cd ci-tool && git pull && source lib/init.sh
./bin/check-pr-changelist.sh