-
Notifications
You must be signed in to change notification settings - Fork 5
/
flowzone.yml
3149 lines (2782 loc) · 111 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
- &checkGitHubAppPrivateKey
name: Check for GitHub App private key
id: gh_app_private_key
shell: bash
run: |
if [ -n '${{ secrets.GH_APP_PRIVATE_KEY }}' ]
then
echo 'found=true' >> $GITHUB_OUTPUT
else
echo 'found=false' >> $GITHUB_OUTPUT
fi
- &getGitHubAppToken # https://github.com/marketplace/actions/github-app-token
name: Generate GitHub App installation token
uses: tibdex/github-app-token@b62528385c34dbc9f38e5f4225ac829252d1ea92 # v1.8.0
if: steps.gh_app_private_key.outputs.found == 'true'
id: gh_app_token
with:
app_id: ${{ inputs.app_id }}
installation_id: ${{ inputs.installation_id }}
private_key: ${{ secrets.GH_APP_PRIVATE_KEY }}
permissions: ${{ inputs.token_scope }}
- &downloadSourceArtifact
name: Download source artifact
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3
with:
name: source-${{ github.event.pull_request.head.sha || github.event.head_commit.id }}
path: ${{ runner.temp }}
- &extractSourceArtifact
name: Extract source artifact
# tar: Cannot connect to D: resolve failed
shell: pwsh
working-directory: .
run: tar -xf ${{ runner.temp }}/source.tgz
- &getVersionTag
name: Get version from tags
id: version_tag
run: |
tag="$(git tag --points-at HEAD | tail -n1)"
echo "tag=${tag}" >> $GITHUB_OUTPUT
echo "semver=$(npx -q -y -- semver -c -l "${tag}")" >> $GITHUB_OUTPUT
echo "describe=$(git describe --tags --always --dirty | cat)" >> $GITHUB_OUTPUT
- &deployToBalenaAction
uses: balena-io/deploy-to-balena-action@e7041b7ca6dd85f47a3eb5ce141178bf77d85920 # v0.27.0
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 }}
registry_secrets: |
{
"ghcr.io": {
"username": "${{ github.actor }}",
"password": "${{ secrets.GITHUB_TOKEN }}"
},
"docker.io": {
"username": "${{ secrets.DOCKERHUB_USER }}",
"password": "${{ secrets.DOCKERHUB_TOKEN }}"
}
}
- &getReleaseNotes
name: Generate release notes
id: release_notes
run: |
set -ea
# prevent git from existing with 141
set +o pipefail
previous_tag="$(git --no-pager tag --list --sort=-version:refname "v*.*.*" --merged | head -n2 | tail -n1)"
release_notes_file="$(mktemp)"
git log ${previous_tag}..${{ github.event.pull_request.head.sha || github.event.head_commit.id }} --pretty=reference > "${release_notes_file}"
echo "file=${release_notes_file}" >> $GITHUB_OUTPUT
# FIXME: https://github.com/balena-io/deploy-to-balena-action/issues/194
- &updateBalenaReleaseNotes
name: Update balena release notes
run: |
set -ea
release_notes="$(cat < '${{ steps.release_notes.outputs.file }}' | jq -R -s .)"
app_id="$(curl --silent --retry 3 --fail \
"https://api.${{ inputs.balena_environment }}/v6/application?\$filter=slug%20eq%20%27${{ matrix.slug }}%27&\$select=id" \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer ${{ secrets.BALENA_API_KEY || secrets.BALENA_API_KEY_PUSH }}' \
| jq -r '.d[].id')"
release_id='${{ steps.balena_deploy.outputs.release_id }}'
if [[ -n $release_notes ]] && [[ -n $app_id ]] && [[ -n $release_id ]]; then
curl --silent --retry 3 --fail \
-X PATCH "https://api.${{ inputs.balena_environment }}/v6/release?\$filter=belongs_to__application%20eq%20${app_id}%20and%20id%20eq%20${release_id}" \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer ${{ secrets.BALENA_API_KEY || secrets.BALENA_API_KEY_PUSH }}' \
-d "{\"note\":${release_notes}}"
fi
- &checkoutMergeBranch
# for pull_request_target events that are not closed we need to specify the merge branch manually
# because the default checkout ref is the tip of the main/master branch
name: Checkout merge branch
if: github.event_name == 'pull_request_target' && github.event.action != 'closed'
id: checkout_merge
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3
with:
fetch-depth: 0
submodules: "recursive"
ref: "refs/pull/${{ github.event.number }}/merge"
token: ${{ steps.gh_app_token.outputs.token || secrets.FLOWZONE_TOKEN }}
- &checkoutSha # otherwise use the default checkout behaviour
name: Checkout sha
if: github.event_name != 'pull_request_target' || github.event.action == 'closed'
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3
with:
fetch-depth: 0
submodules: "recursive"
token: ${{ steps.gh_app_token.outputs.token || secrets.FLOWZONE_TOKEN }}
- &loginWithDockerHub
name: Login to Docker Hub
continue-on-error: true
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a # v2
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@f4ef78c080cd8ba55a85445d5b36e214a81df20a # v2
with:
registry: ghcr.io
username: ${{ github.actor }}
# FIXME: as per GitHub support:
# "You cannot authenticate with a GitHub App token on the GitHub Package Registry"
# so this will fail for external PRs as the automatic actions token will be read-only
password: ${{ secrets.GITHUB_TOKEN }}
- &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 }}"
# default to automatic actions token
GH_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
- &rejectExternalWorkflowChanges
name: Reject external workflow changes
<<: *ifExternalPullRequest
env:
<<: *gitHubCliEnvironment
run: |
if [[ $(gh pr diff ${{ github.event.pull_request.number }} --name-only) =~ ^\.github\/ ]]
then
echo "::error::Modifications to workflow files are not supported for external contributions. \
Please contact a member of the organization for assistance."
exit 1
fi
- &rejectExternalCustomActions
name: Reject external custom actions
if: |
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.event.pull_request.head.ref }}' || true
env:
<<: *gitHubCliEnvironment
GH_TOKEN: ${{ steps.gh_app_token.outputs.token || secrets.FLOWZONE_TOKEN }}
- &isDraftPullRequest # check both the github context (static) and via the gh cli (dynamic)
name: Check if PR is draft
id: is_draft_pr
env:
<<: *gitHubCliEnvironment
run: |
if gh pr view ${{ github.event.pull_request.number }} --json isDraft | jq -e '.isDraft == true'
then
echo "result=true" >> $GITHUB_OUTPUT
else
echo "result=false" >> $GITHUB_OUTPUT
fi
- &jsonArrayBuilder
name: Build JSON array from comma-separated list
id: to_json_array
uses: kanga333/json-array-builder@c7cd9d3a8b17cd368e9c2210bc3c16b0e2714ce5 # v0.2.1
with:
cmd: bash -c "echo $INPUT | tr -d '[:space:]'"
separator: ","
- &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:
<<: *dockerPlatformSlugMap
TARGET: ${{ matrix.target }}
PLATFORM: ${{ matrix.platform }}
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
platform_slug="$(jq -cr --arg platform "${PLATFORM}" '.[$platform] // ""' <<< "${PLATFORM_SLUG_MAP}")"
if [ -n "${PLATFORM}" ] && [ -z "${platform_slug}" ]
then
echo "::error::Unsupported platform: ${PLATFORM}"
fi
if [ -n "${IMAGE}" ]
then
if [[ "${IMAGE}" =~ ^(.*\/)?([^\/]+)\/([^\/\:]+)(\:.+)?$ ]]
then
image_slug="${IMAGE}"
else
image_slug="docker.io/${IMAGE}"
fi
fi
echo "image=${image_slug}" >> $GITHUB_OUTPUT
echo "target=${target_slug}" >> $GITHUB_OUTPUT
echo "platform=${platform_slug}" >> $GITHUB_OUTPUT
echo "prefix=${prefix_slug}" >> $GITHUB_OUTPUT
echo "suffix=${suffix_slug}" >> $GITHUB_OUTPUT
- &dockerTestMetadata # https://github.com/docker/metadata-action
name: Generate docker metadata
id: test_meta
uses: docker/metadata-action@c4ee3adeed93b1fa6a762f209fb01608c1a22f1e # v4
with: &dockerTestMetaWith
images: |
sut
localhost:5000/sut
${{ needs.is_docker.outputs.docker_images_crlf }}
labels: |
org.opencontainers.image.version=${{ steps.version_tag.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 }}
- &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=${{ steps.version_tag.outputs.tag }}
type=raw,value=${{ steps.version_tag.outputs.semver }}
flavor: |
latest=${{ steps.version_tag.outputs.semver != '' }}
prefix=${{ steps.strings.outputs.prefix }},onlatest=true
suffix=${{ steps.strings.outputs.suffix }},onlatest=true
- &rejectConflictingSecrets
name: Check 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
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 external pull_request events
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
- &rejectSelfHostedRunners
name: Reject self-hosted runners
if: |
github.event.pull_request.head.repo.full_name != github.repository &&
(
contains(fromJSON(inputs.runs_on), 'self-hosted') ||
contains(fromJSON(inputs.custom_runs_on), 'self-hosted') ||
contains(fromJSON(inputs.custom_runs_on).*, 'self-hosted') ||
contains(fromJSON(inputs.docker_runs_on).*, 'self-hosted')
)
run: |
echo "::error:External workflows can not be used with self-hosted runners. \
Please contact a member of the organization for assistance."
exit 1
- &setupQemuBinfmt # https://github.com/docker/setup-qemu-action
name: Setup QEMU
uses: docker/setup-qemu-action@e81a89b1732b9c48d79cd809d8d81d79c4647a18 # v2
if: contains(matrix.runs_on, 'self-hosted') != true
with:
platforms: all
# https://hub.docker.com/r/tonistiigi/binfmt
image: tonistiigi/binfmt:qemu-v6.2.0
- &setupBuildx # https://github.com/docker/setup-buildx-action
name: Setup buildx
uses: docker/setup-buildx-action@4b4e9c3e2d4531116a6f8ba8e71fc6e2cb6e6c8c # v2
with:
driver-opts: network=host
install: true
- &setupCrane # https://github.com/imjasonh/setup-crane
uses: imjasonh/setup-crane@00c9e93efa4e1138c9a7a5c594acd6c75a2fbf0c # v0.3
with:
version: v0.14.0
# If there are no existing protections an empty object will be returned
- &getBranchProtectionRules
name: Get branch protection rules
id: branch_protection
env:
<<: *gitHubCliEnvironment
GH_TOKEN: ${{ steps.gh_app_token.outputs.token || secrets.FLOWZONE_TOKEN }}
run: |
result="$(gh api "${BRANCH_PROTECTION_URI}" --jq '.' ; exit=$?)"
if [[ "${exit}" -gt 0 ]]
then
message="$(echo "${result}" | jq -r '.message // ""')"
case "${message}" in
"Branch not Found"|"Branch not protected")
echo "::warning::Failed to get branch protection rules ${message} ${result}"
exit 0
;;
*)
echo "::error::Failed to get branch protection rules ${message} ${result}"
exit 1
;;
esac
fi
echo "json=${result}" >> $GITHUB_OUTPUT
echo "required_status_checks__strict=$(jq -cr '.required_status_checks.strict // true' <<< "${result}")" >> $GITHUB_OUTPUT
echo "required_status_checks__contexts=$(jq -cr '.required_status_checks.contexts // []' <<< "${result}")" >> $GITHUB_OUTPUT
echo "required_pull_request_reviews__required_approving_review_count=$(jq -cr '.required_pull_request_reviews.required_approving_review_count // 0' <<< "${result}")" >> $GITHUB_OUTPUT
echo "required_pull_request_reviews__dismiss_stale_reviews=$(jq -cr '.required_pull_request_reviews.dismiss_stale_reviews // false' <<< "${result}")" >> $GITHUB_OUTPUT
echo "required_pull_request_reviews__require_code_owner_reviews=$(jq -cr '.required_pull_request_reviews.require_code_owner_reviews // false' <<< "${result}")" >> $GITHUB_OUTPUT
echo "required_pull_request_reviews__dismissal_restrictions__users=$(jq -cr '.required_pull_request_reviews.dismissal_restrictions.users // []' <<< "${result}")" >> $GITHUB_OUTPUT
echo "required_pull_request_reviews__dismissal_restrictions__teams=$(jq -cr '.required_pull_request_reviews.dismissal_restrictions.teams // []' <<< "${result}")" >> $GITHUB_OUTPUT
echo "required_pull_request_reviews__dismissal_restrictions__apps=$(jq -cr '.required_pull_request_reviews.dismissal_restrictions.apps // []' <<< "${result}")" >> $GITHUB_OUTPUT
echo "required_linear_history__enabled=$(jq -cr '.required_linear_history.enabled // false' <<< "${result}")" >> $GITHUB_OUTPUT
echo "allow_force_pushes__enabled=$(jq -cr '.allow_force_pushes.enabled // false' <<< "${result}")" >> $GITHUB_OUTPUT
echo "allow_deletions__enabled=$(jq -cr '.allow_deletions.enabled // false' <<< "${result}")" >> $GITHUB_OUTPUT
echo "required_conversation_resolution__enabled=$(jq -cr '.required_conversation_resolution.enabled // false' <<< "${result}")" >> $GITHUB_OUTPUT
echo "required_signatures__enabled=$(jq -cr '.required_signatures.enabled // false' <<< "${result}")" >> $GITHUB_OUTPUT
echo "enforce_admins__enabled=$(jq -cr '.enforce_admins.enabled // false' <<< "${result}")" >> $GITHUB_OUTPUT
echo "block_creations__enabled=$(jq -cr '.block_creations.enabled // false' <<< "${result}")" >> $GITHUB_OUTPUT
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
GPG_PRIVATE_KEY:
description: "GPG private key exported with `gpg --armor --export-secret-keys ...` to sign commits"
required: false
GPG_PASSPHRASE:
description: "Passphrase to decrypt GPG private key"
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
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
inputs:
app_id:
description: "GitHub App id to impersonate"
type: string
required: false
# https://github.com/organizations/product-os/settings/apps/flowzone-app
# https://github.com/organizations/product-os/settings/variables/actions/APP_ID
default: "${{ vars.APP_ID || '291899' }}"
# not needed if installed on this current org/repo
installation_id:
description: "GitHub App installation id"
type: string
required: false
# https://github.com/organizations/product-os/settings/installations
# https://github.com/organizations/product-os/settings/variables/actions/INSTALLATION_ID
default: "${{ vars.INSTALLATION_ID || '34040165' }}"
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: >-
{
"actions": "read",
"administration": "write",
"checks": "read",
"contents": "write",
"members": "read",
"metadata": "read",
"organization_secrets": "read",
"packages": "write",
"pages": "write",
"pull_requests": "read",
"secrets": "read",
"statuses": "read",
"workflows": "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
repo_config:
description: "Set to true to standardise repository settings after a successful run"
type: boolean
required: false
default: false
repo_allow_forking:
description: "Allow forking of an organization repository"
type: boolean
required: false
default: true
repo_default_branch:
description: "Set the default branch name for the repository"
type: string
required: false
default: master
repo_delete_branch_on_merge:
description: "Delete head branch when pull requests are merged"
type: boolean
required: false
default: true
repo_allow_update_branch:
description: "Always suggest updating pull request branches"
type: boolean
required: false
default: true
repo_description:
description: "Description of the repository"
type: string
required: false
default: ""
repo_homepage:
description: "Repository home page URL"
type: string
required: false
default: ""
repo_enable_auto_merge:
description: "Enable auto-merge functionality"
type: boolean
required: false
default: true
repo_enable_issues:
description: "Enable issues in the repository"
type: boolean
required: false
default: true
repo_enable_merge_commit:
description: "Enable merging pull requests via merge commit"
type: boolean
required: false
default: true
repo_enable_projects:
description: "Enable projects in the repository"
type: boolean
required: false
default: false
repo_enable_rebase_merge:
description: "Enable merging pull requests via rebase"
type: boolean
required: false
default: false
repo_enable_squash_merge:
description: "Enable merging pull requests via squashed commit"
type: boolean
required: false
default: false
repo_enable_wiki:
description: "Enable wiki in the repository"
type: boolean
required: false
default: false
repo_visibility:
description: "Change the visibility of the repository to {public,private,internal}"
type: string
required: false
default: default
disable_versioning:
description: "Set to true to disable automatic versioning"
type: boolean
required: false
default: false
job_name:
description: "The name of the job, necessary for branch protection if not using the default of 'Flowzone'"
type: string
required: false
default: "Flowzone"
checkout_fetch_depth:
description: "Configures the depth of the actions/checkout git fetch."
type: number
required: false
default: 1
tests_run_on:
description: "Deprecated, use 'custom_runs_on' input instead."
type: string
required: false
default: ""
runs_on:
description: "JSON array of runner label strings for generic jobs."
type: string
required: false
default: >
[
"ubuntu-22.04"
]
custom_runs_on:
description: "JSON 2-dimensional matrix of runner label strings for custom 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: "{}"
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: "Comma-delimited string of values that will be passed to the custom test action."
type: string
required: false
default: ""
custom_publish_matrix:
description: "Comma-delimited string of values that will be passed to the custom publish action."
type: string
required: false
default: ""
custom_finalize_matrix:
description: "Comma-delimited string of values that will be passed to the custom finalize action."
type: string
required: false
default: ""
protect_branch:
description: "Set to false to disable updating branch protection rules after a successful run."
type: boolean
required: false
default: true
required_approving_review_count:
description: "Count of GitHub approved reviews required for Pull Requests to be merged. Set to 0 if using palantir/policy-bot for PR merge conditions."
type: string
required: false
default: "0"
required_status_checks:
description: "JSON array of status checks that must pass before a Pull Requests can be merged. Skipped if `protect_branch` is false."
type: string
required: false
default: >
[
"Flowzone / All tests",
"Flowzone / All jobs",
"policy-bot: ${{ github.event.repository.default_branch }}"
]
toggle_auto_merge:
description: "Set to false to disable toggling auto-merge on PRs."
type: boolean
required: false
default: true
# https://docs.github.com/en/actions/using-jobs/using-concurrency
concurrency:
group: flowzone-${{ github.ref }}
# cancel jobs in progress as long as it's not a merged PR
cancel-in-progress: ${{ github.ref != github.base_ref }}
env:
NPM_REGISTRY: "https://registry.npmjs.org"
CARGO_REGISTRY: crates.io
jobs:
is_pr_open:
name: Is PR Open
runs-on: ${{ fromJSON(inputs.runs_on) }}
timeout-minutes: ${{ fromJSON(inputs.jobs_timeout_minutes) }}
if: |
(
github.event_name == 'pull_request' ||
github.event_name == 'pull_request_target'
) && (
github.event.action == 'opened' ||
github.event.action == 'synchronize'
)
steps:
- *rejectExternalPullRequest
- *rejectInternalPullRequestTarget
- *rejectConflictingSecrets
- *rejectExternalWorkflowChanges
- *rejectSelfHostedRunners
- *logGitHubContext
# in our context closed does not include merged
is_pr_closed:
name: Is PR Closed
runs-on: ${{ fromJSON(inputs.runs_on) }}
timeout-minutes: ${{ fromJSON(inputs.jobs_timeout_minutes) }}
if: |
(
github.event_name == 'pull_request' ||
github.event_name == 'pull_request_target'
) && (
github.event.action == 'closed' &&
github.event.pull_request.merged == false
)
steps:
- *rejectExternalPullRequest
- *rejectInternalPullRequestTarget
- *rejectConflictingSecrets
- *rejectExternalWorkflowChanges
- *rejectSelfHostedRunners
- *logGitHubContext
is_pr_merged:
name: Is PR Merged
runs-on: ${{ fromJSON(inputs.runs_on) }}
timeout-minutes: ${{ fromJSON(inputs.jobs_timeout_minutes) }}
if: |
(
github.event_name == 'pull_request' ||
github.event_name == 'pull_request_target'
) && (
github.event.action == 'closed' &&
github.event.pull_request.merged == true
)
steps:
- *rejectExternalPullRequest
- *rejectInternalPullRequestTarget
- *rejectConflictingSecrets
- *logGitHubContext
is_pushed_tag:
name: Is Pushed Tag
runs-on: ${{ fromJSON(inputs.runs_on) }}
timeout-minutes: ${{ fromJSON(inputs.jobs_timeout_minutes) }}
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
steps:
- *rejectConflictingSecrets
- *logGitHubContext
versioned_source:
name: Versioned source
runs-on: ${{ fromJSON(inputs.runs_on) }}
timeout-minutes: ${{ fromJSON(inputs.jobs_timeout_minutes) }}
needs:
- is_pr_open
- is_pr_merged
- is_pushed_tag
if: |
!failure() && !cancelled() && (
needs.is_pushed_tag.result == 'success' ||
needs.is_pr_open.result == 'success' ||
needs.is_pr_merged.result == 'success'
)
<<: *rootWorkingDirectory
outputs:
tag: ${{ steps.versionist.outputs.tag || steps.version_tag.outputs.tag }}
semver: ${{ steps.versionist.outputs.semver || steps.version_tag.outputs.semver }}
steps:
- *checkGitHubAppPrivateKey
- *getGitHubAppToken
- *checkoutMergeBranch
- *checkoutSha
# fail on merge commits (ones with more than one parent)
- name: Reject merge commits
run: |
if [ "$(git cat-file -p ${{ github.event.pull_request.head.sha || github.event.head_commit.id }} | grep '^parent ' | wc -l)" -gt 1 ]
then
echo "::error::Latest commit appears to be a merge, which is currently unsupported. Try a rebase instead."
exit 1
fi
- name: Import GPG key for signing commits
if: inputs.disable_versioning != true
id: import-gpg
uses: crazy-max/ghaction-import-gpg@111c56156bcc6918c056dbef52164cfa583dc549 # v5.2.0
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.GPG_PASSPHRASE }}
git_config_global: true
git_user_signingkey: true
git_commit_gpgsign: true
- name: Install versionist
if: inputs.disable_versioning != true
run: |
npm install -g balena-versionist@0.14.12 versionist@6.9.2
- name: Generate changelog
if: inputs.disable_versioning != true
env:
GH_TOKEN: ${{ steps.gh_app_token.outputs.token || secrets.FLOWZONE_TOKEN }}
run: |
if [ ! -f .versionbot/CHANGELOG.yml ]
then
(cd ${{ runner.temp }}
wget https://github.com/mikefarah/yq/releases/download/3.0.1/yq_linux_amd64 -O yq
echo "a1097c74b81a2ef255583d9718bf4be6 yq" | md5sum -c -
chmod +x yq
PATH="${PWD}:${PATH}" $(npm root -g)/versionist/scripts/generate-changelog.sh "${GITHUB_WORKSPACE}"
)
fi
# run balena-versionist
# print the error if anything fails
# fail the workflow if the error is anything other than "No such file or directory"
- name: Run versionist
if: inputs.disable_versioning != true
id: versionist
env:
GITHUB_TOKEN: ${{ steps.gh_app_token.outputs.token || secrets.FLOWZONE_TOKEN }}
run: |
out="$(balena-versionist 2>&1)"
error="$(awk '/Error:/{getline; print}' <<< "${out}")"
case ${error} in
"") # no error
;;
'No such file or directory'*)
echo "::error::${error}"
;;
*)
echo "::error::${error}"
exit 1
;;
esac
git status --porcelain
versions=()
[ -f .versionbot/CHANGELOG.yml ] && versions+=($(yq e '.[0].version' .versionbot/CHANGELOG.yml))
semver="${versions[0]}"
echo "semver=${semver}" >> $GITHUB_OUTPUT