-
Notifications
You must be signed in to change notification settings - Fork 5
5108 lines (4924 loc) · 203 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
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 }}
installation_id:
description: Deprecated, no longer used
type: string
required: false
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
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-24.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.
type: boolean
required: false
default: false
max_parallel:
description: Set a max parallel value for ALL matrix strategy jobs.
type: number
required: false
default: 20
generate_sbom:
description: Generate a Software Bill of Materials (SBOM) for the release.
type: boolean
required: false
default: true
outputs:
cloudflare_deployment_url:
description: Cloudflare Deployment URL
value: ${{ jobs.website_publish.outputs.cloudflare_deployment_url }}
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}
env:
NPM_REGISTRY: https://registry.npmjs.org
CARGO_REGISTRY: crates.io
jobs:
event_types:
name: Event Types
runs-on: ubuntu-24.04
timeout-minutes: 60
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 }}
permissions: {}
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 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: Generate GitHub App installation token
uses: tibdex/github-app-token@3beb63f4bd073e61482598c45c71c1019b59b73a
if: inputs.app_id
id: gh_app_token
with:
app_id: ${{ inputs.app_id }}
installation_retrieval_mode: organization
installation_retrieval_payload: ${{ github.repository_owner }}
private_key: ${{ secrets.GH_APP_PRIVATE_KEY }}
permissions: |-
{
"metadata": "read",
"issues": "read",
"pull_requests": "write"
}
- name: Wait for approval on pull_request_target events
if: github.event_name == 'pull_request_target' && github.event.pull_request.merged != true
uses: product-os/review-commit-action@cddebf4cec8e40ea8f698b6dcce8cd70e38b7320
with:
poll-interval: "10"
allow-authors: false
github-token: ${{ steps.gh_app_token.outputs.token || secrets.FLOWZONE_TOKEN }}
- 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}
permissions:
contents: read
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 }}
author: ${{ steps.create_commit.outputs.author }}
tag_sha: ${{ steps.create_tag.outputs.sha }}
depth: ${{ steps.git_describe.outputs.depth || 0 }}
env:
GH_DEBUG: "true"
GH_PAGER: cat
GH_PROMPT_DISABLED: "true"
GH_REPO: ${{ github.repository }}
steps:
- name: Generate GitHub App installation token
uses: tibdex/github-app-token@3beb63f4bd073e61482598c45c71c1019b59b73a
if: inputs.app_id
id: gh_app_token
with:
app_id: ${{ inputs.app_id }}
installation_retrieval_mode: organization
installation_retrieval_payload: ${{ github.repository_owner }}
private_key: ${{ secrets.GH_APP_PRIVATE_KEY }}
permissions: |-
{
"administration": "write",
"contents": "write",
"metadata": "read",
"pull_requests": "read"
}
- name: Reject HEAD branches containing merge commits
if: github.event.pull_request.state == 'open'
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea
with:
github-token: ${{ steps.gh_app_token.outputs.token || secrets.FLOWZONE_TOKEN }}
result-encoding: json
script: |
const { data: commits } = await github.rest.pulls.listCommits({
...context.repo,
pull_number: context.payload.pull_request.number
});
if (commits.some(({ parents }) => parents.length > 1)) {
throw new Error('Non-linear history detected - merge commit(s) identified in HEAD branch');
}
- name: Reject merge commits that do not include the HEAD commit as a parent
if: github.event.pull_request.merged
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea
with:
github-token: ${{ steps.gh_app_token.outputs.token || secrets.FLOWZONE_TOKEN }}
result-encoding: json
script: |
console.debug(`Merge commit SHA: ${context.sha}`)
console.debug(`HEAD commit SHA: ${context.payload.pull_request.head.sha}`)
const { data: commit } = await github.rest.repos.getCommit({
...context.repo,
ref: context.sha
});
console.debug('Commit parents: %s', JSON.stringify(commit.parents, null, 2))
if (!commit.parents.some(({ sha }) => sha === context.payload.pull_request.head.sha)) {
throw new Error('Non-linear history detected - HEAD branch commit is not a parent of the merge commit');
}
- name: Checkout pull request head sha
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
with:
fetch-depth: 0
submodules: recursive
ref: ${{ github.event.pull_request.head.sha || '¯\_(ツ)_/¯' }}
token: ${{ steps.gh_app_token.outputs.token || secrets.FLOWZONE_TOKEN }}
persist-credentials: false
if: github.event.pull_request.state == 'open'
- name: Checkout ${{ github.sha }}
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
with:
fetch-depth: 0
submodules: recursive
ref: ${{ github.sha || '¯\_(ツ)_/¯' }}
token: ${{ steps.gh_app_token.outputs.token || secrets.FLOWZONE_TOKEN }}
persist-credentials: false
if: github.event.pull_request.state != 'open'
- 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=1" >> "${GITHUB_OUTPUT}"
else
echo "depth=0" >> "${GITHUB_OUTPUT}"
fi
- name: Setup Node.js
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a
env:
NODE_VERSION: 20.18.2
with:
node-version: ${{ env.NODE_VERSION }}
- name: Install versioning tools
if: inputs.disable_versioning != true
run: |
npm install -g \
balena-versionist@~0.15.0 \
versionist@^7.0.3
npm ls -g
- 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 ] && read -r -a 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
env:
PARENT_COMMIT_SHA: ${{ steps.git_describe.outputs.sha }}
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea
with:
github-token: ${{ steps.gh_app_token.outputs.token || secrets.FLOWZONE_TOKEN }}
script: |
const { execSync } = require('child_process');
const fs = require('fs').promises;
// Get modified and untracked files
const getModifiedFiles = () => {
const modifiedCmd = 'git diff --name-only';
const untrackedCmd = 'git ls-files --others --exclude-standard';
const modified = execSync(modifiedCmd).toString().trim().split('\n');
const untracked = execSync(untrackedCmd).toString().trim().split('\n');
return [...new Set([...modified, ...untracked])].filter(f => f != null && !!f.trim());
};
// Create tree entries for modified files
const createTreeEntries = async () => {
const files = getModifiedFiles();
const entries = await Promise.all(files.map(async (file) => {
core.info(`Creating blob for file ${file}...`);
// Read file content and create blob
const content = await fs.readFile(file, { encoding: 'utf8' });
const { data: blob } = await github.rest.git.createBlob({
...context.repo,
content: Buffer.from(content).toString("base64"),
encoding: 'base64'
});
return {
path: file,
mode: '100644',
type: 'blob',
sha: blob.sha
};
}));
return entries;
};
// Get base tree SHA
const parentSha = process.env.PARENT_COMMIT_SHA;
const baseTreeSha = execSync(`git show -s --format=%T "${parentSha}"`).toString().trim();
// Create new tree
const treeEntries = await createTreeEntries();
const { data: tree } = await github.rest.git.createTree({
...context.repo,
tree: treeEntries,
base_tree: baseTreeSha
});
core.setOutput('sha', tree.sha);
return tree;
- name: Create commit object
if: inputs.disable_versioning != true
id: create_commit
env:
MESSAGE: ${{ steps.versionist.outputs.tag }}
TREE_SHA: ${{ steps.create_tree.outputs.sha }}
PARENT_COMMIT_SHA: ${{ steps.git_describe.outputs.sha }}
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea
with:
github-token: ${{ steps.gh_app_token.outputs.token || secrets.FLOWZONE_TOKEN }}
result-encoding: json
script: |
const { data: commit } = await github.rest.git.createCommit({
...context.repo,
message: process.env.MESSAGE,
tree: process.env.TREE_SHA,
parents: [process.env.PARENT_COMMIT_SHA]
});
core.setOutput('author', commit.author.name);
core.setOutput('sha', commit.sha);
return commit;
- name: Create tag object
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 }}
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea
with:
github-token: ${{ steps.gh_app_token.outputs.token || secrets.FLOWZONE_TOKEN }}
result-encoding: json
script: |
const { data: tag } = await github.rest.git.createTag({
...context.repo,
tag: process.env.TAG,
message: process.env.MESSAGE,
object: process.env.SHA,
type: 'commit'
});
core.setOutput('sha', tag.sha);
return tag;
if: inputs.disable_versioning != true
- name: Update git reference (force)
env:
GH_TOKEN: ${{ steps.gh_app_token.outputs.token || secrets.FLOWZONE_TOKEN }}
REF: heads/${{ github.base_ref }}
SHA: ${{ steps.create_commit.outputs.sha }}
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea
with:
github-token: ${{ steps.gh_app_token.outputs.token || secrets.FLOWZONE_TOKEN }}
result-encoding: json
script: |
const { data: ref } = await github.rest.git.updateRef({
...context.repo,
ref: process.env.REF.replace(/^refs\//, ''),
sha: process.env.SHA,
force: true
});
return ref;
if: |
github.event.pull_request.merged &&
steps.create_commit.outputs.sha
- name: Create git reference
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 }}
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea
with:
github-token: ${{ steps.gh_app_token.outputs.token || secrets.FLOWZONE_TOKEN }}
result-encoding: json
script: |
const { data: ref } = await github.rest.git.createRef({
...context.repo,
ref: process.env.REF,
sha: process.env.SHA
});
return ref;
if: |
github.event.pull_request.merged &&
steps.create_tag.outputs.sha
release_notes:
name: Generate release notes
runs-on: ${{ fromJSON(inputs.runs_on) }}
timeout-minutes: ${{ fromJSON(inputs.jobs_timeout_minutes) }}
needs:
- versioned_source
if: |
needs.versioned_source.outputs.tag != '' &&
(
github.event.action != 'closed' ||
github.event.pull_request.merged == true
)
defaults:
run:
working-directory: .
shell: bash --noprofile --norc -eo pipefail -x {0}
permissions:
contents: read
outputs:
body: ${{ steps.format_release_notes.outputs.body }}
comment: ${{ steps.format_release_notes.outputs.comment }}
note: ${{ steps.short_release_notes.outputs.result }}
env:
GH_DEBUG: "true"
GH_PAGER: cat
GH_PROMPT_DISABLED: "true"
GH_REPO: ${{ github.repository }}
steps:
- name: Generate GitHub App installation token
uses: tibdex/github-app-token@3beb63f4bd073e61482598c45c71c1019b59b73a
if: inputs.app_id
id: gh_app_token
with:
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",
"pull_requests": "read"
}
- name: Format release notes
id: format_release_notes
continue-on-error: true
env:
GH_TOKEN: ${{ steps.gh_app_token.outputs.token || secrets.FLOWZONE_TOKEN }}
run: |
set -x
pr_title="$(gh pr view ${{ github.event.pull_request.number }} --json title --jq .title)"
raw_body="$(gh pr view ${{ github.event.pull_request.number }} --json body --jq .body)"
if [[ -n "$pr_title" ]]; then
# if Renovate did this, extract its release notes from pull request body and
# massage until they resemble balena-io-modules/balena-deploy-request output
renovate_bot="$(gh pr view ${{ github.event.pull_request.number }} --json author --jq \
'select((.author.is_bot==true) and (.author.login | contains("renovate"))).author.login')"
title_pattern="## (R|r)elease (N|n)otes"
if [[ -n "$renovate_bot" ]] && [[ "$raw_body" =~ '### Release Notes' ]]; then
# TODO: remove duplicate <details> sections on the pr_body
# https://github.com/renovatebot/renovate/issues/13037
pr_body="$(echo "${raw_body}" \
| sed -n '/^### Release Notes$/,/^---$/p' \
| sed "s|^### Release Notes$||g" \
| sed 's/^---$//g')"
notable_changes="$(echo "${pr_body}" |
# Only get lines starting with `-`, `> -` or `<summary>`
grep -E '^> -|^-|^<summary>' |
# Replace the contents of the summary tag with a list item
sed -E 's|^<summary>(.*)</summary>|-\1|g' |
# Remove duplicate lines
awk '!(NF && seen[$0]++)' |
# Remove first line
sed 1d)"
# Prepare the release notes
release_notes_changes="$(echo "${notable_changes}" | sed -E 's|^> -(.*)| -\1|g')"
release_notes="$(printf '## %s\n\n### Notable changes\n\n%s\n\n%s' "${pr_title}" "${release_notes_changes}" "${pr_body}")"
# Prepare the comment body
notable_changes="$(echo "${notable_changes}" | sed -E 's|^|* |g')"
notable_changes="$(printf 'Notable changes\n* [only keep the important and rephrase, leaving this in place will avoid posting release notes]\n%s' "${notable_changes}")"
# https://zulip.com/help/format-your-message-using-markdown
# shortnames: https://pygments.org/docs/lexers/
release_notes_comment="$(printf '#release-notes %s\n\n%s%s' "${pr_title}" "${notable_changes}" "${pr_body}")"
# Handle non-renovate cases
elif [[ "$raw_body" =~ $title_pattern ]]; then
# Find a section `## Release notes` and use that as the release notes body
release_notes_body="$(echo "${raw_body}" \
| sed -n '/^## Release Notes/I,/^## /p' \
| sed '/^## /d' \
| sed -e :a -e '/./,$!d;/^\n*$/{$d;N;};/\n$/ba')" # Remove starting/trailing empty lines
release_notes="$(printf '## %s\n%s' "${pr_title}" "${release_notes_body}")"
fi
if [[ -n "$release_notes" ]]; then
EOF="$(openssl rand -hex 16)"
echo "body<<$EOF" >> $GITHUB_OUTPUT
echo "${release_notes}" >> $GITHUB_OUTPUT
echo "$EOF" >> $GITHUB_OUTPUT
fi
if [[ -n "$release_notes_comment" ]]; then
EOF="$(openssl rand -hex 16)"
echo "comment<<$EOF" >> $GITHUB_OUTPUT
echo "${release_notes_comment}" >> $GITHUB_OUTPUT
echo "$EOF" >> $GITHUB_OUTPUT
fi
fi
- name: Generate short release note
id: short_release_notes
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea
env:
USER_DEFINED: ${{ steps.format_release_notes.outputs.body }}
CURRENT_TAG: ${{ needs.versioned_source.outputs.tag }}
with:
result-encoding: json
script: |
// Get all tags sorted by version in descending order
const { data: tags } = await github.rest.repos.listTags({
...context.repo,
per_page: 10, // only fetch the last handful of tags
page: 1
});
// Filter out the current tag
const filteredTags = tags.filter(tag => tag.name !== process.env.CURRENT_TAG);
console.log('tags:', JSON.stringify(filteredTags, null, 2));
core.setOutput('tags', filteredTags);
// Get the previous version tag
const previousTag = filteredTags.find(tag => tag.name.match(/^v\d+\.\d+\.\d+/));
if (!previousTag) {
core.setFailed('No previous version tag found');
}
console.log('previousTag:', JSON.stringify(previousTag, null, 2));
core.setOutput('previousTag', previousTag);
const base = previousTag.name;
const head = context.payload.pull_request?.head.sha || context.sha;
// Get commit history between previous tag and current commit
const { data: { commits } } = await github.rest.repos.compareCommitsWithBasehead({
...context.repo,
basehead: `${base}...${head}`,
});
console.log('commits:', JSON.stringify(commits, null, 2));
core.setOutput('commits', commits);
// Format commits as git log --pretty=references
// e.g. 8011111 (commit message, yyyy-mm-dd)
const changelog = commits.map(commit => {
const shortSha = commit.sha.substring(0, 8);
return `${shortSha} (${commit.commit.message.split('\n')[0]}, ${commit.commit.author.date.split('T')[0]})`;
}).join('\n');
core.setOutput('changelog', changelog);
// Generate release notes
const userDefined = process.env.USER_DEFINED;
const releaseNotes = userDefined
? `${userDefined}\n\n### List of commits\n\n${changelog}`
: changelog;
console.log(releaseNotes);
// Write to file
const fs = require('fs');
fs.writeFileSync(process.env.RUNNER_TEMP + '/release-notes.txt', releaseNotes);
return releaseNotes;
- name: Upload release notes file
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08
with:
name: release-notes
path: ${{ runner.temp }}/release-notes.txt
retention-days: 1
release_notes_comment:
name: Prepare deploy message
runs-on: ${{ fromJSON(inputs.runs_on) }}
timeout-minutes: ${{ fromJSON(inputs.jobs_timeout_minutes) }}
needs:
- versioned_source
- release_notes
if: |
inputs.release_notes == true &&
(
github.event.action != 'closed' ||
github.event.pull_request.merged == true
)
defaults:
run:
working-directory: .
shell: bash --noprofile --norc -eo pipefail -x {0}
permissions: {}
env:
GH_DEBUG: "true"
GH_PAGER: cat
GH_PROMPT_DISABLED: "true"
GH_REPO: ${{ github.repository }}
steps:
- name: Generate GitHub App installation token
uses: tibdex/github-app-token@3beb63f4bd073e61482598c45c71c1019b59b73a
if: inputs.app_id
id: gh_app_token
with:
app_id: ${{ inputs.app_id }}
installation_retrieval_mode: organization
installation_retrieval_payload: ${{ github.repository_owner }}
private_key: ${{ secrets.GH_APP_PRIVATE_KEY }}
permissions: |-
{
"contents": "write",
"issues": "read",
"metadata": "read",
"pull_requests": "write"
}
- uses: peter-evans/find-comment@3eae4d37986fb5a8592848f6a574fdf654e61f9e
id: find_comment
if: needs.release_notes.outputs.comment != ''
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: flowzone-app[bot]
body-includes: "#release-notes"
token: ${{ steps.gh_app_token.outputs.token || secrets.FLOWZONE_TOKEN }}
- uses: peter-evans/find-comment@3eae4d37986fb5a8592848f6a574fdf654e61f9e
id: find_edited_comment
if: needs.release_notes.outputs.comment != ''
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: flowzone-app[bot]
body-regex: \* \[only keep the important and rephrase(, leaving this in place will avoid posting release notes)?\]
token: ${{ steps.gh_app_token.outputs.token || secrets.FLOWZONE_TOKEN }}
- uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043
if: |
needs.release_notes.outputs.comment != '' &&
(
(
steps.find_comment.outputs.comment-id == '' &&
steps.find_edited_comment.outputs.comment-id == ''
) ||
(
steps.find_comment.outputs.comment-id != '' &&
steps.find_edited_comment.outputs.comment-id != ''
)
)
with:
comment-id: ${{ steps.find_comment.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
${{ needs.release_notes.outputs.comment }}
edit-mode: replace
token: ${{ steps.gh_app_token.outputs.token || secrets.FLOWZONE_TOKEN }}
reactions: eyes
- name: Get and format timestamp
id: timestamp
env:
FORMAT: "%Y-%m-%d-%H%M%S"
run: |
echo "datetime=$(date +"${FORMAT}")" >> $GITHUB_OUTPUT
if: |
github.event.pull_request.merged &&
needs.versioned_source.outputs.commit_sha != ''
- name: Create tag object
id: create_tag
env:
GH_TOKEN: ${{ steps.gh_app_token.outputs.token || secrets.FLOWZONE_TOKEN }}
TAG: production-${{ steps.timestamp.outputs.datetime }}
MESSAGE: production-${{ steps.timestamp.outputs.datetime }}
SHA: ${{ needs.versioned_source.outputs.commit_sha }}
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea
with:
github-token: ${{ steps.gh_app_token.outputs.token || secrets.FLOWZONE_TOKEN }}
result-encoding: json
script: |
const { data: tag } = await github.rest.git.createTag({
...context.repo,
tag: process.env.TAG,
message: process.env.MESSAGE,
object: process.env.SHA,
type: 'commit'
});
core.setOutput('sha', tag.sha);
return tag;
if: |
github.event.pull_request.merged &&
needs.versioned_source.outputs.commit_sha != ''
- name: Create git reference
env:
GH_TOKEN: ${{ steps.gh_app_token.outputs.token || secrets.FLOWZONE_TOKEN }}
REF: refs/tags/production-${{ steps.timestamp.outputs.datetime }}
SHA: ${{ steps.create_tag.outputs.sha }}
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea
with:
github-token: ${{ steps.gh_app_token.outputs.token || secrets.FLOWZONE_TOKEN }}
result-encoding: json
script: |
const { data: ref } = await github.rest.git.createRef({
...context.repo,
ref: process.env.REF,
sha: process.env.SHA
});
return ref;
if: |
github.event.pull_request.merged &&
steps.create_tag.outputs.sha
- uses: zulip/github-actions-zulip/send-message@e4c8f27c732ba9bd98ac6be0583096dea82feea5
id: zulip_send
if: |
github.event.pull_request.merged == true &&
vars.ZULIP_STREAM != '' &&
vars.ZULIP_TOPIC != '' &&
vars.ZULIP_BOT_EMAIL != '' &&
vars.ZULIP_API_URL != '' &&
steps.find_edited_comment.outcome == 'success' &&
steps.find_edited_comment.outputs.comment-id == ''
continue-on-error: true
with:
api-key: ${{ secrets.ZULIP_API_KEY }}
email: ${{ vars.ZULIP_BOT_EMAIL }}
organization-url: ${{ vars.ZULIP_API_URL }}
to: ${{ vars.ZULIP_STREAM }}
type: stream