-
Notifications
You must be signed in to change notification settings - Fork 5
/
flowzone.yml
4590 lines (3971 loc) · 163 KB
/
flowzone.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
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
.flowzone:
- &ifInternalPullRequest # check if the PR is from a fork by comparing the repository name
if: github.event.pull_request.head.repo.full_name == github.repository
- &ifExternalPullRequest # check if the PR is from a fork by comparing the repository name
if: github.event.pull_request.head.repo.full_name != github.repository
- &ifPrivateRepository
if: github.event.repository.private
- &ifPublicRepository
if: github.event.repository.private != true
- &getGitHubAppToken # https://github.com/marketplace/actions/github-app-token
name: Generate GitHub App installation token
uses: tibdex/github-app-token@3beb63f4bd073e61482598c45c71c1019b59b73a # v2.1.0
if: inputs.app_id
id: gh_app_token
with: &getGitHubAppTokenWith
app_id: ${{ inputs.app_id }}
installation_retrieval_mode: organization
installation_retrieval_payload: ${{ github.repository_owner }}
private_key: ${{ secrets.GH_APP_PRIVATE_KEY }}
permissions: >-
{
"contents": "read",
"metadata": "read"
}
# optionally attempt to get AWS login short-lived session credentials over OIDC
- &configureAWSCredentials # https://github.com/aws-actions/configure-aws-credentials
name: Configure AWS credentials
id: aws_credentials
uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4.0.2
# skip if the PR is from a fork or aws region is unset
if: |
( matrix.region != '' || inputs.aws_region != '' ) &&
github.event.pull_request.head.repo.full_name == github.repository
continue-on-error: true
with:
role-to-assume: ${{ matrix.role || inputs.aws_iam_role }}
role-session-name: github-${{ github.job }}-${{ github.run_id }}-${{ github.run_attempt }}
aws-region: ${{ matrix.region || inputs.aws_region }}
# https://github.com/orgs/community/discussions/26636#discussioncomment-3252664
mask-aws-account-id: false
- &generatePythonMetadata
name: Generate Python metadata
id: python_meta
run: |
package="$(poetry version --no-ansi | awk '{print $1}')"
version="$(poetry version --no-ansi | awk '{print $2}')"
commit_sha="$(echo ${{ github.event.pull_request.head.sha }} | tr "a-z" "A-Z")"
decimal_sha="$(echo "ibase=16; $commit_sha" | bc)"
version_tag="${version}-dev${decimal_sha}"
echo "package=${package}" >> "${GITHUB_OUTPUT}"
echo "version=${version}" >> "${GITHUB_OUTPUT}"
echo "version_tag=${version_tag}" >> "${GITHUB_OUTPUT}"
- &deployToBalenaAction
uses: balena-io/deploy-to-balena-action@9c9d61c6b9ecb89b32557299f0c5534c18c97d14 # v2.0.85
id: balena_deploy
with:
balena_token: ${{ secrets.BALENA_API_KEY || secrets.BALENA_API_KEY_PUSH }}
environment: ${{ inputs.balena_environment }}
fleet: ${{ matrix.slug }}
source: ${{ inputs.working_directory }}
note: ${{ needs.release_notes.outputs.note }}
# Feb 2023: as per GitHub support: "You cannot authenticate with a GitHub App token on the GitHub Package Registry"
# Nov 2024: Still cannot use GitHub App Tokens to authenticate with the GitHub Package Registry (login works, push/pull fails)
registry_secrets: |
{
"ghcr.io": {
"username": "${{ github.actor }}",
"password": "${{ secrets.GITHUB_TOKEN }}"
},
"docker.io": {
"username": "${{ secrets.DOCKERHUB_USER }}",
"password": "${{ secrets.DOCKERHUB_TOKEN }}"
}
}
- &getTimeStamp
name: Get and format timestamp
id: timestamp
env:
FORMAT: "%Y-%m-%d-%H%M%S"
run: |
echo "datetime=$(date +"${FORMAT}")" >> $GITHUB_OUTPUT
# https://docs.github.com/en/rest/git/tags?apiVersion=2022-11-28#create-a-tag-object
- &createTagObject
name: Create tag object
if: inputs.disable_versioning != true
id: create_tag
env:
GH_TOKEN: ${{ steps.gh_app_token.outputs.token || secrets.FLOWZONE_TOKEN }}
TAG: ${{ steps.versionist.outputs.tag }}
MESSAGE: ${{ steps.versionist.outputs.tag }}
SHA: ${{ steps.create_commit.outputs.sha }}
run: |
response="$(gh api -X POST repos/$GH_REPO/git/tags \
-F "tag=${TAG}" \
-F "message=${MESSAGE}" \
-F "object=${SHA}" \
-F "type=commit")"
echo "$response" | jq .
echo "sha=$(echo $response | jq -r .sha)" >> "${GITHUB_OUTPUT}"
echo "json=$(echo $response | jq -c .)" >> "${GITHUB_OUTPUT}"
# https://docs.github.com/en/rest/git/refs?apiVersion=2022-11-28#update-a-reference
- &updateGitReference
name: Update git reference
if: github.event.pull_request.merged == true && steps.create_commit.outputs.sha != ''
env:
GH_TOKEN: ${{ steps.gh_app_token.outputs.token || secrets.FLOWZONE_TOKEN }}
REF: "refs/heads/${{ github.base_ref }}"
SHA: ${{ steps.create_commit.outputs.sha }}
run: |
gh api \
-X PATCH \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"/repos/${{ github.repository }}/git/${REF}" \
-f sha="${SHA}" \
-F force=true \
--include
# https://docs.github.com/en/rest/git/refs?apiVersion=2022-11-28#create-a-reference
- &createGitReference
name: Create git reference
if: github.event.pull_request.merged == true && steps.create_tag.outputs.sha != ''
env:
GH_TOKEN: ${{ steps.gh_app_token.outputs.token || secrets.FLOWZONE_TOKEN }}
REF: "refs/tags/${{ steps.versionist.outputs.tag }}"
SHA: ${{ steps.create_tag.outputs.sha }}
run: |
gh api \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/repos/$GH_REPO/git/refs \
-f ref="${REF}" \
-f sha="${SHA}" \
--include
- &checkoutAuth
token: ${{ steps.gh_app_token.outputs.token || secrets.FLOWZONE_TOKEN }}
persist-credentials: false
- &checkoutPullRequestMergeRef
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_target
# https://github.com/actions/checkout
name: Checkout pull request merge ref
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0
submodules: "recursive"
ref: "refs/pull/${{ github.event.number }}/merge"
<<: *checkoutAuth
- &checkoutPullRequestHeadSha
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_target
# https://github.com/actions/checkout
name: Checkout pull request head sha
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0
submodules: "recursive"
# fallback to an invalid ref if the checkout ref is undefined
ref: ${{ github.event.pull_request.head.sha || '¯\_(ツ)_/¯' }}
<<: *checkoutAuth
- &checkoutEventSha
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_target
# https://github.com/actions/checkout
name: Checkout ${{ github.sha }}
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0
submodules: "recursive"
# fallback to an invalid ref if the checkout ref is undefined
ref: ${{ github.sha || '¯\_(ツ)_/¯' }}
<<: *checkoutAuth
- &checkoutVersionedSha # https://github.com/actions/checkout
name: Checkout versioned commit
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: "${{ needs.versioned_source.outputs.depth || 0 }}"
# Note that fetch-tags is not currently working as described:
# https://github.com/actions/checkout/issues/1781
fetch-tags: true
submodules: "recursive"
# fallback to an invalid ref if the checkout ref is undefined
ref: "${{ needs.versioned_source.outputs.sha || '¯\_(ツ)_/¯' }}"
<<: *checkoutAuth
- &resetGitHubDirectory
# checkout the tip of BASE if the PR is from a fork
# or the merge commit if the PR is internal
name: Reset .github directory to ${{ github.ref }}
env:
GIT_AUTH_TOKEN: ${{ steps.gh_app_token.outputs.token || secrets.FLOWZONE_TOKEN }}
# Use bash without tracing to avoid leaking secrets
shell: bash
# Create base64 encoded auth header
#
# Use git-c for non-persistent credential configuration
#
# The git -c option sets a configuration value for a single Git command invocation.
# It does not modify any configuration files or persist the setting beyond this specific command.
#
# This approach ensures that the authentication credentials are used securely for this
# specific operation without risk of unintended persistence or exposure in configuration files.
run: |
auth_header=$(printf "x-access-token:${GIT_AUTH_TOKEN}" | base64 | tr -d '\n')
git -c "http.https://github.com/.extraheader=Authorization: basic ${auth_header}" fetch origin ${{ github.ref }}
git checkout FETCH_HEAD -- .github
# Resolve tag, semver, sha, and description of current git working copy.
# tag is the latest tag that points to the current commit.
# semver is the semantic version of the tag.
# describe is the output of `git describe --tags --always --dirty`.
# sha is the full commit hash.
# depth is set to a default number of commits to fetch on downstream jobs
# (enough to get last two tags, or 0 for all commits when submodules are present)
- &describeGitState
name: Describe git state
id: git_describe
run: |
tag="$(git tag --points-at HEAD | tail -n1)"
{
echo "tag=${tag}" ;
echo "semver=$(npx -q -y -- semver -c -l "${tag}")" ;
echo "describe=$(git describe --tags --always --dirty | cat)" ;
echo "sha=$(git rev-parse HEAD)" ;
} >> "${GITHUB_OUTPUT}"
if [[ "$(git submodule)" = "" ]]; then
echo "depth=100" >> "${GITHUB_OUTPUT}"
else
echo "depth=0" >> "${GITHUB_OUTPUT}"
fi
# Create a local reference for the versioned tag so that it
# may be consumed by build steps that need to know the version of the source.
# These refs should already exist on merge/finalize.
- &createLocalRefs
name: Create local tag for draft version
if: github.event.pull_request.state == 'open' && inputs.disable_versioning != true
run: |
git update-ref refs/tags/${{ needs.versioned_source.outputs.tag }} ${{ needs.versioned_source.outputs.tag_sha }}
# Enabling fetch-tags via actions/checkout does not work when fetch-depth > 0
# https://github.com/actions/checkout/issues/1781
- &fetchTags
name: Fetch tags
if: needs.versioned_source.outputs.depth != 0 && needs.versioned_source.outputs.depth != ''
env:
GIT_AUTH_TOKEN: ${{ steps.gh_app_token.outputs.token || secrets.FLOWZONE_TOKEN }}
# Use bash without tracing to avoid leaking secrets
shell: bash
# Create base64 encoded auth header
#
# Use git -c for non-persistent credential configuration
#
# The git -c option sets a configuration value for a single Git command invocation.
# It does not modify any configuration files or persist the setting beyond this specific command.
#
# This approach ensures that the authentication credentials are used securely for this
# specific operation without risk of unintended persistence or exposure in configuration files.
run: |
auth_header=$(printf "x-access-token:${GIT_AUTH_TOKEN}" | base64 | tr -d '\n')
git -c "http.https://github.com/.extraheader=Authorization: basic ${auth_header}" fetch -q --tags
- &loginWithDockerHub
name: Login to Docker Hub
continue-on-error: true
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
with:
registry: docker.io
username: ${{ secrets.DOCKERHUB_USER || secrets.DOCKER_REGISTRY_USER }}
password: ${{ secrets.DOCKERHUB_TOKEN || secrets.DOCKER_REGISTRY_PASS }}
- &loginWithGitHubContainerRegistry
name: Login to GitHub Container Registry
continue-on-error: true
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
with:
# Feb 2023: as per GitHub support: "You cannot authenticate with a GitHub App token on the GitHub Package Registry"
# Nov 2024: Still cannot use GitHub App Tokens to authenticate with the GitHub Package Registry (login works, push/pull fails)
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- &loginWithECRPublic
name: Login to AWS/ECR (public)
if: steps.aws_credentials.outcome == 'success'
continue-on-error: true
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
with:
registry: public.ecr.aws
- &loginWithECRPrivate
name: Login to AWS/ECR (private)
if: steps.aws_credentials.outcome == 'success'
continue-on-error: true
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
with:
registry: ${{ matrix.image }}
- &customWorkingDirectory
defaults:
run:
working-directory: ${{ inputs.working_directory }}
shell: bash --noprofile --norc -eo pipefail -x {0}
- &rootWorkingDirectory
defaults:
run:
working-directory: .
shell: bash --noprofile --norc -eo pipefail -x {0}
- &gitHubCliEnvironment
# environment variables used by gh CLI
# https://cli.github.com/manual/gh_help_environment
GH_DEBUG: "true"
GH_PAGER: "cat"
GH_PROMPT_DISABLED: "true"
GH_REPO: "${{ github.repository }}"
- &rejectExternalCustomActions
name: Reject external custom actions
if: |
github.event.pull_request.state == 'open' &&
github.event.pull_request.head.repo.full_name != github.repository &&
inputs.restrict_custom_actions == true
run: |
echo "::error::Custom actions are disabled for external contributors and will be skipped. \
Please contact a member of the organization for assistance."
exit 1
- &logGitHubContext
name: Log GitHub context
env:
GITHUB_CONTEXT: ${{ toJSON(github) }}
run: echo "${GITHUB_CONTEXT}" || true
- &deleteDraftGitHubRelease
name: Delete draft GitHub release
run: gh release delete --yes "${GITHUB_HEAD_REF}" || true
env:
<<: *gitHubCliEnvironment
GH_TOKEN: ${{ steps.gh_app_token.outputs.token || secrets.FLOWZONE_TOKEN }}
- &jsonArrayBuilder
name: Build JSON array
id: to_json_array
shell: bash
run: |
set -x
# Remove spaces and newlines from the input
INPUT="$(echo "${INPUT}" | tr -d '[:space:]')"
# Convert to JSON array using jq to split the string by the given delimiter
# Add a step to check if the array is empty, default to [""] if so
JSON_ARRAY="$(jq --raw-input --compact-output --null-input --arg delim "$DELIMITER" --arg input "$INPUT" '
if $input == "" then
[""] # Default to a single empty string element if input is empty
else
$input | split($delim) # Split the input by the delimiter
end
')"
echo "build=${JSON_ARRAY}" >> "${GITHUB_OUTPUT}"
echo "json=${JSON_ARRAY}" >> "${GITHUB_OUTPUT}"
- &newlineListBuilder
name: Build newline-separated list from JSON array
id: to_newline_list
run: |
build="$(echo "${{ join(fromJSON(env.INPUT),' ') }}" | tr " " "\n")"
DELIMITER="$(echo $RANDOM | md5sum | head -c 32)"
echo "build<<${DELIMITER}" >> "${GITHUB_OUTPUT}"
echo "${build}" >> "${GITHUB_OUTPUT}"
echo "${DELIMITER}" >> "${GITHUB_OUTPUT}"
- &dockerPlatformSlugMap
PLATFORM_SLUG_MAP: >
{
"linux/386": "i386",
"linux/amd64": "amd64",
"linux/arm64": "arm64v8",
"linux/arm/v7": "arm32v7",
"linux/arm/v6": "arm32v6",
"linux/arm/v5": "arm32v5",
"linux/s390x": "s390x",
"linux/mips64le": "mips64le",
"linux/ppc64le": "ppc64le",
"linux/riscv64": "riscv64",
"windows/amd64": "windows-amd64"
}
- &sanitizeDockerStrings
name: Sanitize docker strings
id: strings
env:
TARGET: ${{ matrix.target }}
IMAGE: ${{ matrix.image }}
run: |
target_slug="$(echo "${TARGET}" | sed 's/[^[:alnum:]]/-/g')"
if [ -n "${TARGET}" ] && [ -z "${target_slug}" ]
then
echo "::error::Unsupported platform: ${TARGET}"
fi
if [ "${TARGET}" != "default" ]
then
if [ "${{ inputs.docker_invert_tags }}" = "true" ]
then
prefix_slug="${target_slug}-"
else
suffix_slug="-${target_slug}"
fi
fi
case ${IMAGE} in
'')
image_slug=
;;
*.*/*)
# convert tl.d/org/repo(:tag)? to tl.d/org/repo
image_slug="${IMAGE%%:*}"
;;
*)
# convert org/repo(:tag)? to docker.io/org/repo
image_slug="docker.io/${IMAGE%%:*}"
;;
esac
# convert tl.d/org/repo to org/repo
repo_slug="${image_slug#*/}"
echo "image=${image_slug}" >> "${GITHUB_OUTPUT}"
echo "target=${target_slug}" >> "${GITHUB_OUTPUT}"
echo "prefix=${prefix_slug}" >> "${GITHUB_OUTPUT}"
echo "suffix=${suffix_slug}" >> "${GITHUB_OUTPUT}"
echo "repo=${repo_slug}" >> "${GITHUB_OUTPUT}"
- &dockerTestMetadata # https://github.com/docker/metadata-action
name: Generate docker metadata
id: test_meta
uses: docker/metadata-action@369eb591f429131d6889c46b94e711f089e6ca96 # v5.6.1
with: &dockerTestMetaWith
images: |
sut
localhost:5000/sut
${{ needs.is_docker.outputs.docker_images_crlf }}
labels: |
org.opencontainers.image.version=${{ needs.versioned_source.outputs.semver }}
org.opencontainers.image.ref.name=${{ matrix.target }}
tags: |
type=raw,value=${{ github.event.pull_request.head.sha }}
type=raw,value=build-${{ github.event.pull_request.head.sha }}
type=raw,value=build-${{ github.event.pull_request.head.ref }}
flavor: |
latest=true
prefix=${{ steps.strings.outputs.prefix }}
suffix=${{ steps.strings.outputs.suffix }}
- &dockerCacheFromMetadata
<<: *dockerTestMetadata
id: cache_meta
# ensure docker_images_crlf is not an empty list
if: join(fromJSON(needs.is_docker.outputs.docker_images)) != ''
with:
images: |
${{ needs.is_docker.outputs.docker_images_crlf }}
tags: |
type=raw,value=${{ github.base_ref || github.ref_name }}
type=raw,value=${{ github.event.pull_request.head.sha }}
type=raw,value=build-${{ github.event.pull_request.head.sha }}
type=raw,value=build-${{ github.event.pull_request.head.ref }}
flavor: |
latest=true
prefix=${{ steps.strings.outputs.prefix }},onlatest=true
suffix=${{ steps.strings.outputs.suffix }},onlatest=true
- &dockerDraftMetadata
<<: *dockerTestMetadata
id: draft_meta
with:
<<: *dockerTestMetaWith
images: |
${{ matrix.image }}
flavor: |
latest=false
prefix=${{ steps.strings.outputs.prefix }}
suffix=${{ steps.strings.outputs.suffix }}
- &dockerFinalMetadata
<<: *dockerTestMetadata
id: final_meta
with:
<<: *dockerTestMetaWith
images: |
${{ matrix.image }}
# for unversioned merges we will use the base branch as the tag
# and version tag and semver will be empty
tags: |
type=raw,value=${{ github.base_ref || github.ref_name }}
type=raw,value=${{ needs.versioned_source.outputs.tag }}
type=raw,value=${{ needs.versioned_source.outputs.semver }}
flavor: |
latest=${{ needs.versioned_source.outputs.semver != '' }}
prefix=${{ steps.strings.outputs.prefix }},onlatest=true
suffix=${{ steps.strings.outputs.suffix }},onlatest=true
- &rejectMissingSecrets
name: Reject missing secrets
run: |
if [ -z '${{ secrets.FLOWZONE_TOKEN }}${{ secrets.GH_APP_PRIVATE_KEY }}' ]
then
echo '::error::Must specify either GH_APP_PRIVATE_KEY or FLOWZONE_TOKEN.'
false
fi
- &rejectFailedJobs
name: Reject failed jobs
run: |
if [ "${{ contains(needs.*.result, 'failure') }}" = "true" ]
then
echo "One or more jobs have failed"
exit 1
fi
- &rejectCancelledJobs
name: Reject cancelled jobs
run: |
if [ "${{ contains(needs.*.result, 'cancelled') }}" = "true" ]
then
echo "One or more jobs were cancelled"
exit 1
fi
- &rejectExternalPullRequest
name: Reject external pull_request events on pull_request
if: |
github.event_name == 'pull_request' &&
github.event.pull_request.head.repo.full_name != github.repository
run: |
echo "::error::External workflows can not be used with 'pull_request' events. \
Please contact a member of the organization for assistance."
exit 1
- &rejectInternalPullRequestTarget
name: Reject internal pull_request events on pull_request_target
if: |
github.event_name == 'pull_request_target' &&
github.event.pull_request.head.repo.full_name == github.repository
run: |
echo "::error::Internal workflows should not be used with 'pull_request_target' events. \
Please consult the documentation for more information."
exit 1
- &setupBuildx # https://github.com/docker/setup-buildx-action
name: Setup buildx
id: setup_buildx
uses: docker/setup-buildx-action@c47758b77c9736f4b2ef4073d4d51994fabfe349 # v3.7.1
with:
driver-opts: network=host
install: true
- &setupQemuBinfmt # https://github.com/docker/setup-qemu-action
name: Setup QEMU
id: qemu_binfmt
uses: docker/setup-qemu-action@49b3bc8e6bdd4a60e6116a5414239cba5943d3cf # v3.2.0
env:
LOG_LEVEL: debug
# renovate: datasource=docker depName=binfmt packageName=tonistiigi/binfmt
BINFMT_VERSION: qemu-v8.0.4-33
with:
platforms: ${{ matrix.platform }}
# https://hub.docker.com/r/tonistiigi/binfmt
image: tonistiigi/binfmt:${{ env.BINFMT_VERSION }}
- &setupNode # https://github.com/actions/setup-node
name: Setup Node.js
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
with:
node-version: 20.x
- &setupCrane # https://github.com/imjasonh/setup-crane
name: Setup crane
uses: imjasonh/setup-crane@31b88efe9de28ae0ffa220711af4b60be9435f6e # v0.4
with:
version: v0.14.0
- &setupPython # https://github.com/actions/setup-python
name: Setup python
id: setup-python
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0
with:
python-version: "3.9"
- &setupPoetry # https://github.com/abatilo/actions-poetry
name: Setup poetry
if: steps.setup-python.outputs.python-version != ''
uses: abatilo/actions-poetry@e78f54a89cb052fff327414dd9ff010b5d2b4dbd # v3.0.1
with:
poetry-version: "1.5.1"
- &setupSkopeo # https://github.com/product-os/setup-skopeo-action
name: Setup skopeo
uses: product-os/setup-skopeo-action@5a3989811388c16b01f29554996e0c7e802b410b # v0.0.2
with:
# https://github.com/lework/skopeo-binary/releases
version: "v1.15.0"
- &setupAwsCli
name: Setup AWS CLI
uses: product-os/setup-awscli-action@506c5b26faaa69e050009260f5f0c6755e7dd963 # v0.0.8
with:
version: "2.15.43"
- &sortNodeVersions
name: Sort node versions
id: node_versions
env:
VERSIONS: ${{ needs.is_npm.outputs.node_versions }}
run: |
echo "min=$(echo "${VERSIONS}" | jq -r '.[]' | sort --version-sort | head -n1)" >> "${GITHUB_OUTPUT}"
echo "max=$(echo "${VERSIONS}" | jq -r '.[]' | sort --version-sort --reverse | head -n1)" >> "${GITHUB_OUTPUT}"
- &waitForCloudFormation
name: Wait for resources
run: |
stack_status="$(aws cloudformation describe-stacks \
--stack-name '${{ matrix.stack }}' --output text --query Stacks[*].StackStatus || true)"
if [[ -n "$stack_status" ]]; then
aws cloudformation wait stack-exists --stack-name '${{ matrix.stack }}'
if [[ "$stack_status" =~ CREATE_IN_PROGRESS ]]; then
aws cloudformation wait stack-create-complete --stack-name '${{ matrix.stack }}'
fi
if [[ "$stack_status" =~ UPDATE_IN_PROGRESS ]]; then
aws cloudformation wait stack-update-complete --stack-name '${{ matrix.stack }}'
fi
if [[ "$stack_status" =~ ROLLBACK_IN_PROGRESS ]]; then
aws cloudformation wait stack-rollback-complete --stack-name '${{ matrix.stack }}'
fi
aws cloudformation describe-stacks --stack-name '${{ matrix.stack }}'
fi
- &getAWSCallerIdentity
name: Get caller identity (AWS/whoami)
if: steps.aws_credentials.outcome == 'success'
continue-on-error: true
run: aws sts get-caller-identity
- &updateKubeconfig
name: Update kubeconfig
run: |
aws eks update-kubeconfig --name "$(echo "${KUBE_CTX}" | awk -F'/' '{print $2}')"
- &publishSBOMArtifacts
name: Publish SBOM artifacts
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
- &publishSBOMToDependencyTrack
name: Publish SBOM To Dependency Track
if: ${{ env.SERVER_HOSTNAME != '' }}
run: |
curl -X "PUT" "https://${{ env.SERVER_HOSTNAME }}/api/v1/bom" \
-H 'Content-Type: application/json' \
-H 'X-API-Key: ${{env.API_KEY}}' \
-d '{
"projectName": "'"${{env.PROJECT_NAME}}"'",
"projectVersion": "'"${{env.PROJECT_VERSION}}"'",
"autoCreate": "true",
"bom": "'"$(base64 -w 0 "${{ env.BOM_FILE }}")"'"
}'
- &convenienceFunctions
name: Convenience functions
id: functions
run: |
# shellcheck disable=SC2034
EOF="$(openssl rand -hex 16)"
# https://sre.google/sre-book/addressing-cascading-failures/
with_backoff="$(mktemp)"
cat << $EOF > "${with_backoff}"
function with_backoff() {
local max_attempts=\${ATTEMPTS-3}
local timeout=\${TIMEOUT-2}
local attempt=0
local exitCode=0
set +e
while [[ \$attempt < \$max_attempts ]]; do
"\$@"
exitCode=\$?
[[ \$exitCode == 0 ]] && break
echo "Failure! Retrying in \$timeout.." 1>&2
sleep "\$timeout"
attempt=\$(( attempt + 1 ))
timeout=\$(( timeout * 2 ))
done
[[ \$exitCode != 0 ]] && echo "You've failed me for the last time! (\$*)" 1>&2
set -e
return \$exitCode
}
$EOF
echo "with_backoff=${with_backoff}" >> "${GITHUB_OUTPUT}"
- &randomDelay
name: Random delay
run: |
DELAY="${DELAY-5}"
random="$(((RANDOM % DELAY) + 1))"
echo "sleeping for ${random}s"
sleep "${random}s"
name: Flowzone
on:
workflow_call:
secrets:
# https://github.com/organizations/product-os/settings/secrets/actions/GH_APP_PRIVATE_KEY
GH_APP_PRIVATE_KEY:
description: "GitHub App to generate ephemeral access tokens"
required: false
FLOWZONE_TOKEN:
description: ".. or Personal Access Token (PAT) with admin/owner permissions in the org."
required: false
NPM_TOKEN:
description: "The npm auth token to use for publishing"
required: false
DOCKERHUB_USER:
description: "Username to publish to the Docker Hub container registry"
required: false
DOCKER_REGISTRY_USER:
description: "Deprecated, use DOCKERHUB_USER instead"
required: false
DOCKERHUB_TOKEN:
description: "A personal access token to publish to the Docker Hub container registry"
required: false
DOCKER_REGISTRY_PASS:
description: "Deprecated, use DOCKERHUB_TOKEN instead"
required: false
BALENA_API_KEY:
description: "API key for pushing releases to balena applications"
required: false
BALENA_API_KEY_PUSH:
description: "Deprecated, use BALENA_API_KEY instead"
required: false
CARGO_REGISTRY_TOKEN:
description: "A personal access token to publish to a cargo registry"
required: false
COMPOSE_VARS:
description: "Optional base64 encoded docker-compose `.env` file for testing Docker images"
required: false
CF_ACCOUNT_ID:
description: "Cloudflare account ID"
required: false
CF_API_TOKEN:
description: "Cloudflare API token with limited access for Pages projects"
required: false
PYPI_TOKEN:
description: "Token to publish to pypi.org"
required: false
PYPI_TEST_TOKEN:
description: "Token to publish to test.pypi.org"
required: false
ZULIP_API_KEY:
description: "API key to post Zulip messages."
required: false
CUSTOM_JOB_SECRET_1:
description: "Optional secret for using with custom jobs"
required: false
CUSTOM_JOB_SECRET_2:
description: "Optional secret for using with custom jobs"
required: false
CUSTOM_JOB_SECRET_3:
description: "Optional secret for using with custom jobs"
required: false
DTRACK_TOKEN:
description: "API key for Dependency-Track integration"
required: false
inputs:
aws_region:
description: "AWS region with GitHub OIDC provider IAM configuration"
type: string
required: false
default: "${{ vars.AWS_REGION || '' }}"
aws_iam_role:
description: "AWS IAM role ARN to assume with GitHub OIDC provider"
type: string
required: false
default: "${{ vars.AWS_IAM_ROLE || '' }}"
cloudformation_templates:
description: |
AWS CloudFormation templates to deploy (e.g.)
```
{
"stacks": [
{
"name": "foo",
"template": "aws/bar.yaml",
"tags": [
"Name=foo",
"Environment=${FOO}"
],
"capabilities": [
"CAPABILITY_IAM",
"CAPABILITY_NAMED_IAM"
]
},
...
]
}
```
* assumes `aws/bar.yaml` exists.
* `${ENVVARS}` injected at runtime from `vars` and `secrets` contexts
type: string
required: false
default: ""
app_id:
description: "GitHub App ID to impersonate"
type: string
required: false
default: "${{ vars.FLOWZONE_APP_ID || vars.APP_ID }}"
# not needed if installed on this current org/repo
installation_id:
description: "Deprecated, no longer used"
type: string
required: false
token_scope:
description: "Ephemeral token scope(s)"
type: string
required: false
# https://github.com/organizations/product-os/settings/installations/34040165
# https://docs.github.com/en/rest/apps/apps?apiVersion=2022-11-28#create-a-scoped-access-token
default: >-
{
"administration": "write",
"contents": "write",
"metadata": "read",
"packages": "write",
"pages": "write",
"pull_requests": "read"
}
jobs_timeout_minutes:
description: "Timeout for the job(s)."
type: number
required: false
default: 360
working_directory:
description: "GitHub actions working directory"
type: string
required: false
default: "."
docker_images:
description: "Comma-delimited string of Docker images (without tags) to publish (skipped if empty)"
type: string
required: false
default: ""
bake_targets:
description: "Comma-delimited string of Docker buildx bake targets to publish (skipped if empty)"
type: string
required: false
default: "default"
docker_invert_tags:
description: "Invert the tags for the Docker images (e.g. `{tag}-{variant}` becomes `{variant}-{tag}`)"
type: boolean
required: false
default: false
docker_publish_platform_tags:
description: "Publish platform-specific tags in addition to multi-arch manifests (e.g. `product-os/flowzone:latest-amd64`)"
type: boolean
required: false
default: false
balena_environment:
description: "balenaCloud environment"
type: string
required: false
default: balena-cloud.com
balena_slugs:
description: "Comma-delimited string of balenaCloud apps, fleets, or blocks to deploy (skipped if empty)"
type: string
required: false
default: ""
cargo_targets:
description: "Comma-delimited string of Rust stable targets to publish (skipped if empty)"
type: string
required: false
default: |
aarch64-unknown-linux-gnu,
armv7-unknown-linux-gnueabihf,
arm-unknown-linux-gnueabihf,
x86_64-unknown-linux-gnu,
i686-unknown-linux-gnu
rust_toolchain:
description: "Version specifier (e.g. 1.65, stable, nigthly) for the toolchain to use when building Rust sources"
type: string
required: false
default: stable
rust_binaries:
description: "Set to true to publish Rust binary release artifacts to GitHub"
type: boolean
required: false
default: false
pseudo_terminal:
description: "Set to true to enable terminal emulation for test steps"
type: boolean
required: false
default: false
disable_versioning:
description: "Set to true to disable automatic versioning"
type: boolean
required: false
default: false
runs_on:
description: "JSON array of runner label strings for default jobs."
type: string
required: false
default: >
[
"ubuntu-22.04"
]
docker_runs_on:
description: "JSON key-value pairs mapping platforms to arrays of runner labels. Unlisted platforms will use `runs_on`."
type: string
required: false
default: "{}"
cloudformation_runs_on:
description: "JSON array of runner label strings for cloudformation jobs."
type: string
required: false
cloudflare_website:
description: "Setting this to your existing CF pages project name will generate and deploy a website. Skipped if empty."
type: string
required: false
default: ""
docusaurus_website:
description: "Set to false to disable building a docusaurus website. If false the script `npm run deploy-docs` will be run if it exists."
type: boolean
required: false
default: true
github_prerelease:
description: "Finalize releases on merge."
type: boolean
required: false
default: false
restrict_custom_actions:
description: "Do not execute custom actions for external contributors. Only remove this restriction if custom actions have been vetted as secure."
type: boolean
required: false
default: true
custom_test_matrix:
description: "JSON matrix strategy for the custom test action. Properties 'environment' and 'os' will be applied to the job."
type: string
required: false
default: ""
custom_publish_matrix:
description: "JSON matrix strategy for the custom publish action. Properties 'environment' and 'os' will be applied to the job."
type: string
required: false
default: ""
custom_finalize_matrix:
description: "JSON matrix strategy for the custom finalize action. Properties 'environment' and 'os' will be applied to the job."
type: string
required: false
default: ""
custom_runs_on:
description: "Deprecated. Add the 'os' property in custom_test_matrix, custom_publish_matrix, and custom_finalize_matrix instead."
type: string
required: false
toggle_auto_merge:
description: "Set to false to disable toggling auto-merge on PRs."
type: boolean
required: false
default: true
release_notes:
description: "Create git tags and a PR comment with detailed change log."