-
Notifications
You must be signed in to change notification settings - Fork 44
425 lines (409 loc) · 14.3 KB
/
release.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
name: Publish artifacts
on:
push:
branches:
- 'main'
paths:
- "router/**"
- "subgraphs/**"
workflow_dispatch:
inputs:
rebuildAll:
description: 'Rebuild/publish all packages (yes/no)'
required: false
default: 'yes'
forceVersionBump:
description: 'Force version bump all packages (yes/no)'
required: false
default: 'no'
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
good-commits:
name: Check commits
runs-on: ubuntu-latest
outputs:
count: ${{ steps.commits.outputs.count }}
steps:
- uses: actions/checkout@v3
- name: Info
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "$GITHUB_CONTEXT"
-
name: check commits
id: commits
env:
COMMITS: ${{ toJson(github.event.commits) }}
run: |
if [[ "$COMMITS" != "null" ]]; then
MATCHING_COMMITS=$(jq -c ' . | map(select( .message | contains("CI: Bump artifact versions") | not )) ' <<< "$COMMITS" )
echo "$MATCHING_COMMITS" | jq
RESULT=$( echo "$MATCHING_COMMITS" | jq ' length ')
echo "RESULT: $RESULT"
echo "::set-output name=count::$RESULT"
else
echo "::set-output name=count::1"
fi
found-good-commits:
name: Found good commits
runs-on: ubuntu-latest
needs: good-commits
if: needs.good-commits.outputs.count > 0
steps:
- name: Found good commits
env:
COMMITS: ${{ toJson(github.event.commits) }}
run: |
echo "ALL COMMITS"
echo "$COMMITS" | jq
build-matrix:
name: Create build matrix
runs-on: ubuntu-latest
needs: good-commits
if: needs.good-commits.outputs.count > 0
outputs:
packages: ${{ steps.matrix.outputs.packages }}
matrix: ${{ steps.matrix.outputs.matrix }}
count: ${{ steps.matrix.outputs.count }}
steps:
- uses: actions/checkout@v3
-
name: generate matrix
id: matrix
env:
GITHUB_SHA: ${{ env.GITHUB_SHA}}
GITHUB_EVENT_BEFORE: ${{ github.event.before }}
REBUILD_ALL: ${{ github.event.inputs && github.event.inputs.rebuildAll == 'yes' }}
FORCE_VERSION_BUMP: ${{ github.event.inputs && github.event.inputs.forceVersionBump == 'yes' }}
run: |
if [[ "$FORCE_VERSION_BUMP" == "true" ]]; then
PACKAGES=$(.scripts/build-matrix.sh main force-version-bump)
else
PACKAGES=$(.scripts/build-matrix.sh)
fi
if [[ "$REBUILD_ALL" == "true" ]]; then
MATRIX="$PACKAGES"
else
MATRIX=$(jq -c ' .include |= map(select(.changes=="1")) ' <<< "$PACKAGES")
fi
echo "::set-output name=packages::$( echo "$PACKAGES" )"
echo "::set-output name=matrix::$( echo "$MATRIX" )"
echo "::set-output name=count::$( echo "$MATRIX" | jq ' .include | length ' )"
-
name: packages
env:
PACKAGES: ${{ steps.matrix.outputs.packages }}
MATRIX: ${{ steps.matrix.outputs.matrix }}
COUNT: ${{ steps.matrix.outputs.count }}
REBUILD_ALL: ${{ github.event.inputs && github.event.inputs.rebuildAll == 'yes' }}
run: |
echo "--------------------------------"
echo " ALL PACKAGES "
echo "--------------------------------"
echo "$PACKAGES" | jq
echo "--------------------------------"
echo " BUILD MATRIX "
echo "--------------------------------"
if [[ "$REBUILD_ALL" == "true" ]]; then
echo " *** FORCE REBUILD *** "
fi
if [[ "$COUNT" -eq 0 ]]; then
echo " *** EMPTY MATRIX *** "
fi
echo "$MATRIX" | jq
found-packages-to-build:
name: Package changes detected
runs-on: ubuntu-latest
needs: build-matrix
if: needs.build-matrix.outputs.count > 0
steps:
- name: Found ${{ needs.build-matrix.outputs.count }} packages to build
env:
PACKAGES: ${{ needs.build-matrix.outputs.packages }}
MATRIX: ${{ needs.build-matrix.outputs.matrix }}
COUNT: ${{ needs.build-matrix.outputs.count }}
REBUILD_ALL: ${{ github.event.inputs && github.event.inputs.rebuildAll == 'yes' }}
run: |
echo "--------------------------------"
echo " ALL PACKAGES "
echo "--------------------------------"
echo "$PACKAGES" | jq
echo "--------------------------------"
echo " BUILD MATRIX "
echo "--------------------------------"
if [[ "$REBUILD_ALL" == "true" ]]; then
echo " *** FORCE REBUILD *** "
fi
if [[ "$COUNT" -eq 0 ]]; then
echo " *** EMPTY MATRIX *** "
fi
echo "$MATRIX" | jq
docker-ci:
name: Docker CI
needs: [build-matrix]
if: needs.build-matrix.outputs.count > 0
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v3
-
name: install rover
run: |
echo ---------------------------------------------------------------
echo rover - installing ...
echo ---------------------------------------------------------------
curl -sSL https://rover.apollo.dev/nix/latest | sh
echo "$HOME/.rover/bin" >> ${GITHUB_PATH}
-
name: update docker-compose
run: |
which docker-compose && exit 0 || true
echo ---------------------------------------------------------------
echo docker-compose - installing ...
echo ---------------------------------------------------------------
BIN_DIR=$HOME/.docker-compose/bin
FILE=$BIN_DIR/docker-compose
mkdir -p $BIN_DIR
set -x
curl -L --fail https://github.com/docker/compose/releases/download/1.29.1/docker-compose-`uname -s`-`uname -m` -o $FILE
chmod +x $FILE
echo "downloaded $($FILE --version)"
echo "$BIN_DIR" >> ${GITHUB_PATH}
set +x
echo ---------------------------------------------------------------
-
name: check tools
run: |
echo ---------------------------------------------------------------
( set -x; which rover )
echo "$(rover --version)"
echo ---------------------------------------------------------------
( set -x; which docker-compose )
echo "$(docker-compose --version)"
echo ---------------------------------------------------------------
- name: make supergraph
run: |
make supergraph
- name: docker-compose up -d
run: |
docker-compose up -d
sleep 3
docker-compose logs
- name: smoke test
run: .scripts/smoke.sh 4000
- name: docker-compose down
run: docker-compose down
build-push:
runs-on: ubuntu-latest
needs: [docker-ci, build-matrix]
if: needs.build-matrix.outputs.count > 0
strategy:
matrix: ${{ fromJson(needs.build-matrix.outputs.matrix) }}
name: Build-push ${{ matrix.name }}
steps:
-
name: Info
run: |
echo --------------------------------------------
echo name: ${{ matrix.name }}
echo dir: ${{ matrix.dir }}
echo versionOld: ${{ matrix.versionOld }}
echo versionNew: ${{ matrix.versionNew }}
echo changes: ${{ matrix.changes }}
-
name: Checkout
uses: actions/checkout@v3
-
name: Set up QEMU
uses: docker/setup-qemu-action@v2
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
-
name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
context: ./${{ matrix.dir }}
push: true
tags: prasek/${{ matrix.name }}:${{ matrix.versionNew }}, prasek/${{ matrix.name }}:latest
-
name: Image digest
run: |
SHA=${{ steps.docker_build.outputs.digest }}
echo $SHA
echo "::set-output name=sha-${{ matrix.name }}::$( echo "$SHA" )"
k8s:
name: Smoke test - k8s
runs-on: ubuntu-latest
needs: [build-matrix, build-push]
if: |
always() &&
needs.build-matrix.outputs.count > 0
steps:
-
name: Checkout
uses: actions/checkout@v3
-
name: update kind
run: |
curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.11.1/kind-linux-amd64
chmod +x ./kind
mkdir -p $HOME/.kind/bin
mv ./kind $HOME/.kind/bin/kind
echo "PATH=$HOME/.kind/bin:$PATH" >> ${GITHUB_ENV}
-
name: test-k8s
run: .scripts/k8s-ci.sh
version-bump:
name: "Source PR: Bump versions"
runs-on: ubuntu-latest
needs: [build-matrix, build-push, k8s]
if: needs.build-matrix.outputs.count > 0
env:
PACKAGES: ${{ needs.build-matrix.outputs.packages }}
MATRIX: ${{ needs.build-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v3
-
name: Info
run: |
echo --------------------------------
echo ALL PACKAGES
echo --------------------------------
echo "$PACKAGES" | jq
echo --------------------------------
echo BUILD MATRIX
echo --------------------------------
echo "$MATRIX" | jq
-
name: verify-clean
env:
MATRIX: ${{ needs.build-matrix.outputs.matrix }}
run: |
# verify no changes
git diff --exit-code
- name: install kustomize
run: |
BIN_DIR="$HOME/.kustomize/bin"
mkdir -p $BIN_DIR
cd $BIN_DIR
curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash
echo "PATH=$PATH:$BIN_DIR" >> ${GITHUB_ENV}
-
name: version bump
id: version-bump
run: |
.scripts/bump-package-versions.sh "$MATRIX" >> $GITHUB_ENV
.scripts/bump-image-versions.sh "$MATRIX" >> $GITHUB_ENV
echo "$(git diff)"
-
name: create source repo pull request
id: cpr
uses: peter-evans/create-pull-request@v4
with:
token: ${{ secrets.PAT }}
committer: Supergraph Demo Bot <[email protected]>
author: Supergraph Demo Bot <[email protected]>
commit-message: 'CI: Bump artifact versions'
title: 'CI: Bump artifact versions'
body: |
${{ env.PACKAGE_BUMP_PR_MSG }}
${{ env.IMAGE_BUMP_PR_MSG }}
branch: version-bump
base: main
delete-branch: true
-
name: enable pull request automerge
if: |
steps.cpr.outputs.pull-request-operation == 'created' ||
steps.cpr.outputs.pull-request-operation == 'updated'
uses: peter-evans/enable-pull-request-automerge@v2
with:
token: ${{ secrets.PAT }}
pull-request-number: ${{ steps.cpr.outputs.pull-request-number }}
merge-method: rebase
- name: Check output
if: |
steps.cpr.outputs.pull-request-operation == 'created' ||
steps.cpr.outputs.pull-request-operation == 'updated'
run: |
echo PR CREATED or MODIFIED
echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}"
echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}"
- name: No changes detected
if: |
steps.cpr.outputs.pull-request-operation != 'created' &&
steps.cpr.outputs.pull-request-operation != 'updated'
run: |
echo "No changes detected."
config-pr:
name: "Config PR: Bump versions"
needs: [build-matrix, build-push, k8s]
env:
PACKAGES: ${{ needs.build-matrix.outputs.packages }}
MATRIX: ${{ needs.build-matrix.outputs.matrix }}
runs-on: ubuntu-latest
steps:
-
name: checkout supergraph-demo-k8s-graph-ops
uses: actions/checkout@v3
with:
token: ${{ secrets.PAT }}
repository: apollographql/supergraph-demo-k8s-graph-ops
-
name: version bump
id: version-bump
run: |
.scripts/bump-image-versions.sh "$MATRIX" >> $GITHUB_ENV
echo "$(git diff)"
-
name: create pull request
id: cpr
uses: peter-evans/create-pull-request@v4
with:
token: ${{ secrets.PAT }}
committer: Supergraph Demo Bot <[email protected]>
author: Supergraph Demo Bot <[email protected]>
commit-message: Bump image versions
title: Bump image versions
body: |
${{ env.IMAGE_BUMP_PR_MSG }}
branch: bump-image-versions
base: main
delete-branch: true
-
name: enable pull request automerge
if: |
steps.cpr.outputs.pull-request-operation == 'created' ||
steps.cpr.outputs.pull-request-operation == 'updated'
uses: peter-evans/enable-pull-request-automerge@v2
with:
token: ${{ secrets.PAT }}
repository: apollographql/supergraph-demo-k8s-graph-ops
pull-request-number: ${{ steps.cpr.outputs.pull-request-number }}
merge-method: rebase
-
name: Check output
if: |
steps.cpr.outputs.pull-request-operation == 'created' ||
steps.cpr.outputs.pull-request-operation == 'updated'
run: |
echo PR CREATED or MODIFIED
echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}"
echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}"
-
name: No changes detected
if: |
steps.cpr.outputs.pull-request-operation != 'created' &&
steps.cpr.outputs.pull-request-operation != 'updated'
run: |
echo "No changes detected."