This repository was archived by the owner on Sep 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathconfig.yml
336 lines (264 loc) · 9.32 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
# Course information
title: "GitHub Actions: Continuous Delivery with AWS"
description: Create two deployment workflows using AWS.
tags:
- GitHub Actions
- Workflows
- CD
- Amazon Web Services (AWS)
- Deployment
template:
name: github-actions-continuous-delivery
repo: continuous-delivery-aws-template
# Before
before:
# Repository must have a main branch with the working code, and 4 other branches:
# staging-workflow: with the workflow file stub for staging from label
# aws-configuration: with blank/stub files for `aws-config.yml` and `sam-template.yml`
# production-deployment-workflow: with the workflow file stub for production deploy from merge
# staging-test: with a small change to the app that can be seen in staging
# we create a staging label that will be used later to test
- type: createLabel
name: stage
color: f87000
# PART 1: STAGING WORKFLOW
# Step 1: Configure a trigger based on labels
# Before step: Pull request will be open with overview of workflow file.
- type: createPullRequest
title: Create a staging workflow
body: 01_label-trigger.md
head: staging-workflow
# protected branch
- type: updateBranchProtection
steps:
# Step 1: User commits the proper trigger
- title: Configure a trigger based on labels
description: Configure the workflow trigger based on an a label being added
event: pull_request.synchronize
link: '{{ repoUrl }}/pull/1'
actions:
- type: getFileContents
action_id: fileContents
filename: '.github/workflows/deploy-staging.yml'
required: false
# We validate that trigger is correct
- type: gate
every: true
gates:
- left: '%payload.pull_request.title%'
operator: ===
right: Create a staging workflow
- left: '/on:\s*\n\s*pull_request:\s*\n\s*types:\s*\[\s*labeled\s*\]\s*/gi'
operator: test
right: '%actions.fileContents%'
else:
- type: respond
with: 0Xe_unexpected.md
data:
expected: commit the file `.github/workflows/deploy-staging.yml` and a `[labeled]` trigger on the `staging-workflow` branch
# Step 2: Trigger a job on specific labels
# We tell the user to write the proper environment in the workflow file
- type: respond
with: 02_conditional.md
# event: User commits proper environment in workflow
- title: Trigger a job on specific labels
description: Use a conditional to trigger a job on a specific label
event: pull_request.synchronize
link: '{{ repoUrl }}/pull/1'
actions:
- type: getFileContents
action_id: fileContents
filename: '.github/workflows/deploy-staging.yml'
required: false
# We validate
- type: gate
left: /\s*if:\s*contains\s*\(\s*github\.event\.pull_request\.labels\.\*\.name,\s*'stage'\)/gi
operator: test
right: '%actions.fileContents%'
else:
- type: respond
with: 0Xe_unexpected.md
data:
expected: "the conditional `if: contains(github.event.pull_request.labels.*.name, 'stage')` in the `.github/workflows/deploy-staging.yml` file"
# Step 3: Write the steps for the staging workflow
# We tell the user to write the proper steps for the workflow
- type: respond
with: 03_workflow-steps.md
# event: commit, user writes the steps for the workflow, using recommended existing GitHub steps
- title: Deploy a Node.js app to AWS for the first time
description: Use the GitHub-created action to deploy to AWS
event: pull_request
link: '{{ repoUrl }}/pull/1'
actions:
# We validate
#- type: gate
# We remove branch protections
- type: removeBranchProtection
# Step 4: Merge the staging workflow
# We tell the user to merge
- type: respond
with: 04_merge-staging.md
# event: merge
- title: Merge the staging workflow
description: Merge this staging workflow pull request
event: pull_request.closed
link: '{{ repoUrl }}/pull/1'
actions:
# we make sure it's merged
- type: gate
every: true
gates:
- left: '%payload.action%'
operator: ===
right: closed
- left: '%payload.pull_request.merged%'
# we reprotect main for the next PR
- type: updateBranchProtection
# PART 2: AWS CONFIGURATION
# Step 5: Confirm AWS configuration
# We open a PR, we ask user to confirm AWS account configuration by responding with :+1:
- type: createPullRequest
title: Configure AWS
body: 05_confirm-aws.md
head: aws-configuration
action_id: awsPR
# we point user to new PR
- type: respond
with: 0X_next-steps.md
data:
url: '%actions.awsPR.data.html_url%'
# event: responding with a comment
- title: Create an S3 bucket
description: Create an S3 bucket in AWS and tell the action where to find it
event: pull_request.synchronize
link: '{{ repoUrl }}/pull/2'
actions:
# Step 7: Approve pull request adding aws-config.yml and sam-template.yml
# We explain what the purpose of these templates are, and ask the user to approve
- type: respond
with: 07_approve.md
# we formally request their approval
- type: requestReviewFromRegistrant
pullRequest: Configure AWS
# event: approval
- title: Approve pull request
description: Approve pull request adding the aws-config.yml and sam-template.yml
event: pull_request_review
link: '{{ repoUrl }}/pull/2'
actions:
# we make sure it's approved
- type: gate
left: '%payload.review.state%'
operator: ===
right: approved
else:
- type: respond
with: 07_approve-pr.md
# we merge
- type: mergeBranch
head: aws-configuration
base: main
# merge main into staging-test so staging-test has the appropriate updates
- type: mergeBranch
head: main
base: staging-test
# we must prepare next pr now so we can point to it. We ask the user to test this action by adding a label
- type: createPullRequest
title: Test the staging action
body: 08_test.md
head: staging-test
action_id: testPR
# we point user to next pull request
- type: respond
with: 0X_next-steps.md
data:
url: '%actions.testPR.data.html_url%'
# PART 3: TEST STAGING WORKFLOW
# Step 8: Test the staging action
# event: label added, and deployment successful
- title: Test the staging action
description: Test the new action to deploy labeled pull requests to staging
event: pull_request.labeled
link: '{{ repoUrl }}/pull/3'
actions:
# We need to prepare next PR for them where they write the prod deployment workflow
- type: createPullRequest
title: Production deployment workflow
body: 09_merge-trigger.md
head: production-deployment-workflow
action_id: prodPR
# We respond and tell them what to expect
- type: respond
with: 08_deployment.md
data:
url: '%actions.prodPR.data.html_url%'
# PART 4: PRODUCTION DEPLOYMENT WORKFLOW
# Step 9: Write the production deployment trigger
# event: User commits the proper trigger
- title: Write the production deployment trigger
description: Write the production deployment trigger in the new workflow
event: pull_request
link: '{{ repoUrl }}/pull/3'
actions:
# We validate
- type: getFileContents
action_id: fileContents
filename: '.github/workflows/deploy-prod.yml'
required: false
# We validate that trigger is correct
- type: gate
every: true
gates:
- left: '%payload.pull_request.title%'
operator: ===
right: Production deployment workflow
- left: '%actions.fileContents%'
else:
- type: respond
with: 0Xe_unexpected.md
data:
expected: commit the file `.github/workflows/deploy-prod.yml` on a pull request titled "Production deployment workflow"
# Step 10: Choose the environment for AWS
# We tell the user to write the proper environment
- type: respond
with: 10_deploy-prod.md
# event: commit, user writes the environment
- title: Complete the deployment to production workflow
description: Commit the steps to the production workflow that allow you to deploy on merge to main.
event: pull_request
link: '{{ repoUrl }}/pull/3'
actions:
# We validate
# - type: gate
# Step 11: Create the Docker image and push it to GitHub Packages
# We tell the user to write the proper steps for the workflow
- type: respond
with: 11_workflow-steps.md
# event: commit, user writes the steps for the workflow, using recommended existing GitHub steps
- title: Create the Docker image and push it to GitHub Packages
description: Add a step to the workflow for building and pushing a Docker image to GitHub Packages.
event: pull_request
link: '{{ repoUrl }}/pull/3'
actions:
# We validate
# type: gate
# We approve
# PART 5: TEST WORKFLOWS
# Step 12: Merge this pull request and test the production deployment workflow
# We remove branch protections
- type: removeBranchProtection
# We tell the user to merge, and that their merge will bring the action into `main`, and will also create a deployment into production
- type: respond
with: 12_merge.md
# event: merge
- title: Merge the production workflow
description: Merge this pull request and test the production deployment workflow
event: pull_request.closed
link: '{{ repoUrl }}/pull/3'
actions:
# check that its merged
- type: gate
left: '%payload.pull_request.merged%'
# final response: congratulations
- type: respond
with: 12_congratulations.md