This repository has been archived by the owner on Sep 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathconfig.yml
452 lines (432 loc) · 15.5 KB
/
config.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
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
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
title: "GitHub Actions: Using GitHub Script"
description: >-
This course covers how to use GitHub Script to quickly use octokit/rest in a
GitHub Actions workflow.
tags:
- GitHub Actions
- Octokit
- Workflow
- Automation
- Application programming interface (API)
template:
repo: write-github-script-template
name: write-github-script
# Repo artifacts
# repositoryUrl
# actionsUrl
# workflowEditUrl
# branchSettingsUrl
# 1. (Issue) Start here!
# welcomeIssueUrl
# welcomeIssueNumber
# 2. (PR) Learner created PR, "Automate issue response" possibly
# firstPullNumber
# firstPullUrl
# 3. (Issue) Create an issue comment with GitHub Script
# secondIssueNumber
# secondIssueUrl
# 4. (PR) Learner created PR, "Add issues to project board" possibly
# secondPullNumber
# secondPullUrl
# 5. (Issue) Comment and triage with GitHub Script
# thirdIssueUrl
# thirdIssueNumber
# 6. (PR) Learner created PR, "Create better comments" possibly
# thirdPullNumber
# thirdPullUrl
# 7. (Issue) It's alive!
# fourthIssueUrl
# fourthIssueNumber
before:
- type: updateBranchProtection
store:
repositoryUrl: '{{ payload.repository.html_url }}'
actionsUrl: '{{ payload.repository.html_url }}/actions'
workflowEditUrl: '{{ payload.repository.html_url }}/edit/main/.github/workflows/my-workflow.yml'
branchSettingsUrl: '{{ payload.repository.html_url }}/settings/branches'
- type: createProjectBoard
name: Learning Lab Project Board
description: >-
This board is used with the GitHub Actions: Using GitHub Script Learning Lab course.
columns:
- Triage Backlog
- Triage Complete
store:
projectUrl: "{{ result.data.html_url }}"
- type: createIssue
title: Start here!
body: 00_welcome-issue.md
store:
welcomeIssueUrl: "%result.data.html_url%"
welcomeIssueNumber: "%result.data.number%"
data:
quicklink: "{{ store.repositoryUrl }}/new/main?filename=.github/workflows/my-workflow.yml"
actionsUrl: "{{ store.repositoryUrl }}/actions/new"
comments:
- 00_explain-gh-script.md
- 00_octokit-comparison.md
- 00_welcome-activity.md
steps:
- title: Start here!
description: Create a pull request to add a workflow
event:
- pull_request.opened
- pull_request.edited
link: "{{store.welcomeIssueUrl}}"
actions:
# Validate the filepath for the my-workflow.yml file
# get tree
- type: getTree
action_id: isInTree
recursive: true
sha: "%payload.pull_request.head.sha%"
store:
firstPullNumber: "%payload.pull_request.number%"
firstPullUrl: "%payload.pull_request.html_url%"
# check for a file in a tree
- type: gate
left: "%actions.isInTree.data.tree%"
operator: includes
right: "path:.github/workflows/my-workflow.yml"
else:
# if file isn't where expected find true location
- type: findInTree
path: my-workflow.yml
tree: "%actions.isInTree.data.tree%"
action_id: fileLocation
# help user with proper file location
- type: respond
with: e-wrong-file-location.md
data:
haveFile: "%actions.fileLocation.path%"
needFile: ".github/workflows/my-workflow.yml"
editLink: "%payload.repository.html_url%/edit/%payload.pull_request.head.ref%/%actions.fileLocation.path%"
fileName: my-workflow.yml
# End filepath verification
#######################################################
- type: respond
issue: "%store.welcomeIssueNumber%"
with: new-pull-request.md
data:
pullUrl: '{{ store.firstPullUrl }}'
- type: closeIssue
issue: "%store.welcomeIssueNumber%"
- type: createReview
body: 01_merge-workflow.md
event: APPROVE
- title: Merge your first pull request
description: Make the workflow available to the repository by merging the pull request
event: pull_request.closed
link: "{{store.firstPullUrl}}"
actions:
- type: gate
every: true
gates:
- left: '{{ payload.pull_request.number }}'
operator: ===
right: '{{ store.firstPullNumber }}'
- left: '{{ payload.pull_request.merged }}'
else:
- type: respond
with: e-generic.md
data:
expected: 'merge pull request #{{ store.firstPullNumber }}'
- type: createIssue
title: Create an issue comment with GitHub Script
body: 02_workflow-triggered.md
store:
secondIssueNumber: "%result.data.number%"
secondIssueUrl: "%result.data.html_url%"
- type: respond
with: new-issue.md
issue: "%store.firstPullNumber%"
data:
issueUrl: '{{ store.secondIssueUrl }}'
- title: Add another GitHub Script action
description: Use GitHub Script to place this issue into a project board
# event: check_suite.completed # issue_comment.created/edited
event: issue_comment.created
link: "{{store.secondIssueUrl}}"
actions:
- type: gate
left: "%payload.comment.user.login%"
operator: ===
right: "github-actions[bot]"
else:
- type: respond
issue: "%store.secondIssueNumber%"
with: debug.md
data:
debug: "%payload%"
- type: respond
with: 03_workflow-success.md
issue: "%store.secondIssueNumber%"
- type: octokit
method: projects.listForRepo
owner: "%payload.repository.owner.login%"
repo: "%payload.repository.name%"
store:
boardID: "%result.data.0.id%"
- type: octokit
method: projects.listColumns
project_id: "%store.boardID%"
store:
columnID: "%result.data.0.id%"
- type: respond
with: 03_add-to-projects.md
issue: "%store.secondIssueNumber%"
data:
columnID: "%store.columnID%"
quicklink: "%payload.repository.html_url%/edit/main/.github/workflows/my-workflow.yml"
# new pull request
- title: Modify your workflow file
description: Create a pull request to add changes to your workflow
event:
- pull_request.opened
- pull_request.edited
link: "{{ store.secondIssueUrl }}"
actions:
#######################################################
# Validate the filepath for the my-workflow.yml file
# get tree
- type: getTree
action_id: isInTree
recursive: true
sha: "%payload.pull_request.head.sha%"
store:
secondPullNumber: "%payload.pull_request.number%"
secondPullUrl: "%payload.pull_request.html_url%"
# check for a file in a tree
- type: gate
left: "%actions.isInTree.data.tree%"
operator: includes
right: "path:.github/workflows/my-workflow.yml"
else:
# if file isn't where expected find true location
- type: findInTree
path: my-workflow.yml
tree: "%actions.isInTree.data.tree%"
# multiple: true
action_id: fileLocation
# help user with proper file location
- type: respond
with: e-wrong-file-location.md
data:
haveFile: "%actions.fileLocation.path%"
needFile: ".github/actions/cat-facts/action.yml"
editLink: "%payload.repository.html_url%/edit/%payload.pull_request.head.ref%/%actions.fileLocation.path%"
fileName: my-workflow.yml
# End filepath verification
#######################################################
- type: respond
issue: "%store.secondIssueNumber%"
with: new-pull-request.md
data:
pullUrl: "%store.secondPullUrl%"
- type: closeIssue
issue: "%store.secondIssueNumber%"
- type: createReview
body: 04_merge-workflow.md
event: APPROVE
data:
actionsUrl: "%payload.repository.html_url%/actions"
- title: Merge the updated workflow into the main branch
description: Make the workflow available for use on the repository
event: pull_request.closed
link: "{{ store.secondPullUrl }}"
actions:
- type: gate
every: true
gates:
- left: '{{ payload.pull_request.number }}'
operator: ===
right: '{{ store.secondPullNumber }}'
- left: '{{ payload.pull_request.merged }}'
else:
- type: respond
with: e-generic.md
data:
expected: 'merge pull request #{{ store.secondPullNumber }}'
- type: createIssue
title: Comment and triage with GitHub Script
body: 05_workflow-triggered.md
action_id: triggerIssue
store:
thirdIssueUrl: "%result.data.html_url%"
thirdIssueNumber: "%result.data.number%"
- type: respond
with: new-issue.md
issue: "%store.secondPullNumber%"
data:
issueUrl: "%store.thirdIssueUrl%"
- title: Break your workflow into multiple steps
description: Separate the workflow concerns by adding more steps
event: issue_comment.created
link: "{{store.thirdIssueUrl}}"
actions:
- type: gate
left: "%payload.comment.user.login%"
operator: ===
right: "github-actions[bot]"
else:
- type: respond
issue: "%store.secondIssueNumber%"
with: debug.md
data:
debug: "%payload%"
- type: octokit
method: projects.listForRepo
owner: "%payload.repository.owner.login%"
repo: "%payload.repository.name%"
action_id: projectBoard
- type: octokit
method: projects.listColumns
project_id: "%actions.projectBoard.data.0.id%"
action_id: listColumns
- type: respond
with: 06_steps-overview.md
issue: "%store.thirdIssueNumber%"
data:
projectTab: "%payload.repository.html_url%/projects/1"
- type: respond
with: 06_steps-activity.md
issue: "%store.thirdIssueNumber%"
data:
listProj: "%actions.projectBoard.data%"
listCol: "%actions.listColumns.data%"
columnID: "%actions.listColumns.data.0.id%"
quicklink: "%payload.repository.html_url%/edit/main/.github/workflows/my-workflow.yml"
- title: Create better comments
description: Use a templated repsonse as the comment body
event:
- pull_request.opened
- pull_request.edited
link: "{{store.thirdPullUrl}}"
actions:
- type: octokit
method: projects.listForRepo
owner: "%payload.repository.owner.login%"
repo: "%payload.repository.name%"
action_id: projectBoard
store:
thirdPullNumber: "%payload.pull_request.number%"
thirdPullUrl: "%payload.pull_request.html_url%"
- type: octokit
method: projects.listColumns
project_id: "%actions.projectBoard.data.0.id%"
action_id: listColumns
- type: respond
issue: "%store.thirdIssueNumber%"
with: new-pull-request.md
data:
pullUrl: "%store.thirdPullUrl%"
- type: closeIssue
issue: "%store.thirdIssueNumber%"
- type: respond
with: 07_explain-node.md
- type: respond
with: 07_use-fs.md
data:
columnID: "%actions.listColumns.data.0.id%"
quicklink: "%payload.repository.html_url%/edit/%payload.pull_request.head.ref%/.github/workflows/my-workflow.yml"
- title: Use a templated response
description: Create the comment body from a template using the Node.js file system module
event: pull_request.synchronize
link: "{{store.thirdPullUrl}}"
actions:
- type: gate
left: '{{ payload.pull_request.number }}'
operator: ===
right: '{{ store.thirdPullNumber }}'
else:
- type: respond
with: e-generic.md
data:
expected: 'push a commit to #{{ store.thirdPullNumber }}'
- type: createReview
body: 08_merge-workflow.md
event: APPROVE
- title: Merge the updated workflow
description: Merge the worklow to the main branch
event: pull_request.closed
link: "{{store.thirdPullUrl}}"
actions:
- type: gate
every: true
gates:
- left: '{{ payload.pull_request.number }}'
operator: ===
right: '{{ store.thirdPullNumber }}'
- left: '{{ payload.pull_request.merged }}'
else:
- type: respond
with: e-generic.md
data:
expected: 'merge pull request #{{ store.thirdPullNumber }}'
- type: octokit
action_id: triggerIssue
method: issues.create
owner: "%payload.repository.owner.login%"
repo: "%payload.repository.name%"
title: It's alive!
body: |
## Great Job so far!
Like before, now we have to wait for the workflow to run so that we can see the results.
<details>
<summary>Workflow not running? Click here for some troubleshooting.</summary>
Try the following troubleshooting steps:
1. Click on the [Actions tab]({{ store.actionsUrl }}) to see the status of your workflow run. See [Managing a workflow run](https://help.github.com/en/actions/configuring-and-managing-workflows/managing-a-workflow-run) on GitHub Help for more information.
1. Edit your [workflow file]( {{ store.workflowEditUrl }}) and look for errors in the linter built into the browser.
1. Look for the [workflow trigger](https://help.github.com/en/actions/reference/events-that-trigger-workflows) and ensure you are performing an action that triggers that workflow.
If you need to make changes to your code, remove the [main branch protection]({{ store.branchSettingsUrl }}) and merge your changes into the `main` branch.
</details>
---
I'll respond here once it has completed!
labels: ["bug"]
store:
fourthIssueUrl: "%result.data.html_url%"
fourthIssueNumber: "%result.data.number%"
- type: respond
with: new-issue.md
issue: "%store.thirdPullNumber%"
data:
issueUrl: "%store.fourthIssueUrl%"
- title: Another workflow run
description: Observe the results of an enhanced workflow run
event: check_suite.completed
link: "{{store.fourthIssueUrl}}"
actions:
- type: gate
left: "%payload.check_suite.app.name%"
operator: ===
right: "GitHub Actions"
else:
- type: respond
with: e-action-result.md
- type: respond
with: 09_workflow-completed.md
issue: "%store.fourthIssueNumber%"
- type: respond
with: 09_issue-activity.md
issue: "%store.fourthIssueNumber%"
data:
quicklink: "%payload.repository.html_url%/issues/new"
- title: Course recap
description: Final notes on course
event: check_suite.completed
link: "{{repoUrl}}/issue/8"
actions:
- type: gate
left: "%payload.check_suite.app.name%"
operator: ===
right: "GitHub Actions"
else:
- type: respond
with: e-action-result.md
- type: respond
with: 10_workflow-completed.md
issue: 8
- type: respond
with: 10_course-recap.md
issue: 8
- type: removeBranchProtection