-
Notifications
You must be signed in to change notification settings - Fork 0
416 lines (379 loc) · 14.3 KB
/
validate.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
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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
name: Marketplace Actions
on:
issues:
types:
- opened
- reopened
- edited
issue_comment:
types:
- created
- edited
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
concurrency:
group: "validation"
cancel-in-progress: false
jobs:
react-to-new-issue:
name: New Issue
if: github.event_name == 'issues' && github.event.action == 'opened'
runs-on: ubuntu-latest
outputs:
comment-id: ${{ steps.comment.outputs.comment-id }}
steps:
- name: Add comment
id: comment
uses: peter-evans/create-or-update-comment@v2
with:
issue-number: ${{ github.event.issue.number }}
body: |
感谢你的提交。
自动验证将在几分钟内开始。
edited-old-issue:
name: Edited Issue
if: github.event_name == 'issues' && github.event.action == 'edited'
runs-on: ubuntu-latest
outputs:
comment-id: ${{ steps.comment.outputs.comment-id }}
steps:
- name: Add comment
id: comment
uses: peter-evans/create-or-update-comment@v2
with:
issue-number: ${{ github.event.issue.number }}
body: |
感谢你的提交。
自动验证将在几分钟内开始。
is-revalidation:
if: github.event.issue.state == 'open' && github.event_name == 'issue_comment'
name: Revalidation
runs-on: ubuntu-latest
steps:
- name: Run /validate command
env:
COMMENT_BODY: ${{ github.event.comment.body }}
run: |
command=$(echo "$COMMENT_BODY" | head -1)
if [[ $command != "/validate"* ]]; then
echo "No /validate command found in first line of the comment \"${command}\", skipping" >> $GITHUB_STEP_SUMMARY
exit 1
fi
- name: Add reactions
uses: peter-evans/create-or-update-comment@v2
with:
comment-id: ${{ github.event.comment.id }}
reactions: "+1"
parse-issue:
name: Parse Issue
needs: [react-to-new-issue, is-revalidation, edited-old-issue]
if: always() && (needs.react-to-new-issue.result == 'success' || needs.is-revalidation.result == 'success' || needs.edited-old-issue.result == 'success')
runs-on: ubuntu-latest
env:
REPO: ${{ github.repository }}
ISSUE_NUM: ${{ github.event.issue.number }}
ISSUE_TITLE: ${{ github.event.issue.title }}
outputs:
module_name: ${{ steps.set-output.outputs.module_name }}
pypi_name: ${{ steps.set-output.outputs.pypi_name }}
result: ${{ steps.run.outputs.result }}
output: ${{ steps.run.outputs.output }}
type: ${{ steps.run.outputs.type }}
name: ${{ steps.run.outputs.name }}
steps:
- name: Parse issue body
id: parse
uses: zentered/issue-forms-body-parser@v1.5.1
- name: Get Inputs
id: set-output
env:
JSON_DATA: ${{ steps.parse.outputs.data }}
run: |
module_name=$(echo $JSON_DATA | jq -r '.["module-name"].text' )
echo "module_name=$module_name" >> $GITHUB_OUTPUT
pypi_name=$(echo $JSON_DATA | jq -r '.["pypi-name"].text' )
echo "pypi_name=$pypi_name" >> $GITHUB_OUTPUT
# 启动 Python 脚本,并传入 pypi_name、ISSUE_TITLE
- uses: actions/checkout@v3
- uses: pdm-project/setup-pdm@v3
name: Setup PDM
with:
python-version: 3.9
cache: true
- name: Install dependencies
run: pdm install --prod
- name: Run Python script
id: run
env:
TITLE: ${{ env.ISSUE_TITLE }}
PYPI_NAME: ${{ steps.set-output.outputs.pypi_name }}
run: |
pdm run .github/actions_scripts/parse.py
parse-failed:
name: Parse Failed
runs-on: ubuntu-latest
needs: parse-issue
if: always() && needs.parse-issue.outputs.result == 'error'
steps:
- uses: actions/checkout@v3.3.0
- name: Render template
id: render
uses: chuhlomin/render-template@v1.6
with:
template: .github/workflows/templates/validation-failed.md
vars: |
validation_output: ${{ needs.parse-issue.outputs.output }}
- name: Add comment
uses: peter-evans/create-or-update-comment@v3.0.2
with:
issue-number: ${{ github.event.issue.number }}
body: ${{ steps.render.outputs.result }}
- name: Remove label validation/succeeded
if: contains(github.event.issue.labels.*.name, 'validation/succeeded')
uses: actions/github-script@v6
with:
script: |
github.rest.issues.removeLabel({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
name: ["validation/succeeded"]
})
- name: Add label parse-issue/failed
if: contains(github.event.issue.labels.*.name, 'parse-issue/failed') == false
uses: actions/github-script@v6
with:
script: |
github.rest.issues.addLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ["parse-issue/failed"]
})
- name: Mark job as failed
run: exit 1
validate:
name: Validate
runs-on: ubuntu-latest
if: always() && needs.parse-issue.outputs.result == 'success'
needs:
- parse-issue
outputs:
name: ${{ steps.test.outputs.name }}
description: ${{ steps.test.outputs.description }}
author: ${{ steps.test.outputs.author }}
license: ${{ steps.test.outputs.license }}
homepage: ${{ steps.test.outputs.homepage }}
tags: ${{ steps.test.outputs.tags }}
result: ${{ steps.test.outputs.result || steps.install-pypi-error.outputs.result }}
output: ${{ steps.test.outputs.output || steps.install-pypi-error.outputs.output }}
steps:
- name: Remove label parse-issue/failed
if: contains(github.event.issue.labels.*.name, 'parse-issue/failed')
uses: actions/github-script@v6
with:
script: |
github.rest.issues.removeLabel({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
name: ["parse-issue/failed"]
})
- uses: actions/checkout@v3
- uses: pdm-project/setup-pdm@v3
name: Setup PDM
with:
python-version: 3.9
cache: true
- name: Install dependencies
run: pdm install --prod
# 若 type 不为 bot,则安装 pypi_name
- name: Install pypi_name
id: install-pypi
if: needs.parse-issue.outputs.type != 'bot'
continue-on-error: true
run: pdm add ${{ needs.parse-issue.outputs.pypi_name }}
- name: Install Error
id: install-pypi-error
if: steps.install-pypi.outcome != 'success' || steps.install-pypi.conclusion != 'success'
run: | # 输出错误信息
echo "result=error" >> $GITHUB_OUTPUT
echo "output=安装pypi包失败,请检查是否存在依赖冲突或者其他情况" >> $GITHUB_OUTPUT
- name: alicebot test
id: test
if: steps.install-pypi.outcome == 'success' && steps.install-pypi.conclusion == 'success'
env:
PYPI_NAME: ${{ needs.parse-issue.outputs.pypi_name }}
MODULE_NAME: ${{ needs.parse-issue.outputs.module_name }}
TYPE: ${{ needs.parse-issue.outputs.type }}
run: |
pdm run .github/actions_scripts/test.py
validation-failed:
name: Validation Failed
runs-on: ubuntu-latest
needs: validate
if: always() && needs.validate.outputs.result == 'error'
steps:
- uses: actions/checkout@v3.3.0
- name: Render template
id: render
uses: chuhlomin/render-template@v1.6
with:
template: .github/workflows/templates/validation-failed.md
vars: |
validation_output: ${{ needs.validate.outputs.output }}
- name: Add comment
uses: peter-evans/create-or-update-comment@v3.0.2
with:
issue-number: ${{ github.event.issue.number }}
body: ${{ steps.render.outputs.result }}
- name: Remove label validation/succeeded
if: contains(github.event.issue.labels.*.name, 'validation/succeeded')
uses: actions/github-script@v6
with:
script: |
github.rest.issues.removeLabel({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
name: ["validation/succeeded"]
})
- name: Add label validation/failed
if: contains(github.event.issue.labels.*.name, 'validation/failed') == false
uses: actions/github-script@v6
with:
script: |
github.rest.issues.addLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ["validation/failed"]
})
- name: Mark job as failed
run: exit 1
create-pr:
name: Create PR
runs-on: ubuntu-latest
needs: [validate, parse-issue]
if: always() && needs.validate.outputs.result == 'success' && needs.parse-issue.outputs.result == 'success'
env:
REPO: ${{ github.repository }}
ISSUE_NUM: ${{ github.event.issue.number }}
ISSUE_TITLE: ${{ github.event.issue.title }}
TYPE: ${{ needs.parse-issue.outputs.type }}
outputs:
result: ${{ steps.copy-commands.outputs.result }}
file_json: ${{ steps.file.outputs.file_json }}
steps:
- name: Get open linked PR
id: get_open_linked_pr
run: |
open_linked_pr_length=$(\
gh pr list \
--repo $REPO \
--state open \
--search "close #$ISSUE_NUM in:body" \
--json number | jq '. | length'\
)
echo "::set-output name=open_linked_pr_length::$open_linked_pr_length"
- name: Check open linked pr length
if: steps.get_open_linked_pr.outputs.open_linked_pr_length != 0
run: |
echo "Unclosed pull request is existing."
exit 1
- uses: actions/checkout@v3
- uses: pdm-project/setup-pdm@v3
name: Setup PDM
with:
python-version: 3.9
cache: true
- name: Install dependencies
run: pdm install --prod
- name: Change file
id: file
env:
TYPE: ${{ needs.parse-issue.outputs.type }}
MODULE_NAME: ${{ needs.parse-issue.outputs.module_name }}
PYPI_NAME: ${{ needs.parse-issue.outputs.pypi_name }}
NAME: ${{ needs.validate.outputs.name }}
DESCRIPTION: ${{ needs.validate.outputs.description }}
AUTHOR: ${{ needs.validate.outputs.author }}
LICENSE: ${{ needs.validate.outputs.license }}
HOMEPAGE: ${{ needs.validate.outputs.homepage }}
TAGS: ${{ needs.validate.outputs.tags }}
run: |
pdm run .github/actions_scripts/file.py
- name: Reopen issue
if: ${{ github.event.issue.state }} == "closed"
run: gh issue reopen $ISSUE_NUM
- name: Define new branch name
id: define_new_branch_name
run: |
new_branch_name=$(echo "${ISSUE_NUM}-$(TZ=UTC-9 date '+%Y%m%d-%H%M%S')")
echo "::set-output name=new_branch_name::$new_branch_name"
- name: Create branch
uses: EndBug/add-and-commit@v9
with:
new_branch: ${{ steps.define_new_branch_name.outputs.new_branch_name }}
- name: Create PR
run: |
gh pr create \
--head $NEW_BRANCH_NAME \
--base $BASE_BRANCH_NAME \
--title "$ISSUE_TITLE" \
--body "close #${ISSUE_NUM}"
env:
NEW_BRANCH_NAME: ${{ steps.define_new_branch_name.outputs.new_branch_name }}
BASE_BRANCH_NAME: ${{ github.event.repository.default_branch }}
- name: Copy Commands
id: copy-commands
run: |
echo "git fetch origin ${NEW_BRANCH}"
echo "git checkout ${NEW_BRANCH}"
echo "code --reuse-window ${TYPE}.json"
result="success"
echo "result=$result" >> $GITHUB_OUTPUT
env:
NEW_BRANCH: ${{ steps.define_new_branch_name.outputs.new_branch_name }}
validation-succeeded:
name: Validation Succeeded
runs-on: ubuntu-latest
needs: [validate, create-pr]
if: always() && needs.validate.outputs.result == 'success' && needs.create-pr.outputs.result == 'success'
steps:
- uses: actions/checkout@v3.3.0
- name: Render template
id: render
uses: chuhlomin/render-template@v1.6
with:
template: .github/workflows/templates/validation-succeeded.md
vars: |
content: ${{ needs.create-pr.outputs.file_json }}
- name: Add Comment
uses: peter-evans/create-or-update-comment@v3.0.2
with:
issue-number: ${{ github.event.issue.number }}
body: ${{ steps.render.outputs.result }}
- name: Remove label validation/failed
if: contains(github.event.issue.labels.*.name, 'validation/failed')
uses: actions/github-script@v6
with:
script: |
github.rest.issues.removeLabel({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
name: ["validation/failed"]
})
- name: Add label validation/succeeded
if: contains(github.event.issue.labels.*.name, 'validation/succeeded') == false
uses: actions/github-script@v6
with:
script: |
github.rest.issues.addLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ["validation/succeeded"]
})