4682 lines (4523 loc) · 188 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
# DO NOT EDIT MANUALLY - This file is auto-generated from `/flowzone.yml`
name: Flowzone
on:
workflow_call:
secrets:
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
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
OPENAI_API_KEY:
description: OpenAI API Key for GPT pull request reviews
required: false
OPENAI_ORG_KEY:
description: OpenAI Organization ID for GPT pull request reviews
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: ""
terraform_projects:
description: |
Terraform projects to deploy (e.g.)
```
{
"projects": [
{
"main_tf": "terraform/foo"
}
]
}
```
* assumes `terraform/foo/main.tf` exists
* GitHub `vars` and `secrets` contexts injected into TF plan/apply steps
type: string
required: false
default: ""
app_id:
description: GitHub App id to impersonate
type: string
required: false
default: ${{ vars.APP_ID || '291899' }}
installation_id:
description: GitHub App installation id
type: string
required: false
default: ${{ vars.INSTALLATION_ID || '34040165' }}
token_scope:
description: Ephemeral token scope(s)
type: string
required: false
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
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
enable_gpt_review:
description: Set to false to disable GPT pull request review generation.
type: boolean
required: false
default: false
ok_to_test_label:
description: Require a label before running checks for external contributions (forks).
type: string
required: false
default: ok-to-test
concurrency:
group: ${{ github.workflow }}-${{ github.event.number || github.ref }}
cancel-in-progress: ${{ github.event.action == 'synchronize' }}
env:
NPM_REGISTRY: https://registry.npmjs.org
CARGO_REGISTRY: crates.io
jobs:
event_types:
name: Event Types
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' ||
github.event.action == 'closed'
)
) || (
github.event_name == 'push' &&
startsWith(github.ref, 'refs/tags/')
)
strategy:
fail-fast: true
matrix:
include:
- event_name: ${{ github.event_name }}
event_action: ${{ github.event.action }}
steps:
- 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
- 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
- name: Reject unapproved pull_request_target events
if: |
inputs.ok_to_test_label != '' &&
github.event.pull_request.state == 'open' &&
github.event.pull_request.head.repo.full_name != github.repository
env:
GH_DEBUG: "true"
GH_PAGER: cat
GH_PROMPT_DISABLED: "true"
GH_REPO: ${{ github.repository }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
pr_labels="$(gh pr view ${{ github.event.pull_request.number }} --json labels -q .labels[].name)"
for label in "${pr_labels}"
do
if [[ "$label" =~ "${{ inputs.ok_to_test_label }}" ]]
then
gh pr edit ${{ github.event.pull_request.number }} --remove-label "${{ inputs.ok_to_test_label }}"
exit 0
fi
done
echo "::error::External contributions must be approved with the label '${{ inputs.ok_to_test_label }}'. \
Please contact a member of the organization for assistance."
exit 1
- 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
- name: Warn if GPT Review is skipped
if: |
github.event.pull_request.state == 'open' &&
github.event.repository.private &&
inputs.enable_gpt_review
run: echo "::warning::GPT Review is not supported for private repositories!"
- name: Log GitHub context
env:
GITHUB_CONTEXT: ${{ toJSON(github) }}
run: echo "${GITHUB_CONTEXT}" || true
versioned_source:
name: Versioned source
runs-on: ${{ fromJSON(inputs.runs_on) }}
timeout-minutes: ${{ fromJSON(inputs.jobs_timeout_minutes) }}
needs:
- event_types
if: |
github.event.action != 'closed' || github.event.pull_request.merged == true
defaults:
run:
working-directory: .
shell: bash --noprofile --norc -eo pipefail -x {0}
outputs:
tag: ${{ steps.versionist.outputs.tag || steps.git_describe.outputs.tag }}
semver: ${{ steps.versionist.outputs.semver || steps.git_describe.outputs.semver }}
sha: ${{ steps.create_tag.outputs.sha || steps.git_describe.outputs.sha }}
commit_sha: ${{ steps.create_commit.outputs.sha }}
tag_sha: ${{ steps.create_tag.outputs.sha }}
env:
GH_DEBUG: "true"
GH_PAGER: cat
GH_PROMPT_DISABLED: "true"
GH_REPO: ${{ github.repository }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Generate GitHub App installation token
uses: tibdex/github-app-token@3beb63f4bd073e61482598c45c71c1019b59b73a
continue-on-error: true
id: gh_app_token
with:
app_id: ${{ inputs.app_id }}
installation_retrieval_mode: id
installation_retrieval_payload: ${{ inputs.installation_id }}
private_key: ${{ secrets.GH_APP_PRIVATE_KEY }}
permissions: |-
{
"administration": "write",
"contents": "write",
"metadata": "read",
"pull_requests": "read"
}
- name: Checkout merge ref
if: github.event.pull_request.state == 'open'
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
with:
fetch-depth: 0
submodules: recursive
ref: refs/pull/${{ github.event.number }}/merge
token: ${{ steps.gh_app_token.outputs.token || secrets.FLOWZONE_TOKEN }}
- name: Checkout event sha
if: github.event.pull_request.state != 'open'
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
with:
fetch-depth: 0
submodules: recursive
ref: ${{ github.sha }}
token: ${{ steps.gh_app_token.outputs.token || secrets.FLOWZONE_TOKEN }}
- name: Reject merge commits
if: github.event.pull_request.state == 'open'
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: Describe git state
id: git_describe
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
echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
- name: Setup Node.js
uses: actions/setup-node@8f152de45cc393bb48ce5d89d36b731f54556e65
with:
node-version: 18.x
- name: Install versionist
if: inputs.disable_versioning != true
run: |
npm install -g balena-versionist@~0.14.13 versionist@^7.0.3
npm ls -g balena-versionist
npm ls -g versionist
- 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
$(npm root -g)/versionist/scripts/generate-changelog.sh .
fi
- 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'*'/package.json')
echo "::error file=.versionbot/CHANGELOG.yml,line=1::Versionist expects a package.json if repo.yml does not provide a 'type' for the project"
;;
*)
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
echo "tag=v${semver}" >> $GITHUB_OUTPUT
- name: Create blobs and tree objects
if: inputs.disable_versioning != true
id: create_tree
shell: bash
env:
GH_TOKEN: ${{ steps.gh_app_token.outputs.token || secrets.FLOWZONE_TOKEN }}
PARENT_COMMIT_SHA: ${{ steps.git_describe.outputs.sha }}
run: |
# Temporary array to hold our new tree objects
declare -a tree_array
# Use git status to check for new and modified files
modified_files=$(git diff --name-only ; git ls-files --others --exclude-standard)
# Extract changes
for file in $modified_files; do
echo "Creating blob of file $file..."
base64 -w0 "$file" > content.base64
response=$(gh api -X POST /repos/$GH_REPO/git/blobs \
-F 'content=@content.base64' \
-F 'encoding=base64')
rm content.base64
echo "$response" | jq .
blob_sha=$(echo $response | jq -r .sha)
# Add blob to our tree
tree_array+=("{\"path\":\"$file\",\"mode\":\"100644\",\"type\":\"blob\",\"sha\":\"$blob_sha\"}")
done
# Get the SHA of the tree the parent commit points to
base_tree_sha=$(git show -s --format=%T $PARENT_COMMIT_SHA)
# Create JSON array for tree creation
tree_json=$(printf ",%s" "${tree_array[@]}")
tree_json=${tree_json:1}
tree_json="[$tree_json]"
tree_json="{\"tree\": $tree_json, \"base_tree\": \"$base_tree_sha\"}"
echo "Creating tree..."
echo "$tree_json" | jq .
response=$(echo $tree_json | gh api -X POST /repos/$GH_REPO/git/trees --input -)
echo "$response" | jq .
echo "sha=$(echo $response | jq -r .sha)" >> $GITHUB_OUTPUT
echo "json=$(echo $response | jq -c .)" >> $GITHUB_OUTPUT
- name: Create commit object
if: inputs.disable_versioning != true
id: create_commit
env:
GH_TOKEN: ${{ steps.gh_app_token.outputs.token || secrets.FLOWZONE_TOKEN }}
MESSAGE: ${{ steps.versionist.outputs.tag }}
PARENT_COMMIT_SHA: ${{ steps.git_describe.outputs.sha }}
run: |
response=$(gh api -X POST /repos/$GH_REPO/git/commits \
-F "message=$MESSAGE" \
-F "tree=${{ steps.create_tree.outputs.sha }}" \
-F "parents[]=$PARENT_COMMIT_SHA")
echo "$response" | jq .
echo "sha=$(echo $response | jq -r .sha)" >> $GITHUB_OUTPUT
echo "json=$(echo $response | jq -c .)" >> $GITHUB_OUTPUT
- 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 }}
run: |
response=$(gh api -X POST repos/$GH_REPO/git/tags \
-F "tag=${TAG}" \
-F "message=${MESSAGE}" \
-F "object=${{ steps.create_commit.outputs.sha }}" \
-F "type=commit")
echo "$response" | jq .
echo "sha=$(echo $response | jq -r .sha)" >> $GITHUB_OUTPUT
echo "json=$(echo $response | jq -c .)" >> $GITHUB_OUTPUT
- name: Update branch 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 }}
run: |
gh api \
-X PATCH \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/repos/$GH_REPO/git/refs/heads/${{ github.base_ref }} \
-f sha='${{ steps.create_commit.outputs.sha }}' \
-F force=true \
--include
- name: Create tag 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 }}
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='refs/tags/${{ steps.versionist.outputs.tag }}' \
-f sha='${{ steps.create_tag.outputs.sha }}' \
--include
is_npm:
name: Is npm
runs-on: ${{ fromJSON(inputs.runs_on) }}
timeout-minutes: ${{ fromJSON(inputs.jobs_timeout_minutes) }}
needs:
- versioned_source
defaults:
run:
working-directory: ${{ inputs.working_directory }}
shell: bash --noprofile --norc -eo pipefail -x {0}
outputs:
npm: ${{ steps.npm.outputs.enabled }}
has_npm_lockfile: ${{ steps.npm_lock.outputs.has_npm_lockfile }}
npm_private: ${{ steps.npm.outputs.private }}
npm_docs: ${{ steps.npm.outputs.docs }}
node_versions: ${{ steps.node_versions.outputs.json }}
npm_access: ${{ steps.access.outputs.access }}
steps:
- name: Generate GitHub App installation token
uses: tibdex/github-app-token@3beb63f4bd073e61482598c45c71c1019b59b73a
continue-on-error: true
id: gh_app_token
with:
app_id: ${{ inputs.app_id }}
installation_retrieval_mode: id
installation_retrieval_payload: ${{ inputs.installation_id }}
private_key: ${{ secrets.GH_APP_PRIVATE_KEY }}
permissions: |-
{
"contents": "read",
"metadata": "read"
}
- name: Checkout versioned sha
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
with:
fetch-depth: 0
submodules: recursive
ref: ${{ needs.versioned_source.outputs.sha }}
token: ${{ steps.gh_app_token.outputs.token || secrets.FLOWZONE_TOKEN }}
- name: Check for package.json
id: npm
run: |
if test -f "package.json"
then
echo "found package.json"
echo "enabled=true" >> $GITHUB_OUTPUT
echo "private=$(jq -r '.private' package.json)" >> $GITHUB_OUTPUT
echo "docs=$(jq -r '.scripts | has("doc")' package.json)" >> $GITHUB_OUTPUT
echo "NODE_VERSIONS=[]" >> $GITHUB_ENV
else
echo "enabled=false" >> $GITHUB_OUTPUT
fi
- name: Check for package locks
id: npm_lock
run: |
has_npm_lockfile="$([ -e package-lock.json ] || [ -e npm-shrinkwrap.json ] && echo true || echo false)"
echo "has_npm_lockfile=${has_npm_lockfile}" >> $GITHUB_OUTPUT
- name: Set access
id: access
run: |
access="public"
if [ "${{ github.event.repository.private }}" = "true" ]
then
access="restricted"
fi
echo "access=${access}" >> $GITHUB_OUTPUT
- name: Setup Node.js
uses: actions/setup-node@8f152de45cc393bb48ce5d89d36b731f54556e65
with:
node-version: 12.x
if: steps.npm.outputs.enabled == 'true'
- name: Check engine
if: steps.npm.outputs.enabled == 'true'
run: |
if npx -q -y -- check-engine
then
echo "NODE_VERSIONS=$(echo "${NODE_VERSIONS}" | jq -c '. + ["12.x"]')" >> $GITHUB_ENV
fi
- name: Setup Node.js
uses: actions/setup-node@8f152de45cc393bb48ce5d89d36b731f54556e65
with:
node-version: 14.x
if: steps.npm.outputs.enabled == 'true'
- name: Check engine
if: steps.npm.outputs.enabled == 'true'
run: |
if npx -q -y -- check-engine
then
echo "NODE_VERSIONS=$(echo "${NODE_VERSIONS}" | jq -c '. + ["14.x"]')" >> $GITHUB_ENV
fi
- name: Setup Node.js
uses: actions/setup-node@8f152de45cc393bb48ce5d89d36b731f54556e65
with:
node-version: 16.x
if: steps.npm.outputs.enabled == 'true'
- name: Check engine
if: steps.npm.outputs.enabled == 'true'
run: |
if npx -q -y -- check-engine
then
echo "NODE_VERSIONS=$(echo "${NODE_VERSIONS}" | jq -c '. + ["16.x"]')" >> $GITHUB_ENV
fi
- name: Setup Node.js
uses: actions/setup-node@8f152de45cc393bb48ce5d89d36b731f54556e65
with:
node-version: 18.x
if: steps.npm.outputs.enabled == 'true'
- name: Check engine
if: steps.npm.outputs.enabled == 'true'
run: |
if npx -q -y -- check-engine
then
echo "NODE_VERSIONS=$(echo "${NODE_VERSIONS}" | jq -c '. + ["18.x"]')" >> $GITHUB_ENV
fi
- name: Setup Node.js
uses: actions/setup-node@8f152de45cc393bb48ce5d89d36b731f54556e65
with:
node-version: 20.x
if: steps.npm.outputs.enabled == 'true'
- name: Check engine
if: steps.npm.outputs.enabled == 'true'
run: |
if npx -q -y -- check-engine
then
echo "NODE_VERSIONS=$(echo "${NODE_VERSIONS}" | jq -c '. + ["20.x"]')" >> $GITHUB_ENV
fi
- name: Set Node.js versions
if: steps.npm.outputs.enabled == 'true'
id: node_versions
run: |
echo "json=[\"20.x\"]" >> $GITHUB_OUTPUT
if [ "${NODE_VERSIONS}" != "[]" ]
then
echo "json=${NODE_VERSIONS}" >> $GITHUB_OUTPUT
fi
is_docker:
name: Is docker
runs-on: ${{ fromJSON(inputs.runs_on) }}
timeout-minutes: ${{ fromJSON(inputs.jobs_timeout_minutes) }}
needs:
- versioned_source
defaults:
run:
working-directory: ${{ inputs.working_directory }}
shell: bash --noprofile --norc -eo pipefail -x {0}
outputs:
docker_images: ${{ steps.docker_images_json.outputs.build }}
docker_images_crlf: ${{ steps.docker_images_crlf.outputs.build }}
docker_compose_tests: ${{ steps.docker_compose_tests.outputs.found }}
bake_targets: ${{ steps.bake_targets_json.outputs.build }}
docker_bake_json: ${{ steps.docker_bake.outputs.json }}
docker_test_matrix: ${{ steps.docker_test.outputs.build }}
steps:
- name: Generate GitHub App installation token
uses: tibdex/github-app-token@3beb63f4bd073e61482598c45c71c1019b59b73a
continue-on-error: true
id: gh_app_token
with:
app_id: ${{ inputs.app_id }}
installation_retrieval_mode: id
installation_retrieval_payload: ${{ inputs.installation_id }}
private_key: ${{ secrets.GH_APP_PRIVATE_KEY }}
permissions: |-
{
"contents": "read",
"metadata": "read"
}
- name: Checkout versioned sha
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
with:
fetch-depth: 0
submodules: recursive
ref: ${{ needs.versioned_source.outputs.sha }}
token: ${{ steps.gh_app_token.outputs.token || secrets.FLOWZONE_TOKEN }}
- id: docker_images_json
name: Build JSON array from comma-separated list
uses: kanga333/json-array-builder@c7cd9d3a8b17cd368e9c2210bc3c16b0e2714ce5
with:
cmd: bash -c "echo $INPUT | tr -d '[:space:]'"
separator: ","
env:
INPUT: ${{ inputs.docker_images }}
- id: docker_images_crlf
name: Build newline-separated list from JSON array
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
env:
INPUT: ${{ steps.docker_images_json.outputs.build }}
- id: bake_targets_json
name: Build JSON array from comma-separated list
uses: kanga333/json-array-builder@c7cd9d3a8b17cd368e9c2210bc3c16b0e2714ce5
with:
cmd: bash -c "echo $INPUT | tr -d '[:space:]'"
separator: ","
env:
INPUT: ${{ inputs.bake_targets }}
- name: Check for docker compose test files
id: docker_compose_tests
run: |
if [ -n "$(ls docker-compose.test.{yml,yaml} 2>/dev/null)" ]
then
echo "found=true" >> $GITHUB_OUTPUT
else
echo "found=false" >> $GITHUB_OUTPUT
fi
- name: Setup buildx
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226
with:
version: v0.11.2
- name: Pre-process Docker bake files
id: docker_bake
if: |
join(fromJSON(steps.docker_images_json.outputs.build)) != '' ||
steps.docker_compose_tests.outputs.found == 'true'
env:
BAKE_FILE: /tmp/docker-bake.json
run: |
if [ -n "$(ls docker-bake{.override,}.{json,hcl} 2>/dev/null)" ]
then
files="$(echo $(ls -1 docker-bake{.override,}.{json,hcl} 2>/dev/null) | sed 's/ / -f /')"
else
echo '${{ steps.bake_targets_json.outputs.build }}' | jq -s '{target: (map({(.[]):{}}))}' > ${BAKE_FILE}
files="${BAKE_FILE}"
fi
# log merged files and targets
docker buildx bake --print ${{ join(fromJSON(steps.bake_targets_json.outputs.build),' ') }} -f ${files}
json="$(docker buildx bake --print ${{ join(fromJSON(steps.bake_targets_json.outputs.build),' ') }} -f ${files} \
| jq -cr '
.target |= map_values(."inherits" += ["docker-metadata-action"]) |
.target |= map_values(."platforms" //= ["linux/amd64"]) |
del(.group."default") |
if .group == {} then del(.group) else . end
')"
echo "json=${json}">> $GITHUB_OUTPUT
- name: Build docker test matrix
id: docker_test
if: steps.docker_bake.outputs.json != ''
env:
BAKE_JSON: ${{ steps.docker_bake.outputs.json }}
RUNS_ON: ${{ inputs.runs_on }}
DOCKER_RUNS_ON: ${{ inputs.docker_runs_on }}
run: |
matrix="$(jq -cr '.target | to_entries |
{include: map(.value.platforms[] as $p |
{target: .key, platform: $p}
)}' <<< "${BAKE_JSON}")"
matrix="$(jq -cr --argjson in "$DOCKER_RUNS_ON" --argjson default "$RUNS_ON" '.include |=
map(.platform as $p |
.runs_on = if ($in | has($p)) then $in[$p] else $default end)' <<< "${matrix}")"
echo "build=${matrix}">> $GITHUB_OUTPUT
is_python:
name: Is python
env:
SUPPORTED_VERSIONS: |
3.8
3.9
3.10
3.11
runs-on: ${{ fromJSON(inputs.runs_on) }}
timeout-minutes: ${{ fromJSON(inputs.jobs_timeout_minutes) }}
needs:
- versioned_source
defaults:
run:
working-directory: ${{ inputs.working_directory }}
shell: bash --noprofile --norc -eo pipefail -x {0}
outputs:
python_poetry: ${{ steps.python_poetry.outputs.enabled }}
python_versions: ${{ steps.python_versions.outputs.json }}
pypi_publish: ${{ steps.python_poetry.outputs.pypi_publish }}
steps:
- name: Generate GitHub App installation token
uses: tibdex/github-app-token@3beb63f4bd073e61482598c45c71c1019b59b73a
continue-on-error: true
id: gh_app_token
with:
app_id: ${{ inputs.app_id }}
installation_retrieval_mode: id
installation_retrieval_payload: ${{ inputs.installation_id }}
private_key: ${{ secrets.GH_APP_PRIVATE_KEY }}