-
Notifications
You must be signed in to change notification settings - Fork 61
846 lines (779 loc) · 33.6 KB
/
push.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
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
name: Monorepo pipeline - build and deploy
on:
push:
branches:
- 'main'
- 'release/**'
- 'pre-release/**'
paths-ignore:
- '**/*.md'
tags:
- docker-build-*
workflow_dispatch:
create:
pull_request:
types:
- opened
- synchronize
- labeled
defaults:
run:
shell: bash
concurrency:
# See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#example-using-a-fallback-value
group: push-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
env:
DOCKER_REGISTRY: 821090935708.dkr.ecr.eu-west-1.amazonaws.com/
DOCKER_BASE_IMAGE_REGISTRY: 821090935708.dkr.ecr.eu-west-1.amazonaws.com/ecr-public
SPINNAKER_URL: https://spinnaker-gate.shared.devland.is
COMPOSE_HTTP_TIMEOUT: 180
GITHUB_ACTIONS_CACHE_URL: https://cache.dev01.devland.is/
SKIP_GENERATED_CACHE: ${{ contains(github.event.pull_request.labels.*.name, 'skip-generated-cache') }}
NX_AFFECTED_ALL: ${{ contains(github.event.pull_request.labels.*.name, 'nx-affected-all') }}
CONFIGCAT_MAIN_CONFIG_ID: 08d8c761-021c-46f0-8671-6244663a372f
CONFIGCAT_MOBILE_APP_CONFIG_ID: 08daf234-7573-4b3b-85f6-189fc7502542
jobs:
pre-checks:
name: Check if job should run
runs-on: ec2-runners
container:
image: public.ecr.aws/m3u4c4h9/island-is/actions-runner-public:latest
env:
CREATE_PATTERNS: ^release/
PRE_RELEASE_PATTERN: ^pre-release/
outputs:
NODE_IMAGE_TAG: ${{ steps.git-branch.outputs.NODE_IMAGE_TAG }}
GIT_BRANCH: ${{ steps.git-branch.outputs.GIT_BRANCH }}
GIT_BRANCH_DEPLOY: ${{ steps.git-branch-deploy.outputs.GIT_BRANCH_DEPLOY }}
FEATURE_NAME: ${{ steps.git-branch-deploy.outputs.FEATURE_NAME }}
PRE_CHECK: ${{ steps.should-run.outputs.PRE_CHECK }}
PRE_RELEASE: ${{ steps.should-run.outputs.PRE_RELEASE }}
steps:
- name: Get git branch
id: git-branch
run: |
set -euo pipefail
GIT_BRANCH="${GITHUB_HEAD_REF:-${GITHUB_REF/refs\/heads\//}}"
echo GIT_BRANCH="${GIT_BRANCH}" >> "$GITHUB_OUTPUT"
echo GIT_BRANCH="$GIT_BRANCH" >> "$GITHUB_ENV"
- name: Generate deployment branch name
id: git-branch-deploy
run: |
set -euo pipefail
export GIT_BRANCH_DEPLOY="$GIT_BRANCH"
if [[ "$GITHUB_EVENT_NAME" == "pull_request" ]]; then
if [[ ! ("$GIT_BRANCH_DEPLOY" =~ "feature/") ]]; then
# If event is pull request but branch is not prefixed with feature/
GIT_BRANCH_DEPLOY="feature/$GIT_BRANCH_DEPLOY"
fi
# Avoid too long resource names
GIT_BRANCH_DEPLOY="${GIT_BRANCH_DEPLOY:0:50}"
fi
echo GIT_BRANCH_DEPLOY="${GIT_BRANCH_DEPLOY}" >> "$GITHUB_OUTPUT"
echo GIT_BRANCH_DEPLOY="$GIT_BRANCH_DEPLOY" >> "$GITHUB_ENV"
echo FEATURE_NAME="$(echo "$GIT_BRANCH_DEPLOY" | cut -d"/" -f2- | tr -cd '[:alnum:]-' | tr '[:upper:]' '[:lower:]' | cut -c1-50)" >> "$GITHUB_OUTPUT"
- name: Check if we want to run workflow
id: should-run
env:
SPINNAKER_WEBHOOK_TOKEN: ${{ secrets.SPINNAKER_WEBHOOK_TOKEN }}
run: |
echo "GITHUB_EVENT_NAME is '$GITHUB_EVENT_NAME'"
echo "PRE_RELEASE=false" >> "$GITHUB_OUTPUT"
if [[ "$GITHUB_EVENT_NAME" == "create" ]]; then
echo "Workflow was created because of branch creation. Branch name is '$GIT_BRANCH'"
for pre_pattern in $(echo "$PRE_RELEASE_PATTERN" | sed "s/,/ /g")
do
echo "Checking branch against pre_release_pattern '$pre_pattern'"
echo "Check if this is a pre-release and if it should generate a feature-deploy"
if [[ "$GIT_BRANCH" =~ $pre_pattern ]]; then
echo "'$GIT_BRANCH' matches 'pre_$pattern', continuing with build"
echo "PRE_CHECK=feature-deploy" >> "$GITHUB_OUTPUT"
echo "PRE_RELEASE=true" >> "$GITHUB_OUTPUT"
exit 0
fi
done
for pattern in $(echo "$CREATE_PATTERNS" | sed "s/,/ /g")
do
echo "Checking branch against pattern '$pattern'"
if [[ "$GIT_BRANCH" =~ $pattern ]]; then
echo "'$GIT_BRANCH' matches '$pattern', continuing with build"
echo "PRE_CHECK=push" >> "$GITHUB_OUTPUT"
exit 0
fi
done
echo "No pattern matches '$GIT_BRANCH', exiting."
exit 0
fi
if [[ "$GITHUB_EVENT_NAME" == "pull_request" ]]; then
if [[ "${{ github.event.action }}" == "labeled" ]]; then
echo "Action is labeled, using label that was applied: '${{ github.event.label.name }}'"
deployFeature="$([[ "${{ github.event.label.name }}" == "deploy-feature" ]] && echo true || echo false )"
else
echo "Action is ${{ github.event.action }}, using labels on PR"
deployFeature=${{ contains(github.event.pull_request.labels.*.name, 'deploy-feature') }}
fi
if [[ "$deployFeature" == "true" ]]; then
echo "Pull request contains deploy-feature label, continuing with feature deployment"
echo "PRE_CHECK=feature-deploy" >> "$GITHUB_OUTPUT"
exit 0
fi
echo "Pull request does not have deploy-feature label, exiting..."
exit 0
fi
for pre_pattern in $(echo "$PRE_RELEASE_PATTERN" | sed "s/,/ /g")
do
echo "Checking branch against pre_release_pattern '$pre_pattern'"
echo "Check if this is a pre-release and if it should generate a feature-deploy"
if [[ "$GIT_BRANCH" =~ $pre_pattern ]]; then
echo "'$GIT_BRANCH' matches 'pre_$pattern', continuing with build"
echo "PRE_CHECK=feature-deploy" >> "$GITHUB_OUTPUT"
echo "PRE_RELEASE=true" >> "$GITHUB_OUTPUT"
exit 0
fi
done
echo "PRE_CHECK=push" >> "$GITHUB_OUTPUT"
prepare:
runs-on: ec2-runners
container:
image: public.ecr.aws/m3u4c4h9/island-is/actions-runner-public:latest
timeout-minutes: 90
if: needs.pre-checks.outputs.PRE_CHECK
needs:
- pre-checks
env:
AFFECTED_ALL: ${{ secrets.AFFECTED_ALL }}
GIT_BRANCH: ${{ needs.pre-checks.outputs.GIT_BRANCH }}
SERVERSIDE_FEATURES_ON: ''
outputs:
CACHE_KEYS: ${{ steps.get-cache.outputs.keys }}
TEST_CHUNKS: ${{ steps.test_projects.outputs.CHUNKS }}
DOCKER_TAG: ${{ steps.docker_tags.outputs.DOCKER_TAG }}
NODE_IMAGE_TAG: ${{ steps.nodejs_image.outputs.NODE_IMAGE_TAG }}
LAST_GOOD_BUILD_DOCKER_TAG: ${{ steps.git_nx_base.outputs.LAST_GOOD_BUILD_DOCKER_TAG }}
UNAFFECTED: ${{ steps.unaffected.outputs.UNAFFECTED }}
BUILD_CHUNKS: ${{ steps.build_map.outputs.BUILD_CHUNKS }}
IMAGES: ${{ steps.deploy_map.outputs.IMAGES }}
node-modules-hash: ${{ steps.calculate_node_modules_hash.outputs.node-modules-hash }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version-file: 'package.json'
- name: Setup yarn
run: corepack enable
- name: Check node version
run: |
set -euo pipefail
node -v
ls -l `which node`
- name: Git refs
id: git_refs
run: |
set -euo pipefail
if [[ -n "$GITHUB_BASE_REF" ]]
then
# a PR
GIT_BASE_BRANCH="$GITHUB_BASE_REF"
else
# on main
GIT_BASE_BRANCH=main
fi
echo GIT_BRANCH="$GIT_BRANCH" >> "$GITHUB_ENV"
echo GIT_BASE_BRANCH="$GIT_BASE_BRANCH" >> "$GITHUB_ENV"
echo "Base branch is '${GIT_BASE_BRANCH}'"
echo "Branch is '${GIT_BRANCH}'"
- name: Checking out relevant branches for a pre-release
if: needs.pre-checks.outputs.PRE_CHECK && needs.pre-checks.outputs.PRE_RELEASE == 'true'
run: |
echo "Feature Name: '$FEATURE_NAME'"
git checkout main
git checkout "$GITHUB_SHA"
git config --global user.email "ci@island.is"
git config --global user.name "CI Bot"
- name: Checking out relevant branches for a PR
if: needs.pre-checks.outputs.PRE_CHECK && needs.pre-checks.outputs.PRE_CHECK == 'feature-deploy' && !(needs.pre-checks.outputs.PRE_RELEASE == 'true')
run: |
set -euo pipefail
git checkout "$GITHUB_HEAD_REF"
git checkout "$GITHUB_BASE_REF"
git checkout "$GITHUB_SHA"
git config --global user.email "ci@island.is"
git config --global user.name "CI Bot"
BASE_SHA="$(git merge-base HEAD "$GITHUB_BASE_REF")"
HEAD_SHA="$(git merge-base HEAD "$GITHUB_HEAD_REF")"
echo "Current base SHA is '$BASE_SHA' and head SHA is '$HEAD_SHA'"
echo "{\"base_sha\": \"$BASE_SHA\", \"head_sha\":\"$HEAD_SHA\"}" > event.json
- name: Checking out relevant branches for a branch build
if: ${{ !(needs.pre-checks.outputs.PRE_CHECK && needs.pre-checks.outputs.PRE_CHECK == 'feature-deploy') }}
run: |
set -euo pipefail
git checkout main
git checkout "$GITHUB_SHA"
# This is to increase the retention days for our GitHub Actions run events
# See this for more information:
# https://github.blog/changelog/2020-10-08-github-actions-ability-to-change-retention-days-for-artifacts-and-logs/
- name: Keep PR run event
uses: actions/upload-artifact@b18b1d32f3f31abcdc29dee3f2484801fe7822f4
if: needs.pre-checks.outputs.PRE_CHECK && needs.pre-checks.outputs.PRE_CHECK == 'feature-deploy' && !(needs.pre-checks.outputs.PRE_RELEASE == 'true')
with:
name: pr-event
path: event.json
retention-days: 90
include-hidden-files: true
if-no-files-found: error
- name: Generate nodejs image tag
id: nodejs_image
continue-on-error: false
run: |
set -euo pipefail
export NODE_IMAGE_TAG="$(./scripts/ci/get-node-version.mjs)"
echo "NODE_IMAGE_TAG: '${NODE_IMAGE_TAG}'"
echo NODE_IMAGE_TAG="${NODE_IMAGE_TAG}" >> "$GITHUB_OUTPUT"
echo NODE_IMAGE_TAG="${NODE_IMAGE_TAG}" >> "$GITHUB_ENV"
echo "**NODE_IMAGE_TAG** '${NODE_IMAGE_TAG}'" >> "$GITHUB_STEP_SUMMARY"
- name: Generate docker image tag
id: docker_tags
run: |
set -euo pipefail
export DOCKER_BRANCH_TAG="$(echo "${GIT_BRANCH:0:45}" | tr "/." "-" )"
SHA="${{ github.event.pull_request.head.sha }}"
echo "SHA='$SHA' retrieved from event"
if [[ "$SHA" == "" ]]; then
SHA="$GITHUB_SHA"
echo "SHA='$SHA', retrived from action environment"
fi
echo "Using SHA='$SHA' as docker tag SHA"
export DOCKER_TAG="${DOCKER_BRANCH_TAG}_${SHA:0:10}_${GITHUB_RUN_NUMBER}"
echo "Docker tag will be '${DOCKER_TAG}'"
echo DOCKER_TAG="${DOCKER_TAG}" >> "$GITHUB_OUTPUT"
echo DOCKER_TAG="$DOCKER_TAG" >> "$GITHUB_ENV"
echo "**Monorepo tag:** '${DOCKER_TAG}'" >> "$GITHUB_STEP_SUMMARY"
- name: Send Slack notification
id: slack
if: ${{ startsWith( github.env.GIT_BASE_BRANCH, 'release/' ) }}
uses: 8398a7/action-slack@v3
with:
status: custom
fields: repo,message # selectable (default: repo,message)
custom_payload: |
{
attachments: [{
color: 'good',
text: `Monorepo Release Tag is: ${process.env.DOCKER_TAG}`,
}]
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_RELEASE_WEBHOOK_URL }} # required
- run: |
echo HEAD="$GITHUB_SHA" >> "$GITHUB_ENV"
id: git_nx_head
name: Preparing HEAD tag
- name: Get cache
id: get-cache
uses: ./.github/actions/get-cache
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
enable-cache: 'node_modules,generated-files'
- name: Set Test Everything true
run: |
echo "TEST_EVERYTHING=true" >> "$GITHUB_ENV"
if: github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'test everything')
- name: Set Test Everything false
run: echo "TEST_EVERYTHING=false" >> "$GITHUB_ENV"
if: github.event_name != 'pull_request' || !contains(github.event.pull_request.labels.*.name, 'test everything')
- name: Preparing BASE tags
id: git_nx_base
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
HTML_URL: ${{ github.event.pull_request.html_url }}
ISSUE_REPORTING_SLACK_WEBHOOK_URL: ${{ secrets.SLACK_BUILD_ISSUES_REPORTING_WEBHOOK_URL }}
run: |
set -euo pipefail
if [[ "${{needs.pre-checks.outputs.PRE_CHECK}}" == 'feature-deploy' && "${{needs.pre-checks.outputs.PRE_RELEASE}}" == 'false' ]]; then
export HEAD_REF="$GITHUB_HEAD_REF"
export BASE_REF="$GITHUB_BASE_REF"
export PR_REF="$GITHUB_SHA"
else
export HEAD_REF="$GIT_BRANCH"
export BASE_REF="$GIT_BASE_BRANCH"
export PR_REF="not used"
fi
export WORKFLOW_ID=push
export SHELL=/usr/bin/bash
source ./scripts/ci/00_prepare-base-tags.sh $(git merge-base HEAD "$GITHUB_BASE_REF")
git checkout "$GITHUB_SHA"
echo BASE="$BASE" >> "$GITHUB_ENV"
echo LAST_GOOD_BUILD_DOCKER_TAG="${LAST_GOOD_BUILD_DOCKER_TAG}" >> "$GITHUB_OUTPUT"
- name: Docker login to ECR repo
run: ./scripts/ci/docker-login-ecr.sh
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
image: '${{ env.DOCKER_BASE_IMAGE_REGISTRY }}/eks-distro-build-tooling/binfmt-misc:qemu-v6.1.0'
- name: Check if cached buildx image exists
id: cache-check
run: |
if ! docker pull ${{vars.AWS_ECR_REPO_BASE}}/moby/buildkit:buildx-stable-1 ; then
docker pull docker.io/moby/buildkit:buildx-stable-1
docker tag docker.io/moby/buildkit:buildx-stable-1 ${{vars.AWS_ECR_REPO_BASE}}/moby/buildkit:buildx-stable-1
docker push ${{vars.AWS_ECR_REPO_BASE}}/moby/buildkit:buildx-stable-1
fi
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
driver-opts: |
image=${{vars.AWS_ECR_REPO_BASE}}/moby/buildkit:buildx-stable-1
- name: Get node hash
uses: actions/github-script@v7
id: calculate_node_modules_hash
env:
_CACHE_KEY: ${{ steps.get-cache.outputs.keys }}
with:
script: |
const CACHE_KEYS = JSON.parse(process.env._CACHE_KEY)
core.setOutput('node-modules-hash', CACHE_KEYS["node_modules"])
- name: Cache for NodeJS dependencies - Docker layer
id: cache-deps
continue-on-error: true
uses: ./.github/actions/cache
with:
path: cache
key: ${{ steps.calculate_node_modules_hash.outputs.node-modules-hash }}-docker-deps-1
- name: Check cache success
run: '[[ "${{ steps.cache-deps.outputs.success }}" != "false" ]] || exit 1'
- name: Cache for NodeJS dependencies - Docker layer
id: cache-deps-base
continue-on-error: true
uses: ./.github/actions/cache
with:
path: cache_output
key: ${{ steps.calculate_node_modules_hash.outputs.node-modules-hash }}-docker-output-base-1
- name: Check cache success
run: '[[ "${{ steps.cache-deps-base.outputs.success }}" != "false" ]] || exit 1'
- name: set BRANCH env var
run: echo BRANCH="$GIT_BRANCH" >> "$GITHUB_ENV"
- name: Prepare test targets
id: test_projects
run: |
set -euo pipefail
CHUNKS="$(./scripts/ci/generate-chunks.sh test)"
if [[ "$CHUNKS" != "[]" ]]; then
echo CHUNKS="{\"projects\":$CHUNKS}" >> "$GITHUB_OUTPUT"
fi
env:
SKIP_TESTS_ON_BRANCH: ${{ secrets.SKIP_TESTS_ON_BRANCH }}
- name: Prepare docker build targets
id: build_map
run: |
set -euo pipefail
CHUNKS="$(./scripts/ci/generate-build-chunks.sh docker-express docker-next docker-static docker-playwright docker-jest)"
echo "CHUNKS: '$CHUNKS'"
if [[ "$CHUNKS" != "[]" ]]; then
echo BUILD_CHUNKS="$CHUNKS" >> "$GITHUB_OUTPUT"
fi
- name: Gather unaffected docker images
id: unaffected
run: |
set -euo pipefail
UNAFFECTED="$(./scripts/ci/list-unaffected.sh docker-next docker-express docker-static docker-playwright docker-jest)"
echo UNAFFECTED="$UNAFFECTED" >> "$GITHUB_OUTPUT"
- name: check pre-release
if: needs.pre-checks.outputs.PRE_RELEASE == 'true'
run: |
echo "AFFECTED_ALL=7913-$GIT_BRANCH" >> "$GITHUB_ENV"
- name: Prepare deployment targets
id: deploy_map
if: needs.pre-checks.outputs.PRE_CHECK != 'push'
run: |
set -euo pipefail
export BASE="$(git merge-base HEAD "$GITHUB_BASE_REF")"
CHUNKS="$(./scripts/ci/generate-build-chunks.sh docker-express docker-next docker-static docker-playwright docker-jest)"
echo "CHUNKS: '$CHUNKS'"
if [[ "$CHUNKS" != "[]" ]]; then
echo "IMAGES="$(echo "$CHUNKS" | jq '.[] | fromjson | .projects' -r | tr '\n' ',')"" >> "$GITHUB_OUTPUT"
fi
tests:
needs:
- prepare
if: needs.prepare.outputs.TEST_CHUNKS
runs-on: ec2-runners
container:
image: public.ecr.aws/m3u4c4h9/island-is/actions-runner-public:latest
timeout-minutes: 35
env:
AFFECTED_PROJECTS: ${{ matrix.projects }}
MAX_JOBS: 1
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.prepare.outputs.TEST_CHUNKS) }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version-file: 'package.json'
- name: Setup yarn
run: corepack enable
- name: Get cache
id: get-cache
uses: ./.github/actions/get-cache
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
keys: ${{ needs.prepare.outputs.CACHE_KEYS }}
enable-cache: 'node_modules,generated-files'
- uses: ./.github/actions/unit-test
with:
dd-api-key: '${{ secrets.DD_API_KEY }}'
codecov-token: ${{ secrets.CODECOV_TOKEN }}
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
docker-registry: ${{ env.DOCKER_REGISTRY}}
docker-build:
needs:
- pre-checks
- prepare
runs-on: ec2-runners
container:
image: public.ecr.aws/m3u4c4h9/island-is/actions-runner-public:latest
timeout-minutes: 35
if: needs.prepare.outputs.BUILD_CHUNKS
env:
AFFECTED_ALL: ${{ secrets.AFFECTED_ALL }}
GIT_BRANCH: ${{ needs.pre-checks.outputs.GIT_BRANCH}}
DOCKER_TAG: ${{ needs.prepare.outputs.DOCKER_TAG}}
NODE_IMAGE_TAG: ${{ needs.prepare.outputs.NODE_IMAGE_TAG}}
PUBLISH: true
strategy:
fail-fast: false
matrix:
chunk: ${{ fromJson(needs.prepare.outputs.BUILD_CHUNKS) }}
steps:
- name: Gather apps
id: gather
run: |
set -euo pipefail
AFFECTED_PROJECTS="$(echo '${{ matrix.chunk }}' | jq -r '.projects')"
DOCKER_TYPE="$(echo '${{ matrix.chunk }}' | jq -r '.docker_type')"
echo AFFECTED_PROJECTS="$AFFECTED_PROJECTS" >> "$GITHUB_ENV"
echo DOCKER_TYPE="$DOCKER_TYPE" >> "$GITHUB_ENV"
continue-on-error: true
- uses: actions/checkout@v3
if: steps.gather.outcome == 'success'
- uses: actions/setup-node@v4
with:
node-version-file: 'package.json'
if: steps.gather.outcome == 'success'
- name: Setup yarn
run: corepack enable
if: steps.gather.outcome == 'success'
- name: Get cache
id: get-cache
uses: ./.github/actions/get-cache
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
keys: ${{ needs.prepare.outputs.CACHE_KEYS }}
enable-cache: 'node_modules,generated-files'
- name: Cache for dependencies Docker layer
if: steps.gather.outcome == 'success'
id: cache-deps-base
continue-on-error: true
uses: ./.github/actions/cache
with:
path: cache_output
key: ${{ needs.prepare.outputs.node-modules-hash }}-docker-output-base-1
- name: Check cache success
run: '[[ "${{ steps.cache-deps-base.outputs.success }}" != "false" ]] || exit 1'
- name: Cache for NodeJS dependencies - Docker layer
id: cache-deps
if: steps.gather.outcome == 'success'
continue-on-error: true
uses: ./.github/actions/cache
with:
path: cache
key: ${{ needs.prepare.outputs.node-modules-hash }}-docker-deps-1
- name: Check cache success
run: '[[ "${{ steps.cache-deps.outputs.success }}" != "false" ]] || exit 1'
- name: Docker login to ECR repo
if: steps.gather.outcome == 'success'
run: ./scripts/ci/docker-login-ecr.sh
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
image: '${{ env.DOCKER_BASE_IMAGE_REGISTRY }}/eks-distro-build-tooling/binfmt-misc:qemu-v6.1.0'
- name: Check if cached buildx image exists
id: cache-check
run: |
if ! docker pull ${{vars.AWS_ECR_REPO_BASE}}/moby/buildkit:buildx-stable-1 ; then
docker pull docker.io/moby/buildkit:buildx-stable-1
docker tag docker.io/moby/buildkit:buildx-stable-1 ${{vars.AWS_ECR_REPO_BASE}}/moby/buildkit:buildx-stable-1
docker push ${{vars.AWS_ECR_REPO_BASE}}/moby/buildkit:buildx-stable-1
fi
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
driver-opts: |
image=${{vars.AWS_ECR_REPO_BASE}}/moby/buildkit:buildx-stable-1
- name: Prepare Docker build arguments
id: dockerargs
if: steps.gather.outcome == 'success'
env:
NODE_IMAGE_TAG: ${{ needs.prepare.outputs.NODE_IMAGE_TAG }}
GIT_COMMIT_SHA: ${{ github.sha }}
DOCKER_BASE_IMAGE_REGISTRY: ${{ env.DOCKER_BASE_IMAGE_REGISTRY }}
run: |
set -x
# Strip protocol prefix and .git postfix
SERVER_URL="${{ github.server_url }}/${{ github.repository }}"
SERVER_URL="${SERVER_URL#*://}"
SERVER_URL="${SERVER_URL%.git}"
build_args=(
--build-arg="DOCKER_IMAGE_REGISTRY=${DOCKER_BASE_IMAGE_REGISTRY}"
--build-arg="NODE_IMAGE_TAG=${NODE_IMAGE_TAG}"
--build-arg="GIT_BRANCH=${GIT_BRANCH}"
--build-arg="GIT_COMMIT_SHA=${GIT_COMMIT_SHA}"
--build-arg="GIT_REPOSITORY_URL=${SERVER_URL}"
)
export EXTRA_DOCKER_BUILD_ARGS="${build_args[*]}"
echo "EXTRA_DOCKER_BUILD_ARGS=${EXTRA_DOCKER_BUILD_ARGS}" >> "${GITHUB_ENV}"
- name: Building Docker images
continue-on-error: true
id: dockerbuild
if: steps.gather.outcome == 'success'
env:
NODE_IMAGE_TAG: ${{ needs.prepare.outputs.NODE_IMAGE_TAG }}
GIT_COMMIT_SHA: ${{ github.sha }}
DOCKER_BASE_IMAGE_REGISTRY: ${{ env.DOCKER_BASE_IMAGE_REGISTRY }}
run: |
set -x
echo "Node image tag is: '${NODE_IMAGE_TAG}'"
echo "Docker build args are: 'EXTRA_DOCKER_BUILD_ARGS'"
export EXTRA_DOCKER_BUILD_ARGS
./scripts/ci/run-in-parallel.sh "90_${DOCKER_TYPE}"
- name: Building Docker images Retry
if: steps.gather.outcome == 'success' && steps.dockerbuild.outcome == 'failure'
env:
NODE_IMAGE_TAG: ${{ needs.prepare.outputs.NODE_IMAGE_TAG }}
GIT_COMMIT_SHA: ${{ github.sha }}
DOCKER_BASE_IMAGE_REGISTRY: ${{ env.DOCKER_BASE_IMAGE_REGISTRY }}
run: |
set -x
echo "Node image tag is: '${NODE_IMAGE_TAG}'"
echo "Docker build args are: 'EXTRA_DOCKER_BUILD_ARGS'"
export EXTRA_DOCKER_BUILD_ARGS
./scripts/ci/run-in-parallel.sh "90_${DOCKER_TYPE}"
helm-docker-build:
needs:
- prepare
- pre-checks
# if: needs.prepare.outputs.IMAGES && needs.pre-checks.outputs.PRE_CHECK != 'push'
runs-on: ec2-runners
container:
image: public.ecr.aws/m3u4c4h9/island-is/actions-runner-public:latest
timeout-minutes: 5
env:
FEATURE_NAME: ${{ needs.pre-checks.outputs.FEATURE_NAME }}
DOCKER_TAG: ${{ needs.prepare.outputs.DOCKER_TAG}}
GIT_BRANCH: ${{ needs.pre-checks.outputs.GIT_BRANCH }}
NODE_IMAGE_TAG: ${{ needs.prepare.outputs.NODE_IMAGE_TAG }}
steps:
- uses: actions/checkout@v3
- name: Docker login
run: ./scripts/ci/docker-login-ecr.sh
env:
AWS_ACCESS_KEY_ID: ${{ secrets.ECR_AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.ECR_AWS_SECRET_ACCESS_KEY }}
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.ECR_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.ECR_AWS_SECRET_ACCESS_KEY }}
aws-region: eu-west-1
- name: Docker build image
working-directory: infra
run: |
echo Registry is: ${{env.DOCKER_BASE_IMAGE_REGISTRY}}
echo Image tag is: ${{env.NODE_IMAGE_TAG}}
export EXTRA_DOCKER_BUILD_ARGS="--build-arg DOCKER_IMAGE_REGISTRY=${{env.DOCKER_BASE_IMAGE_REGISTRY}} --build-arg NODE_IMAGE_TAG=${{env.NODE_IMAGE_TAG}}"
./scripts/build-docker-container.sh "$DOCKER_TAG"
echo "COMMENT<<EOF" >> "$GITHUB_ENV"
echo "Affected services are: ${{needs.prepare.outputs.IMAGES}}" >> "$GITHUB_ENV"
docker run --rm "${DOCKER_REGISTRY}helm-config:$DOCKER_TAG" ingress-comment --images=${{needs.prepare.outputs.IMAGES}} --chart=islandis --feature="$FEATURE_NAME" >> "$GITHUB_ENV"
echo 'EOF' >> "$GITHUB_ENV"
env:
PUBLISH: 'true'
- name: Retag as latest
if: ${{ env.GIT_BRANCH == 'main' && env.NX_AFFECTED_ALL != 'true' }}
env:
UNAFFECTED: helm-config
LAST_GOOD_BUILD_DOCKER_TAG: ${{ env.DOCKER_TAG }}
DOCKER_TAG: latest
run: ./scripts/ci/retag-unaffected.sh "$UNAFFECTED"
- name: Comment on PR
if: needs.pre-checks.outputs.PRE_CHECK == 'feature-deploy' && !(needs.pre-checks.outputs.PRE_RELEASE == 'true')
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const updateComment = require('./.github/actions/update-comment.js')
const { COMMENT } = process.env
await updateComment({github, context, comment: COMMENT})
retag-unaffected:
runs-on: ec2-runners
container:
image: public.ecr.aws/m3u4c4h9/island-is/actions-runner-public:latest
timeout-minutes: 5
if: ${{ !cancelled() && needs.pre-checks.result == 'success' && needs.prepare.result != 'skipped' }}
needs:
- pre-checks
- docker-build
- prepare
env:
GIT_BRANCH: ${{ needs.pre-checks.outputs.GIT_BRANCH}}
DOCKER_TAG: ${{ needs.prepare.outputs.DOCKER_TAG}}
LAST_GOOD_BUILD_DOCKER_TAG: ${{ needs.prepare.outputs.LAST_GOOD_BUILD_DOCKER_TAG}}
UNAFFECTED: ${{ needs.prepare.outputs.UNAFFECTED}}
steps:
- name: Check prepare success
run: '[[ ${{ needs.prepare.result }} == "success" ]] || exit 1'
- name: Check docker-build success
run: '[[ ${{ needs.docker-build.result }} != "failure" ]] || exit 1'
- uses: actions/checkout@v3
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: eu-west-1
- name: Retag unaffected Docker images
run: ./scripts/ci/retag-unaffected.sh "$UNAFFECTED"
deploy:
runs-on: ec2-runners
container:
image: public.ecr.aws/m3u4c4h9/island-is/actions-runner-public:latest
if: ${{ !cancelled() && needs.retag-unaffected.result == 'success' && needs.helm-docker-build.result != 'failure' }}
needs:
- retag-unaffected
- pre-checks
- prepare
- helm-docker-build
env:
GIT_BRANCH_DEPLOY: ${{ needs.pre-checks.outputs.GIT_BRANCH_DEPLOY }}
FEATURE_NAME: ${{ needs.pre-checks.outputs.FEATURE_NAME }}
DOCKER_TAG: ${{ needs.prepare.outputs.DOCKER_TAG }}
IMAGES: ${{ needs.prepare.outputs.IMAGES }}
steps:
- uses: actions/checkout@v3
- name: Trigger Deployment for service
env:
SPINNAKER_WEBHOOK_TOKEN: ${{ secrets.SPINNAKER_WEBHOOK_TOKEN }}
run: |
echo "Sending webhook with branch: '$GIT_BRANCH_DEPLOY'"
curl "$SPINNAKER_URL/webhooks/webhook/islandis" -H "content-type: application/json" --data-binary @- <<BODY
{
"token": "$SPINNAKER_WEBHOOK_TOKEN",
"branch": "$GIT_BRANCH_DEPLOY",
"parameters": {
"docker_tag": "$DOCKER_TAG",
"feature_name": "$FEATURE_NAME",
"images": "$IMAGES",
"pull_request_number": "$(echo "$GITHUB_REF" | cut -d'/' -f3)"
}
}
BODY
- name: Trigger Deployment for IDS-Services
env:
DOCKER_TAG: ${{ needs.prepare.outputs.DOCKER_TAG }}
GIT_BRANCH_DEPLOY: ${{ needs.pre-checks.outputs.GIT_BRANCH_DEPLOY }}
SPINNAKER_WEBHOOK_TOKEN: ${{ secrets.SPINNAKER_WEBHOOK_TOKEN }}
GH_PRIVATE_REPO_TOKEN: ${{secrets.GH_PRIVATE_REPO_TOKEN}}
run: |
set -euo pipefail
if read -d "\n" IDENTITY_SERVER_HEAD_SHA IDENTITY_SERVER_RUN_NUMBER; then :; fi <<<$(curl -H "Authorization: token $GH_PRIVATE_REPO_TOKEN" -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/island-is/identity-server.web/actions/workflows/build.yml/runs\?branch\=main\&status\=success\&per_page\=1\&event\=push | jq '.workflow_runs[] | .head_sha, .run_number' | tr -d \")
export IDENTITY_SERVER_DOCKER_TAG="main_${IDENTITY_SERVER_HEAD_SHA:0:10}_${IDENTITY_SERVER_RUN_NUMBER}"
echo "Deploying with identity-server docker tag: '$IDENTITY_SERVER_DOCKER_TAG'"
echo "Sending webhook with branch: '$GIT_BRANCH_DEPLOY'"
curl "$SPINNAKER_URL/webhooks/webhook/ids-dev" -H "content-type: application/json" --data-binary @- <<BODY
{
"token": "$SPINNAKER_WEBHOOK_TOKEN",
"branch": "$GIT_BRANCH_DEPLOY",
"parameters": {
"dependency_docker_tag": "$DOCKER_TAG",
"docker_tag": "$IDENTITY_SERVER_DOCKER_TAG"
}
}
BODY
push-success:
runs-on: ec2-runners
container:
image: public.ecr.aws/m3u4c4h9/island-is/actions-runner-public:latest
if: ${{ !cancelled() }}
needs:
- pre-checks
- retag-unaffected
- deploy
- tests
steps:
- name: Check retag success
run: '[[ ${{ needs.retag-unaffected.result }} != "failure" ]] || exit 1'
- name: Check deploy success
run: '[[ ${{ needs.deploy.result }} != "failure" ]] || exit 1'
- name: Check tests success
run: '[[ ${{ needs.tests.result }} != "failure" ]] || exit 1'
- name: Announce success
if: needs.pre-checks.outputs.PRE_CHECK
run: echo "Build is successful"
- name: Announce skipped
if: '!needs.pre-checks.outputs.PRE_CHECK'
run: echo "Build was skipped"
failure-notification:
runs-on: ec2-runners
container:
image: public.ecr.aws/m3u4c4h9/island-is/actions-runner-public:latest
if: failure() && needs.pre-checks.outputs.PRE_CHECK && needs.pre-checks.outputs.PRE_CHECK != 'feature-deploy'
needs:
- pre-checks
- prepare
- docker-build
- retag-unaffected
- deploy
steps:
- name: Send Slack notification
uses: 8398a7/action-slack@v3
with:
status: failure
icon_emoji: ':broken_heart:'
fields: repo,message,commit,author,action,eventName,ref,workflow,took # selectable (default: repo,message)
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # optional
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} # required
scanflags:
if: github.ref == 'ref/heads/main'
runs-on: ec2-runners
container:
image: public.ecr.aws/m3u4c4h9/island-is/actions-runner-public:latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Scan & upload main config
uses: configcat/scan-repository@v2
with:
api-user: ${{ secrets.CONFIGCAT_API_USER }}
api-pass: ${{ secrets.CONFIGCAT_API_PASS }}
config-id: ${{ env.CONFIGCAT_MAIN_CONFIG_ID }}
- name: Scan & upload mobile app config
uses: configcat/scan-repository@v2
with:
api-user: ${{ secrets.CONFIGCAT_API_USER }}
api-pass: ${{ secrets.CONFIGCAT_API_PASS }}
config-id: ${{ env.CONFIGCAT_MOBILE_APP_CONFIG_ID }}
sub-folder: apps/native