10
10
env :
11
11
IMAGE_NAME : penn-chime
12
12
KUBE_CONFIG_DATA : ${{ secrets.kubeconfig_data_preprod }}
13
+ # For hub CLI tool
14
+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
13
15
14
16
jobs :
15
17
# Run tests.
72
74
name : release
73
75
path : release
74
76
77
+ # Create the Deployment API object
78
+ new-deployment :
79
+ needs : release-data
80
+ runs-on : ubuntu-latest
81
+ if : github.event_name == 'release'
82
+
83
+ steps :
84
+ - name : Get release information
85
+ uses : actions/download-artifact@v1
86
+ with :
87
+ name : release
88
+
89
+ - name : Create deployment object for release
90
+ run : |
91
+ set -e
92
+ # Determine deployment environment
93
+ if ${{ github.event.release.prerelease }}; then
94
+ target=preprod
95
+ else
96
+ target=prod
97
+ fi
98
+
99
+ # Create deployment
100
+ hub api /repos/${{ github.repository }}/deployments -X POST --input <(cat <<EOF
101
+ {
102
+ "ref": "$(cat release/tag)",
103
+ "auto_merge": false,
104
+ "required_contexts": [],
105
+ "environment": "$target"
106
+ }
107
+ EOF) > /tmp/deployment.json
108
+
109
+ # Set status to pending
110
+ hub api /repos/${{ github.repository }}/deployments/$(jq .id < /tmp/deployment.json)/statuses \
111
+ -X POST \
112
+ -H "Accept: application/json, application/vnd.github.flash-preview+json" \
113
+ --input <(cat <<EOF
114
+ {
115
+ "state": "pending",
116
+ "description": "Building deployment artifacts",
117
+ "log_url": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
118
+ }
119
+ EOF)
120
+
75
121
# Push image to GitHub Packages.
76
122
# See also https://docs.docker.com/docker-hub/builds/
77
123
publish-image :
@@ -91,6 +137,10 @@ jobs:
91
137
with :
92
138
name : release
93
139
140
+ - name : Get deployment information
141
+ run : |
142
+ hub api /repos/${{ github.repository }}/deployments?ref=$(cat release/tag) -X GET | jq .[0] > /tmp/deployment.json
143
+
94
144
- name : Build image
95
145
run : docker build . --file Dockerfile --tag image
96
146
@@ -112,6 +162,20 @@ jobs:
112
162
echo prod release published to :latest
113
163
fi
114
164
165
+ - name : Mark deployment as failed
166
+ if : failure()
167
+ run : |
168
+ hub api /repos/${{ github.repository }}/deployments/$(jq .id < /tmp/deployment.json)/statuses \
169
+ -X POST \
170
+ -H "Accept: application/json, application/vnd.github.flash-preview+json" \
171
+ --input <(cat <<EOF
172
+ {
173
+ "state": "failure",
174
+ "description": "Error in job publish-image",
175
+ "log_url": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
176
+ }
177
+ EOF)
178
+
115
179
publish-manifests :
116
180
117
181
# Published manifests will signify successful image build
@@ -127,6 +191,10 @@ jobs:
127
191
with :
128
192
name : release
129
193
194
+ - name : Get deployment information
195
+ run : |
196
+ hub api /repos/${{ github.repository }}/deployments?ref=$(cat release/tag) -X GET | jq .[0] > /tmp/deployment.json
197
+
130
198
- name : Build manifest archive
131
199
run : |
132
200
tagname=$(cat release/tag)
@@ -155,6 +223,20 @@ jobs:
155
223
files : ' *.zip'
156
224
repo-token : ${{ secrets.GITHUB_TOKEN }}
157
225
226
+ - name : Mark deployment as failed
227
+ if : failure()
228
+ run : |
229
+ hub api /repos/${{ github.repository }}/deployments/$(jq .id < /tmp/deployment.json)/statuses \
230
+ -X POST \
231
+ -H "Accept: application/json, application/vnd.github.flash-preview+json" \
232
+ --input <(cat <<EOF
233
+ {
234
+ "state": "failure",
235
+ "description": "Error in job publish-manifests",
236
+ "log_url": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
237
+ }
238
+ EOF)
239
+
158
240
deploy-preprod :
159
241
160
242
needs : publish-manifests
@@ -179,6 +261,23 @@ jobs:
179
261
with :
180
262
name : release
181
263
264
+ - name : Get deployment information
265
+ run : |
266
+ hub api /repos/${{ github.repository }}/deployments?ref=$(cat release/tag) -X GET | jq .[0] > /tmp/deployment.json
267
+
268
+ - name : Mark deployment as started
269
+ run : |
270
+ hub api /repos/${{ github.repository }}/deployments/$(jq .id < /tmp/deployment.json)/statuses \
271
+ -X POST \
272
+ -H "Accept: application/json, application/vnd.github.flash-preview+json" \
273
+ --input <(cat <<EOF
274
+ {
275
+ "state": "in_progress",
276
+ "description": "Rolling out $(cat release/tag)",
277
+ "log_url": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
278
+ }
279
+ EOF)
280
+
182
281
- name : Get manifest archive
183
282
run : |
184
283
set -e
@@ -201,6 +300,33 @@ jobs:
201
300
kubectl -n chime rollout status deployment.v1.apps/chime
202
301
kubectl -n chime get deployment/chime -o yaml
203
302
303
+ - name : Mark deployment as failed
304
+ if : failure()
305
+ run : |
306
+ hub api /repos/${{ github.repository }}/deployments/$(jq .id < /tmp/deployment.json)/statuses \
307
+ -X POST \
308
+ -H "Accept: application/json, application/vnd.github.flash-preview+json" \
309
+ --input <(cat <<EOF
310
+ {
311
+ "state": "failure",
312
+ "description": "Error in job deploy-preprod",
313
+ "log_url": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
314
+ }
315
+ EOF)
316
+
317
+ - name : Mark deployment completed
318
+ run : |
319
+ hub api /repos/${{ github.repository }}/deployments/$(jq .id < /tmp/deployment.json)/statuses \
320
+ -X POST \
321
+ -H "Accept: application/json, application/vnd.github.flash-preview+json" \
322
+ --input <(cat <<EOF
323
+ {
324
+ "state": "success",
325
+ "description": "$(cat release/tag) deployed",
326
+ "log_url": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
327
+ }
328
+ EOF)
329
+
204
330
stage-prod-deploy :
205
331
needs : publish-manifests
206
332
if : github.event_name == 'release' && ! github.event.release.prerelease
@@ -229,7 +355,6 @@ jobs:
229
355
run : |
230
356
echo "::set-env name=VERSION::$(cat release/version)"
231
357
echo "::set-env name=TAGNAME::$(cat release/tag)"
232
- echo "::set-env name=GITHUB_TOKEN::${{ secrets.GITHUB_TOKEN }}"
233
358
234
359
- name : Get manifest archive
235
360
run : |
@@ -240,6 +365,10 @@ jobs:
240
365
curl -LO "$arc_url"
241
366
unzip $arc_fname
242
367
368
+ - name : Get deployment information
369
+ run : |
370
+ hub api /repos/${{ github.repository }}/deployments?ref=$(cat release/tag) -X GET | jq .[0] > /tmp/deployment.json
371
+
243
372
- name : Open deployment pull request
244
373
run : |
245
374
set -e
@@ -254,4 +383,32 @@ jobs:
254
383
\`\`\`
255
384
EOF
256
385
257
- hub pull-request -b releases/v1 -h develop -F $pr_body_file
386
+ hub pull-request -b releases/v1 -h develop -F $pr_body_file > /tmp/pr.json
387
+
388
+ - name : Mark deployment as failed
389
+ if : failure()
390
+ run : |
391
+ hub api /repos/${{ github.repository }}/deployments/$(jq .id < /tmp/deployment.json)/statuses \
392
+ -X POST \
393
+ -H "Accept: application/json, application/vnd.github.flash-preview+json" \
394
+ --input <(cat <<EOF
395
+ {
396
+ "state": "failure",
397
+ "description": "Error in job stage-prod-deploy",
398
+ "log_url": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
399
+ }
400
+ EOF)
401
+
402
+ - name : Mark deployment queued
403
+ run : |
404
+ # Update status to success
405
+ hub api /repos/${{ github.repository }}/deployments/$(jq .id < /tmp/deployment.json)/statuses \
406
+ -X POST \
407
+ -H "Accept: application/json, application/vnd.github.flash-preview+json" \
408
+ --input <(cat <<EOF
409
+ {
410
+ "state": "queued",
411
+ "description": "Awaiting approval/merge of deployment Pull Request",
412
+ "log_url": "$(jq < /tmp/pr.json .html_url)"
413
+ }
414
+ EOF)
0 commit comments