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 16
/
config.yml
568 lines (546 loc) · 22 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
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
title: "GitHub Actions: Continuous Integration"
description: Learn how to create workflows that enable you to use Continuous Integration (CI) for your projects.
tags:
- GitHub Actions
- Workflows
- CI
- Continuous Integration
- Integration
template:
repo: using-github-actions-for-ci-template
name: github-actions-for-ci
before:
# 1. Bot creates [Tic tac toe game](https://github.com/githubtraining/actions-template) for the learner, protects main branch
# 1. Bot opens a bug report explaining the app is broken, asks learner to figure out what's wrong by adding some testing.
- type: updateBranchProtection
- type: createIssue
title: There's a bug!
body: 00_bug.md
data:
actionsUrl: "{{ payload.repository.html_url }}/actions/new"
store:
first_issue_url: "{{ result.data.html_url }}"
# Repository artifacts:
# 1. Issue: There's a bug!
# 2. PR: CI for Node (learner)
# 3. PR: Add jest tests (bot)
# 4. Issue: A workflow for the entire team
# 5. PR: Improve CI (learner)
# 6. PR: A custom workflow (bot)
# 7. Issue: Congratulations
steps:
# Step 1
# 1. Learner opens a PR with a new workflow by using the [templated workflow for Node](https://github.com/actions/starter-workflows/blob/main/ci/node.js.yml)
# 1. Bot leaves line-specific comments explaining the pieces that were just added from the templated workflow.
- title: Use a templated workflow
description: Create a pull request with a templated workflow
event: pull_request
link: "{{ store.first_issue_url }}"
actions:
- type: gate
gates:
- left: "%payload.action%"
operator: ===
right: opened
- left: "%payload.action%"
operator: ===
right: edited
- type: gate
left: "%payload.pull_request.title%"
operator: ===
right: CI for Node
else:
- type: respond
with: e-rename-pr.md
data:
title: CI for Node
store:
ci_for_node_pr: "{{ payload.pull_request.number }}"
- type: respond
with: 01_explain-template.md
data:
actionsUrl: "%payload.repository.html_url%/actions"
- type: createPullRequestComment
position: 6
file: .github/workflows/node.js.yml
body: 01_explain-on.md
- type: createPullRequestComment
position: 12
file: .github/workflows/node.js.yml
body: 01_explain-job.md
- type: createPullRequestComment
position: 21
file: .github/workflows/node.js.yml
body: 01_explain-checkout.md
- type: createPullRequestComment
position: 27
file: .github/workflows/node.js.yml
body: 01_explain-run.md
- type: createPullRequest
title: Add jest tests
body: 01_merge-jest.md
base: "%payload.pull_request.head.ref%"
head: add-jest
store:
second_pr_url: "{{ result.data.html_url }}"
# Step 2
# 1. GitHub sends us a workflow run.
# 1. Bot explains what is happening, and why the page build failed (we don't have a [test script](https://github.com/githubtraining/actions-template/blob/main/package.json#L10))
- title: Run a templated workflow
description: Wait for GitHub to run the templated workflow and report back the results
event: check_suite.completed
link: "{{ store.second_pr_url }}"
actions:
- type: gate
left: "%payload.check_suite.app.slug%"
operator: ===
right: github-actions
- type: respond
with: 0X_merge.md
issue: Add jest tests
action_id: jestPr
- type: respond
issue: CI for Node
with: 02_template-workflow-ran.md
data:
url: "%actions.jestPr.data.html_url%"
actionsUrl: "%payload.repository.html_url%/actions"
# Step 3
# 1. Learner adds a `test` script to `package.json`. Workflow still fails because the tests themselves are missing.
# 1. Bot commits changes with Jest files, explains testing framework, asks learner to fix the code based on the results of the tests. Explains how to read results.
- title: Add your first test
description: Add your first test script for CI to pick up
event: pull_request.synchronize
link: "{{ store.second_pr_url }}"
actions:
- type: respond
with: 03_wait-for-first-test.md
data:
actionsUrl: "%payload.repository.html_url%/actions"
- type: respond
with: 0X_goto.md
issue: Add jest tests
data:
url: "%payload.pull_request.html_url%"
# Step 4
# 1. Learner reviews log in the Actions tab, fixes the code as suggested.
# 1. Bot validates learner's work
# 1. Bot asks learner to fix the test
- title: Read an Actions log
description: Tell the bot which test is failing so we can fix it
event: issue_comment.created
link: "{{ store.second_pr_url }}"
actions:
- type: gate
left: "/(Contains the compiled JavaScript)|(Initializes with two players)|(Starts the game with a random player)|(Sets the current player to be whoever it is not)/gim"
operator: test
right: "%payload.comment.body%"
required: false
else:
- type: respond
with: e-test-name.md
- type: getPullRequest
pullRequest: "{{ store.ci_for_node_pr }}"
action_id: ciPr
- type: respond
with: 04_read-failed-log.md
data:
gameJSUrl: "%payload.repository.html_url%/edit/%actions.ciPr.data.head.ref%/src/game.js?pr=/%payload.repository.full_name%/pull/%actions.ciPr.data.number%"
- type: createPullRequestComment
position: 5
file: src/game.js
body: 04_test-suggestion.md
pullRequest: "%actions.ciPr.data.number%"
# - type: createPullRequestComment
# pullRequest: CI for Node
# position: 5
# file: src/game.js
# body: fix-bananas.md
# Step 5
# 1. Learner fixes the code that broke the build
# 1. Bot approves PR. Let's merge the PR
- title: Fix the test
description: Edit the file that's causing the test to fail
event: check_suite.completed
link: "{{ store.second_pr_url }}"
actions:
- type: gate
left: "%payload.check_suite.app.slug%"
operator: ===
right: github-actions
- type: gate
left: "%payload.check_suite.conclusion%"
operator: ===
right: success
else:
- type: respond
with: e-failed-run.md
issue: CI for Node
data:
troubleshooting: >-
- Make sure line 4 of `src/game.js` reads: `this.p2 = p2`
- In the change you're making in `src/game.js`, make sure you're using the same amount of indentation as the surrounding lines
- Ensure you didn't edit any unexpected files. This PR should only contain changes to `src/game.js`, `.github/workflows/node.js.yml`, and `__test__/game.test.js`.
- If all fails, read the logs! They'll contain the most context-specific troubleshooting information. Click on "Details" in the merge box below, or go to the Actions tab directly.
- type: createReview
event: APPROVE
body: 0X_merge.md
pullRequest: CI for Node
# Step 6
# 1. Learner merges PR
# 1. Bot opens issue with description of the team's workflow, would like learner to help automate some of the tasks the team goes through. The requested changes require: branch protections, review approvals, easy way to see when enough approvals has been achieved, matrix build, save build artifacts, dedicated test job. We'll tackle some of the changes to the existing workflow file first, open a PR to target different Node versions.
- title: Share the workflow with the team
description: Merge the pull request containing your first workflow so the entire team can use it
event: pull_request.closed
link: "{{ store.second_pr_url }}"
actions:
- type: gate
every: true
gates:
- left: "%payload.pull_request.merged%"
- left: "%payload.pull_request.title%"
operator: ===
right: CI for Node
- type: createIssue
title: A workflow for the entire team
body: 06_custom-workflow.md
action_id: newIssue
data:
workflowUrl: "%payload.repository.html_url%/edit/main/.github/workflows/node.js.yml"
store:
workflow_issue_url: "{{ result.data.html_url }}"
- type: respond
with: 0X_goto.md
data:
url: "%actions.newIssue.data.html_url%"
# Step 7
# 1. Learner edits the first workflow changing from templated [Node v8,10,12 to just v8,10](https://github.com/githubtraining/actions-template/blob/main/.github/workflows/node.js.yml#L10).
# 1. Bot asks learner to add a build for Windows
- title: Create a custom GitHub Actions workflow
description: Edit the existing workflow with new build targets
event: pull_request
link: "{{ store.workflow_issue_url }}"
actions:
- type: gate
gates:
- left: "%payload.action%"
operator: ===
right: opened
- left: "%payload.action%"
operator: ===
right: edited
- type: gate
left: "%payload.pull_request.title%"
operator: ===
right: Improve CI
else:
- type: respond
with: e-rename-pr.md
data:
title: Improve CI
# - type: findInTree
# path: .github/workflows/node.js.yml
# action_id: nodeAction
# - type: gate
# left: '%actions.nodeAction%'
# else:
# - type: respond
# with: e-missing-file.md
# data:
# expected: .github/workflows/nodejs.yaml
- type: respond
with: 07_explain-build-matrix.md
- type: createPullRequestComment
position: 5
file: .github/workflows/node.js.yml
body: 07_add-windows.md
data:
fileUrl: "%payload.repository.html_url%/edit/%payload.pull_request.head.ref%/.github/workflows/node.js.yml?pr=/%payload.repository.full_name%/pull/%payload.number%"
store:
node_version_pr: "{{ payload.pull_request.html_url }}"
# Step 8
# 1. Learner adds Windows to the [matrix os](https://github.com/githubtraining/actions-template/blob/main/.github/workflows/node.js.yml#L9)
# 1. Bot asks learner to add a new job for testing, and separate out the test script into that new job.
- title: Target a Windows environment
description: Edit your workflow file to build for Windows environments
event: pull_request.synchronize
link: "{{ store.node_version_pr }}"
actions:
# - type: findInTree
# path: .github/workflows/node.js.yml
# action_id: nodeAction
# - type: gate
# left: '%actions.nodeAction%'
# else:
# - type: respond
# with: e-missing-file.md
# data:
# expected: .github/workflows/nodejs.yaml
- type: respond
with: 08_new-job.md
data:
fileUrl: "%payload.repository.html_url%/edit/%payload.pull_request.head.ref%/.github/workflows/node.js.yml?pr=/%payload.repository.full_name%/pull/%payload.number%"
# Step 9
# 1. Learner creates a new job, moves `npm test` down to that job
- title: Use multiple jobs
description: Edit your workflow file to separate build and test jobs
event: pull_request.synchronize
link: "{{ store.node_version_pr }}"
actions:
# - type: findInTree
# path: .github/workflows/node.js.yml
# action_id: nodeAction
# - type: gate
# left: '%actions.nodeAction%'
# else:
# - type: respond
# with: e-missing-file.md
# data:
# expected: .github/workflows/nodejs.yaml
- type: respond
with: 09_wait-for-test.md
data:
fileUrl: "%payload.repository.html_url%/edit/%payload.pull_request.head.ref%/.github/workflows/node.js.yml?pr=/%payload.repository.full_name%/pull/%payload.number%"
# Step 10
# 1. GitHub sends a failed `check_run` (we don't have build artifacts in the second job)
# 1. Bot explains what happens to a job's artifacts, and that they need to be saved, asks learner to upload the artifacts in the build job
- title: Run multiple jobs
description: Wait for the result of multiple jobs in your workflow
event: check_suite.completed
link: "{{ store.node_version_pr }}"
actions:
- type: gate
left: "%payload.check_suite.app.slug%"
operator: ===
right: github-actions
- type: getPullRequest
pullRequest: Improve CI
action_id: ciPr
- type: respond
issue: Improve CI
with: 10_use-upload.md
data:
fileUrl: "%payload.repository.html_url%/edit/%actions.ciPr.data.head.ref%/.github/workflows/node.js.yml?pr=/%payload.repository.full_name%/pull/%actions.ciPr.data.number%"
- type: createPullRequestComment
position: 15
file: .github/workflows/node.js.yml
body: 10_upload-suggestion.md
pullRequest: "%actions.ciPr.data.number%"
# Step 11
# 1. Learner uses the [`actions/upload-artifacts`](https://github.com/actions/upload-artifact) in the build job
# 1. Bot asks learner to now download the artifacts in the test job
- title: Upload a job's build artifacts
description: Use the upload action in your workflow file to save a job's build artifacts
event: pull_request.synchronize
link: "{{ store.node_version_pr }}"
actions:
# - type: findInTree
# path: .github/workflows/node.js.yml
# action_id: nodeAction
# - type: gate
# left: '%actions.nodeAction%'
# else:
# - type: respond
# with: e-missing-file.md
# data:
# expected: .github/workflows/nodejs.yaml
- type: respond
with: 11_use-download.md
data:
fileUrl: "%payload.repository.html_url%/edit/%payload.pull_request.head.ref%/.github/workflows/node.js.yml?pr=/%payload.repository.full_name%/pull/%payload.number%"
- type: createPullRequestComment
position: 17
file: .github/workflows/node.js.yml
body: 11_needs-suggestion.md
- type: createPullRequestComment
position: 31
file: .github/workflows/node.js.yml
body: 11_download-suggestion.md
# Step 12
# 1. Learner commits [`actions/download-artifacts`](https://github.com/actions/download-artifact) to the test job
- title: Download a job's build artifacts
description: Use the download action in your workflow file to access a prior job's build artifacts
event: pull_request.synchronize
link: "{{ store.node_version_pr }}"
actions:
# - type: findInTree
# path: .github/workflows/node.js.yml
# action_id: nodeAction
# - type: gate
# left: '%actions.nodeAction%'
# else:
# - type: respond
# with: e-missing-file.md
# data:
# expected: .github/workflows/nodejs.yaml
- type: createReview
event: APPROVE
body: 12_merge-improved-ci.md
# Step 13
- title: Share the improved CI workflow with the team
description: Merge the pull request with the improved workflow
link: "{{ store.node_version_pr }}"
event: pull_request.closed
actions:
- type: gate
every: true
gates:
- left: "%payload.pull_request.merged%"
- left: "%payload.pull_request.title%"
operator: ===
right: Improve CI
- type: mergeBranch
head: main
base: team-workflow
- type: createPullRequest
title: A custom workflow
body: 13_partial-workflow.md
head: team-workflow
action_id: newPR
data:
workflowIssue: "{{ store.workflow_issue_url }}"
fileUrl: "%payload.repository.html_url%/new/team-workflow/?filename=.github/workflows/approval-workflow.yml"
store:
workflow_pr_url: "{{ result.data.html_url }}"
- type: respond
with: 0X_goto.md
data:
url: "%actions.newPR.data.html_url%"
# Step 14
# 1. GitHub sends a successful `check_run`
# 1. Bot says we're now going to automate review approvals, asks learner to create a new workflow in the PR now and to add a blank step to the workflow for approval automation.
# 1. Learner commits a new, mostly blank, workflow file, chooses a name for the workflow
# 1. Bot asks the learner to choose an event, explains how those events trigger the workflow
- title: Automate the review process
description: Add a new workflow file to automate the team's review process
link: "{{ store.workflow_pr_url }}"
event: pull_request.synchronize
actions:
- type: gate
left: "%payload.pull_request.title%"
operator: ===
right: A custom workflow
- type: respond
with: 14_choose-event.md
- type: createPullRequestComment
position: 1
file: .github/workflows/approval-workflow.yml
body: 14_event-suggestion.md
data:
editUrl: "%payload.repository.html_url%/edit/%payload.pull_request.head.ref%/.github/workflows/approval-workflow.yml?pr=/%payload.repository.full_name%/pull/%payload.number%"
# Step 15
# 1. Learner adds the `pull_request_review` event to the workflow file.
# 1. Bot asks learner to add a job with their own title, explains what that does
- title: Use an action to automate pull request reviews
description: Use the community action in your new workflow
link: "{{ store.workflow_pr_url }}"
event: pull_request.synchronize
actions:
- type: gate
left: "%payload.pull_request.title%"
operator: ===
right: A custom workflow
- type: respond
with: 15_add-job.md
- type: createPullRequestComment
position: 2
file: .github/workflows/approval-workflow.yml
body: 15_add-job-suggestion.md
data:
editUrl: "%payload.repository.html_url%/edit/%payload.pull_request.head.ref%/.github/workflows/approval-workflow.yml?pr=/%payload.repository.full_name%/pull/%payload.number%"
# Step 16
# 1. Learner adds a job
# 1. Bot asks learner to choose a virtual environment, bot explains environment options and why we'd like to pick a specific one
- title: Create an approval job in your new workflow
description: In your new workflow file, create a new job that'll use the community action
link: "{{ store.workflow_pr_url }}"
event: pull_request.synchronize
actions:
- type: gate
left: "%payload.pull_request.title%"
operator: ===
right: A custom workflow
- type: respond
with: 16_add-step.md
data:
editUrl: "%payload.repository.html_url%/edit/%payload.pull_request.head.ref%/.github/workflows/approval-workflow.yml?pr=/%payload.repository.full_name%/pull/%payload.number%"
# Step 17
# 1. Learner commits the `runs-on` and chooses an environment
# 1. Bot asks learner to create a step for approval automation, using the [`pullreminders/label-when-approved-action` action](https://github.com/pullreminders/label-when-approved-action)
# 1. Bot removes branch protections
# 1. Bot points out that branch protections aren't currently in place, asks learner to set branch protections, and approve the PR
- title: Automate approvals
description: Use the community action to automate part of the review approval process
link: "{{ store.workflow_pr_url }}"
event:
- pull_request.synchronize
- issue_comment.created
actions:
- type: gate
left: "%payload.pull_request.title%"
operator: ===
right: A custom workflow
else:
- type: gate
left: "/hint/gi"
operator: test
right: "%payload.comment.body%"
- type: createPullRequestComment
position: 5
file: .github/workflows/approval-workflow.yml
body: 17_add-step-suggestion.md
pullRequest: "%payload.issue.number%"
data:
editUrl: "%payload.repository.html_url%/edit/%payload.pull_request.head.ref%/.github/workflows/approval-workflow.yml?pr=/%payload.repository.full_name%/pull/%payload.number%"
- type: removeBranchProtection
- type: requestReviewFromRegistrant
- type: respond
with: 17_protect-main.md
data:
settingsUrl: "%payload.repository.html_url%/settings"
approvalUrl: "%payload.pull_request.html_url%/files#submit-review"
# Step 18
# 1. Learner sets branch protection and approves the PR
# 1. Action runs and applies a label
# 1. Bot checks that branch protections are in place, asks the learner to fix it if not. Learner may have to re-approve.
# 1. Bot comments that this action can be used to automatically deploy changes.
# 1. Bot merges PR.
# 1. Bot turns on pages build, drops link in the PR, explains to the learner the value on a workflow that enforces team behaviors.
- title: Use branch protections
description: Complete the automated review process by protecting the main branch
link: "{{ store.workflow_pr_url }}"
event:
- pull_request_review.submitted
- pull_request.labeled
actions:
- type: gate
every: true
gates:
- left: "%payload.review.state%"
operator: ===
right: approved
- left: "%payload.pull_request.title%"
operator: ===
right: A custom workflow
- type: octokit
method: repos.getBranch
owner: "%payload.repository.owner.login%"
repo: "%payload.repository.name%"
branch: main
action_id: branchProtection
- type: gate
left: "%actions.branchProtection.data.protected%"
else:
- type: respond
with: e-protect.md
- type: createIssue
title: Congratulations!
body: 18_congratulations.md
action_id: finalIssue
- type: respond
with: 18_labeled.md
- type: mergePullRequest
- type: respond
with: 0X_goto.md
data:
url: "%actions.finalIssue.data.html_url%"