-
Notifications
You must be signed in to change notification settings - Fork 6
1349 lines (1187 loc) · 56.1 KB
/
create-release.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
name: Create Release
on:
schedule:
- cron: '*/30 * * * *' # every 30 minutes
push:
branches:
- main
workflow_dispatch:
inputs:
version:
description: 'Version of the release to cut (e.g. 1.2.3). No leading v'
required: false
force:
description: 'Release stack even if change validator does not detect changes, or a package is removed'
required: true
type: choice
default: 'false'
options:
- 'true'
- 'false'
concurrency: release
env:
STACKS_FILEPATH: "stacks/images.json"
PATCHED_USNS_FILENAME: "patched-usns.json"
jobs:
preparation:
name: Preparation
runs-on: ubuntu-22.04
outputs:
stacks_added: ${{ steps.get-stacks.outputs.stacks_added }}
stacks: ${{ steps.get-stacks.outputs.stacks }}
support_usns: ${{ steps.polling-os-type.outputs.support_usns }}
architectures: ${{ steps.lookup.outputs.platforms }}
archs_added: ${{ steps.lookup.outputs.platforms_added }}
polling_type: ${{ steps.polling-os-type.outputs.polling_type }}
github_repo_name: ${{ steps.repo.outputs.github_repo_name }}
registry_repo_name: ${{ steps.repo.outputs.registry_repo_name }}
repo_owner: ${{ steps.repo.outputs.repo_owner }}
default_stack_dir: ${{ steps.lookup.outputs.default_stack_dir }}
stack_files_dir: ${{ steps.get-stacks.outputs.stack_files_dir }}
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
fetch-depth: 0 # gets full history
- name: Get stacks images
id: get-stacks
run: |
if [[ -f ${{ env.STACKS_FILEPATH }} ]]; then
current_stacks=$(jq '[.images[] |
. +
{
"create_build_image": (.create_build_image // false),
"is_new": true
}]' ${{ env.STACKS_FILEPATH }} )
stack_files_dir="$(dirname "${{ env.STACKS_FILEPATH }}")"
git show $(git describe --tags --abbrev=0):"${{ env.STACKS_FILEPATH }}" > ./previous_images.json
if [ -f "./previous_images.json" ]; then
previous_stacks=$(jq '[.images[] |
. +
{
"create_build_image": (.create_build_image // false),
"is_new": false
}]' "./previous_images.json" )
else
previous_stacks="[]"
fi
stacks=$(echo "$current_stacks" | jq -c --argjson prev "$previous_stacks" '
map(
. as $curr |
($prev[] | select(.name == $curr.name)) // $curr
)
')
else
stacks=$(
cat <<EOF
[
{
"name": "default",
"config_dir": "stack",
"output_dir": "build",
"build_image": "build",
"build_receipt_filename": "build-receipt.cyclonedx.json",
"run_image": "run",
"run_receipt_filename": "run-receipt.cyclonedx.json",
"create_build_image": true,
"is_new": false
}
]
EOF
)
stack_files_dir="stack"
fi
echo "stack_files_dir=$stack_files_dir" >> "$GITHUB_OUTPUT"
## Filter stacks array to include the minimum number of attributes
stacks=$(echo "$stacks" | jq 'map({
name,
config_dir,
output_dir,
build_image,
build_receipt_filename,
run_image,
run_receipt_filename,
create_build_image,
base_build_container_image,
base_run_container_image,
is_new
})')
stacks=$(jq -c <<< "$stacks" )
printf "stacks=%s\n" "${stacks}" >> "$GITHUB_OUTPUT"
- name: Polling OS type
id: polling-os-type
run: |
support_usns=true
if [[ -f ${{ env.STACKS_FILEPATH }} ]]; then
support_usns=$( jq '.support_usns' ${{ env.STACKS_FILEPATH }} )
fi
if [ $support_usns == true ]; then
echo "polling_type=usn" >> "$GITHUB_OUTPUT"
else
echo "polling_type=hash" >> "$GITHUB_OUTPUT"
fi
echo "support_usns=${support_usns}" >> "$GITHUB_OUTPUT"
- name: Get Repository Name
id: repo
run: |
full=${{ github.repository }}
# Strip off the org and slash from repo name
# paketo-buildpacks/jammy-base-stack --> jammy-base-stack
repo=$(echo "${full}" | sed 's/^.*\///')
echo "github_repo_name=${repo}" >> "$GITHUB_OUTPUT"
# Strip off 'stack' suffix from repo name
# paketo-buildpacks/jammy-base-stack --> jammy-base
registry_repo="${repo//-stack/}"
echo "registry_repo_name=${registry_repo}" >> "$GITHUB_OUTPUT"
# translates 'paketo-buildpacks' to 'paketobuildpacks'
repo_owner="${GITHUB_REPOSITORY_OWNER/-/}"
printf "repo_owner=%s\n" "${repo_owner}" >> "$GITHUB_OUTPUT"
- name: Lookup Supported Architectures
id: lookup
run: |
#! /usr/bin/env bash
set -euo pipefail
shopt -s inherit_errexit
# install yj to parse TOML
curl -L $(curl -sL https://api.github.com/repos/sclevine/yj/releases/latest | jq -r '.assets[] | select(.name=="yj-linux-amd64").browser_download_url') -o yj
chmod +x yj
default_stack_dir=$(echo '${{ steps.get-stacks.outputs.stacks }}' | jq -r '.[] | select(.name=="default") | .config_dir')
echo "default_stack_dir=${default_stack_dir}" >> "$GITHUB_OUTPUT"
current_platforms="$(cat "$default_stack_dir/stack.toml" | ./yj -tj | jq -c '[.platforms[] | { name: sub("linux/"; "") , is_new: true }]')"
# get previous platforms
git show $(git describe --tags --abbrev=0):"$default_stack_dir/stack.toml" > ./previous_stack.toml
previous_platforms="$(cat ./previous_stack.toml | ./yj -tj | jq -c '[.platforms[] | { name: sub("linux/"; "") , is_new: false }]')"
platforms=$(echo "$current_platforms" | jq -c --argjson prev "$previous_platforms" '
map(
. as $curr |
($prev[] | select(.name == $curr.name)) // $curr
)
')
echo "platforms=${platforms}" >> "$GITHUB_OUTPUT"
# The following job is specific to Ubuntu images. It checks for new
# USNs (Ubuntu Security Notices) and triggers the flow to create
# a new release with the latest images that have the USNs patched.
poll_usns:
name: Poll USNs
runs-on: ubuntu-22.04
needs: [preparation]
if: ${{ needs.preparation.outputs.polling_type == 'usn' }}
strategy:
matrix:
stacks: ${{ fromJSON(needs.preparation.outputs.stacks) }}
arch: ${{ fromJSON(needs.preparation.outputs.architectures) }}
outputs:
usns: ${{ steps.new_usns.outputs.usns }}
steps:
- name: Generate receipt asset patterns
id: receipt_pattern
run: |
if [ "${{ matrix.arch.name }}" = "amd64" ]; then
if [ ${{ matrix.stacks.create_build_image }} == true ]; then
echo "build=${{ needs.preparation.outputs.github_repo_name }}-\\d+\\.\\d+(\\.\\d+)?-${{ matrix.stacks.build_receipt_filename }}" >> "$GITHUB_OUTPUT"
fi
echo "run=${{ needs.preparation.outputs.github_repo_name }}-\\d+\\.\\d+(\\.\\d+)?-${{ matrix.stacks.run_receipt_filename }}" >> "$GITHUB_OUTPUT"
else
if [ ${{ matrix.stacks.create_build_image }} == true ]; then
echo "build=${{ matrix.arch.name }}-${{ matrix.stacks.build_receipt_filename }}" >> "$GITHUB_OUTPUT"
fi
echo "run=${{ matrix.arch.name }}-${{ matrix.stacks.run_receipt_filename }}" >> "$GITHUB_OUTPUT"
fi
- name: Write Empty Previous Receipts
if: ${{ matrix.arch.is_new == true || matrix.stacks.is_new == true }}
run: |
if [ ${{ matrix.stacks.create_build_image }} == true ]; then
if [ ! -f "./${{ matrix.arch.name }}-previous-build-receipt-${{ matrix.stacks.name }}" ]; then
echo '{"components":[]}' > "./${{ matrix.arch.name }}-previous-build-receipt-${{ matrix.stacks.name }}"
fi
fi
if [ ! -f "./${{ matrix.arch.name }}-previous-run-receipt-${{ matrix.stacks.name }}" ]; then
echo '{"components":[]}' > "./${{ matrix.arch.name }}-previous-run-receipt-${{ matrix.stacks.name }}"
fi
- name: Check for Previous Releases
id: check_previous
run: |
gh auth status
# shellcheck disable=SC2046
if [ $(gh api "/repos/${{ github.repository }}/releases" | jq -r 'length') -eq 0 ]; then
echo "exists=false" >> "$GITHUB_OUTPUT"
exit 0
fi
echo "exists=true" >> "$GITHUB_OUTPUT"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Find and Download Previous Build Receipt
if: ${{ matrix.arch.is_new == false && matrix.stacks.is_new == false && steps.check_previous.outputs.exists == 'true' }}
id: previous_build
uses: paketo-buildpacks/github-config/actions/release/find-and-download-asset@main
with:
asset_pattern: "${{ steps.receipt_pattern.outputs.build }}"
search_depth: 1
repo: ${{ github.repository }}
output_path: "/github/workspace/${{ matrix.arch.name }}-previous-build-receipt-${{ matrix.stacks.name }}"
token: ${{ secrets.PAKETO_BOT_GITHUB_TOKEN }}
strict: true
- name: Find and Download Previous Run Receipt
if: ${{ matrix.arch.is_new == false && matrix.stacks.is_new == false && steps.check_previous.outputs.exists == 'true' }}
id: previous_run
uses: paketo-buildpacks/github-config/actions/release/find-and-download-asset@main
with:
asset_pattern: "${{ steps.receipt_pattern.outputs.run }}"
search_depth: 1
repo: ${{ github.repository }}
output_path: "/github/workspace/${{ matrix.arch.name }}-previous-run-receipt-${{ matrix.stacks.name }}"
token: ${{ secrets.PAKETO_BOT_GITHUB_TOKEN }}
strict: true
- name: Get Package List
id: packages
if: ${{ steps.previous_build.outputs.output_path != '' && steps.previous_run.outputs.output_path != '' }}
uses: paketo-buildpacks/github-config/actions/stack/generate-package-list@main
with:
build_receipt: "${{ github.workspace }}/${{ matrix.arch.name }}-previous-build-receipt-${{ matrix.stacks.name }}"
run_receipt: "${{ github.workspace }}/${{ matrix.arch.name }}-previous-run-receipt-${{ matrix.stacks.name }}"
- name: Generate USNs download asset pattern
id: usn_download_pattern
run: |
arch_prefix=""
if [ "${{ matrix.arch.name }}" = "amd64" ]; then
arch_prefix=""
else
arch_prefix="${{ matrix.arch.name }}"
fi
stack_name_prefix=""
if [ "${{ matrix.stacks.name }}" = "default" ]; then
stack_name_prefix=""
else
stack_name_prefix="${{ matrix.stacks.name }}"
fi
pattern=$(echo '["\\d+.\\d+(.\\d+)?","'"$stack_name_prefix"'", "'"$arch_prefix"'", "${{ env.PATCHED_USNS_FILENAME }}"]' | jq -r 'map(select(length > 0)) | join("-")')
echo "pattern=$pattern" >> "$GITHUB_OUTPUT"
- name: Find and Download Previous Patched USNs
id: download_patched
uses: paketo-buildpacks/github-config/actions/release/find-and-download-asset@main
with:
asset_pattern: "${{ steps.usn_download_pattern.outputs.pattern }}"
search_depth: "-1" # Search all releases
repo: ${{ github.repository }}
output_path: "/github/workspace/${{ matrix.arch.name }}-${{ matrix.stacks.name }}-${{ env.PATCHED_USNS_FILENAME }}-previous"
token: ${{ secrets.PAKETO_BOT_GITHUB_TOKEN }}
- name: Output Patched USNs as JSON String
id: patched
if: ${{ steps.download_patched.outputs.output_path != '' }}
run: |
patched=$(jq --compact-output . < "${GITHUB_WORKSPACE}/${{ matrix.arch.name }}-${{ matrix.stacks.name }}-${{ env.PATCHED_USNS_FILENAME }}-previous")
printf "patched=%s\n" "${patched}" >> "$GITHUB_OUTPUT"
- name: Get Stack Distribution Name
id: distro
run: |
# Extract distro from repo name:
# paketo-buildpacks/jammy-tiny-stack --> jammy
distro="$(echo "${{ github.repository }}" | sed 's/^.*\///' | sed 's/\-.*$//')"
echo "Ubuntu distribution: ${distro}"
printf "distro=%s\n" "${distro}" >> "$GITHUB_OUTPUT"
- name: Get New USNs
id: usns
uses: paketo-buildpacks/github-config/actions/stack/get-usns@main
with:
distribution: ${{ steps.distro.outputs.distro }}
packages: ${{ steps.packages.outputs.packages }}
last_usns: ${{ steps.patched.outputs.patched }}
- name: Write USNs File
id: write_usns
run: |
jq . <<< "${USNS}" > "./${USNS_PATH}"
echo "usns=./${USNS_PATH}" >> "$GITHUB_OUTPUT"
env:
USNS_PATH: "${{ matrix.arch.name }}-${{ matrix.stacks.name }}-${{ env.PATCHED_USNS_FILENAME }}"
USNS: ${{ steps.usns.outputs.usns }}
- name: Upload USNs file
uses: actions/upload-artifact@v4
with:
name: "${{ matrix.arch.name }}-${{ matrix.stacks.name }}-${{ env.PATCHED_USNS_FILENAME }}"
path: "${{ matrix.arch.name }}-${{ matrix.stacks.name }}-${{ env.PATCHED_USNS_FILENAME }}"
- name: Are any new USNs
id: new_usns
run: |
new_usns_length=$(cat "${{ matrix.arch.name }}-${{ matrix.stacks.name }}-${{ env.PATCHED_USNS_FILENAME }}" | jq 'length')
if [ "$new_usns_length" -ge 0 ]; then
echo "usns=true" >> "$GITHUB_OUTPUT"
fi
# The job below checks if new images are available on the registry
# based on the sha256 checksum. If yes, it triggers the flow
# to create a new release with the latest images
poll_images:
name: Poll Images based on the hash code
runs-on: ubuntu-22.04
if: ${{ needs.preparation.outputs.polling_type == 'hash' }}
needs: preparation
strategy:
matrix:
stacks: ${{ fromJSON(needs.preparation.outputs.stacks) }}
arch: ${{ fromJSON(needs.preparation.outputs.architectures) }}
outputs:
images_need_update: ${{ steps.compare_previous_and_current_sha256_hash_codes.outputs.images_need_update }}
steps:
- name: Generate hash code asset patterns
id: hashcode_pattern
run: |
if [ "${{ matrix.arch.name }}" = "amd64" ]; then
echo "build=${{ needs.preparation.outputs.github_repo_name }}-\\d+.\\d+(.\\d+)?-${{ matrix.stacks.build_image }}.oci.sha256" >> "$GITHUB_OUTPUT"
echo "run=${{ needs.preparation.outputs.github_repo_name }}-\\d+.\\d+(.\\d+)?-${{ matrix.stacks.run_image }}.oci.sha256" >> "$GITHUB_OUTPUT"
else
echo "build=-${{ matrix.arch.name }}-${{ matrix.stacks.build_image }}.oci.sha256" >> "$GITHUB_OUTPUT"
echo "run=-${{ matrix.arch.name }}-${{ matrix.stacks.run_image }}.oci.sha256" >> "$GITHUB_OUTPUT"
fi
- name: Find and Download Previous build image hash code of stack ${{ matrix.stacks.build_image }}
if: ${{ matrix.stacks.create_build_image == true }}
uses: paketo-buildpacks/github-config/actions/release/find-and-download-asset@main
with:
asset_pattern: "${{ steps.hashcode_pattern.outputs.build }}"
search_depth: 1
repo: ${{ github.repository }}
output_path: "./previous_${{ matrix.arch.name }}-${{ matrix.stacks.build_image }}.oci.sha256"
token: ${{ secrets.PAKETO_BOT_GITHUB_TOKEN }}
- name: Find and Download Previous run image hash code of stack ${{ matrix.stacks.run_image }}
uses: paketo-buildpacks/github-config/actions/release/find-and-download-asset@main
with:
asset_pattern: "${{ steps.hashcode_pattern.outputs.run }}"
search_depth: 1
repo: ${{ github.repository }}
output_path: "./previous_${{ matrix.arch.name }}-${{ matrix.stacks.run_image }}.oci.sha256"
token: ${{ secrets.PAKETO_BOT_GITHUB_TOKEN }}
- name: Get current build image hash code of ${{ matrix.stacks.name }} stack with arch ${{ matrix.arch.name }}
if: ${{ matrix.stacks.create_build_image == true }}
run: |
skopeo inspect --format "{{.Digest}}" ${{ matrix.stacks.base_build_container_image }} > ./hash-code-current-build-image-${{ matrix.arch.name }}-${{ matrix.stacks.name }}
- name: Get current run image hash code of ${{ matrix.stacks.name }} stack with arch ${{ matrix.arch.name }}
run: |
skopeo inspect --format "{{.Digest}}" ${{ matrix.stacks.base_run_container_image }} > ./hash-code-current-run-image-${{ matrix.arch.name }}-${{ matrix.stacks.name }}
- name: Create empty image hash codes
run: |
if [ ! -f "./hash-code-current-build-image-${{ matrix.arch.name }}-${{ matrix.stacks.name }}" ]; then
touch "./hash-code-current-build-image-${{ matrix.arch.name }}-${{ matrix.stacks.name }}"
fi
if [ ! -f "./hash-code-current-run-image-${{ matrix.arch.name }}-${{ matrix.stacks.name }}" ]; then
touch "./hash-code-current-run-image-${{ matrix.arch.name }}-${{ matrix.stacks.name }}"
fi
- name: Upload run image hash code
uses: actions/upload-artifact@v4
with:
name: hash-code-current-run-image-${{ matrix.arch.name }}-${{ matrix.stacks.name }}
path: hash-code-current-run-image-${{ matrix.arch.name }}-${{ matrix.stacks.name }}
if-no-files-found: error
- name: Upload build image hash code
if: ${{ matrix.stacks.create_build_image == true }}
uses: actions/upload-artifact@v4
with:
name: hash-code-current-build-image-${{ matrix.arch.name }}-${{ matrix.stacks.name }}
path: hash-code-current-build-image-${{ matrix.arch.name }}-${{ matrix.stacks.name }}
if-no-files-found: error
- name: Compare previous and current hash codes
id: compare_previous_and_current_sha256_hash_codes
run: |
if [ "$(cat previous_${{ matrix.arch.name }}-${{ matrix.stacks.run_image }}.oci.sha256)" != "$(cat hash-code-current-run-image-${{ matrix.arch.name }}-${{ matrix.stacks.name }})" ]; then
echo "images_need_update=true" >> "$GITHUB_OUTPUT"
fi
if [ "${{ matrix.stacks.create_build_image }}" == "true" ]; then
if [ "$(cat previous_${{ matrix.arch.name }}-${{ matrix.stacks.build_image }}.oci.sha256)" != "$(cat hash-code-current-build-image-${{ matrix.arch.name }}-${{ matrix.stacks.name }})" ]; then
echo "images_need_update=true" >> "$GITHUB_OUTPUT"
fi
fi
# If there is no change on the usns, and there is no change on the image hash codes
# and the event is schedule, then there is no need to run below workflow as nothing has changed
stack_files_changed:
name: Determine If Stack Files Changed
runs-on: ubuntu-22.04
needs: [ preparation, poll_usns, poll_images ]
if: ${{
!failure() && !cancelled() &&
!(
(needs.poll_images.outputs.images_need_update == null &&
needs.poll_usns.outputs.usns == null ) &&
github.event_name == 'schedule'
) }}
outputs:
stack_files_changed: ${{ steps.compare.outputs.stack_files_changed }}
steps:
- name: Checkout With History
uses: actions/checkout@v4
with:
fetch-depth: 0 # gets full history
- name: Compare With Previous Release
id: compare
run: |
# shellcheck disable=SC2046
changed=$(git diff --name-only $(git describe --tags --abbrev=0) -- "${{ needs.preparation.outputs.stack_files_dir }}")
if [ -z "${changed}" ]
then
echo "No relevant files changed since previous release."
echo "stack_files_changed=false" >> "$GITHUB_OUTPUT"
else
echo "Relevant files have changed since previous release."
echo "${changed}"
echo "stack_files_changed=true" >> "$GITHUB_OUTPUT"
fi
usns_or_sha_changed:
name: USNs or SHAs have changed
runs-on: ubuntu-22.04
outputs:
changed: ${{ steps.usns_or_sha_changed.outputs.changed }}
needs: [ preparation, poll_usns, poll_images ]
if: ${{ !failure() && !cancelled() }}
steps:
- name: Check USNs or SHAs have changed
id: usns_or_sha_changed
run: |
if [ '${{ needs.poll_images.result }}' != 'skipped' ]; then
echo "Poll images job did not skip"
if [ '${{ needs.poll_images.outputs.images_need_update }}' = "true" ]; then
echo "SHAs have changed"
echo "changed=true" >> "$GITHUB_OUTPUT"
else
echo "SHAs have not changed"
echo "changed=false" >> "$GITHUB_OUTPUT"
fi
exit 0
fi
if [ '${{ needs.poll_usns.result }}' != 'skipped' ]; then
echo "Poll USNs did not skip"
if [ '${{ needs.poll_usns.outputs.usns }}' = "true" ]; then
echo "USNs have changed"
echo "changed=true" >> "$GITHUB_OUTPUT"
else
echo "USNs have not changed"
echo "changed=false" >> "$GITHUB_OUTPUT"
fi
exit 0
fi
create_stack:
name: Create Stack
needs: [ preparation, usns_or_sha_changed ]
# If there is no change on the usns, and there is no change on the image hash codes
# and the event is schedule, then there is no need to run below workflow as nothing has changed
if: ${{ !failure() && !cancelled() && !( needs.usns_or_sha_changed.outputs.changed == 'false' && github.event_name == 'schedule') }}
runs-on: ubuntu-22.04
strategy:
matrix:
stacks: ${{ fromJSON(needs.preparation.outputs.stacks) }}
steps:
- name: Checkout
uses: actions/checkout@v4
# https://github.com/docker/setup-qemu-action
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Create stack ${{ matrix.stacks.name }}
id: create-stack
run: |
scripts/create.sh --stack-dir ${{ matrix.stacks.config_dir }} \
--build-dir ${{ matrix.stacks.output_dir }}
- name: Generate Package Receipts
id: receipts
run: |
scripts/receipts.sh --build-image "${{ matrix.stacks.output_dir }}/build.oci" \
--run-image "${{ matrix.stacks.output_dir }}/run.oci" \
--build-receipt current-build-receipt-${{ matrix.stacks.name }} \
--run-receipt current-run-receipt-${{ matrix.stacks.name }}
- name: Upload run image
uses: actions/upload-artifact@v4
with:
name: current-run-image-${{ matrix.stacks.name }}
path: "${{ matrix.stacks.output_dir }}/run.oci"
if-no-files-found: error
- name: Upload build image
if: ${{ matrix.stacks.create_build_image == true }}
uses: actions/upload-artifact@v4
with:
name: current-build-image-${{ matrix.stacks.name }}
path: "${{ matrix.stacks.output_dir }}/build.oci"
if-no-files-found: error
- name: Upload Build receipt
if: ${{ matrix.stacks.create_build_image == true }}
uses: actions/upload-artifact@v4
with:
name: current-build-receipt-${{ matrix.stacks.name }}
path: "*current-build-receipt-${{ matrix.stacks.name }}"
if-no-files-found: error
- name: Upload Run receipt
uses: actions/upload-artifact@v4
with:
name: current-run-receipt-${{ matrix.stacks.name }}
path: "*current-run-receipt-${{ matrix.stacks.name }}"
if-no-files-found: error
diff:
name: Diff Packages
env:
BUILD_DIFF_ADDED_FILENAME: "build-diff-added.json"
BUILD_DIFF_MODIFIED_FILENAME: "build-diff-modified.json"
BUILD_DIFF_REMOVED_FILENAME: "build-diff-removed.json"
RUN_DIFF_ADDED_FILENAME: "run-diff-added.json"
RUN_DIFF_MODIFIED_FILENAME: "run-diff-modified.json"
RUN_DIFF_REMOVED_FILENAME: "run-diff-removed.json"
if: ${{ !cancelled() && !failure() && needs.create_stack.result != 'skipped' }}
outputs:
removed_with_force: ${{ steps.removed_with_force.outputs.packages_removed }}
needs: [ create_stack, preparation ]
runs-on: ubuntu-22.04
strategy:
matrix:
stacks: ${{ fromJSON(needs.preparation.outputs.stacks) }}
arch: ${{ fromJSON(needs.preparation.outputs.architectures) }}
steps:
- name: Checkout With History
uses: actions/checkout@v4
with:
fetch-depth: 0 # gets full history
- name: Download Current Receipt(s)
uses: actions/download-artifact@v4
with:
pattern: current-*-receipt-${{ matrix.stacks.name }}
path: receipt-files
- name: Move/Rename Build receipt properly
if: ${{ matrix.stacks.create_build_image == true }}
run: |
arch_prefix="${{ matrix.arch.name }}-"
if [[ "${{ matrix.arch.name }}" == "amd64" ]]; then
arch_prefix=""
fi
mv receipt-files/current-build-receipt-${{ matrix.stacks.name }}/${arch_prefix}current-build-receipt-${{ matrix.stacks.name }} ./${{ matrix.arch.name }}-current-build-receipt-${{ matrix.stacks.name }}
- name: Move/Rename Run receipt properly
run: |
arch_prefix="${{ matrix.arch.name }}-"
if [[ "${{ matrix.arch.name }}" == "amd64" ]]; then
arch_prefix=""
fi
mv receipt-files/current-run-receipt-${{ matrix.stacks.name }}/${arch_prefix}current-run-receipt-${{ matrix.stacks.name }} ./${{ matrix.arch.name }}-current-run-receipt-${{ matrix.stacks.name }}
- name: Check for Previous Releases
id: check_previous
run: |
gh auth status
# shellcheck disable=SC2046
if [ $(gh api "/repos/${{ github.repository }}/releases" | jq -r 'length') -eq 0 ]; then
echo "exists=false" >> "$GITHUB_OUTPUT"
exit 0
fi
echo "exists=true" >> "$GITHUB_OUTPUT"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Write Empty Previous Receipts
if: ${{ steps.check_previous.outputs.exists == 'false' || matrix.arch.is_new == true || matrix.stacks.is_new == true }}
run: |
if [ ${{ matrix.stacks.create_build_image }} == true ]; then
if [ ! -f "./${{ matrix.arch.name }}-previous-build-receipt-${{ matrix.stacks.name }}" ]; then
echo '{"components":[]}' > "./${{ matrix.arch.name }}-previous-build-receipt-${{ matrix.stacks.name }}"
fi
fi
if [ ! -f "./${{ matrix.arch.name }}-previous-run-receipt-${{ matrix.stacks.name }}" ]; then
echo '{"components":[]}' > "./${{ matrix.arch.name }}-previous-run-receipt-${{ matrix.stacks.name }}"
fi
- name: Previous receipt download filename pattern
if: ${{ steps.check_previous.outputs.exists == 'true' && matrix.arch.is_new == false && matrix.stacks.is_new == false }}
id: previous_receipt_download_pattern
run: |
if [ "${{ matrix.arch.name }}" = "amd64" ]; then
if [ ${{ matrix.stacks.create_build_image }} == true ]; then
echo "build_filename=${{ needs.preparation.outputs.github_repo_name }}-\\d+\\.\\d+(\\.\\d+)?-${{ matrix.stacks.build_receipt_filename }}" >> "$GITHUB_OUTPUT"
fi
echo "run_filename=${{ needs.preparation.outputs.github_repo_name }}-\\d+\\.\\d+(\\.\\d+)?-${{ matrix.stacks.run_receipt_filename }}" >> "$GITHUB_OUTPUT"
else
if [ ${{ matrix.stacks.create_build_image }} == true ]; then
echo "build_filename=${{ matrix.arch.name }}-${{ matrix.stacks.build_receipt_filename }}" >> "$GITHUB_OUTPUT"
fi
echo "run_filename=${{ matrix.arch.name }}-${{ matrix.stacks.run_receipt_filename }}" >> "$GITHUB_OUTPUT"
fi
- name: Find and Download Previous Build Receipt
if: ${{ matrix.stacks.create_build_image == true && steps.check_previous.outputs.exists == 'true' && matrix.arch.is_new == false && matrix.stacks.is_new == false }}
uses: paketo-buildpacks/github-config/actions/release/find-and-download-asset@main
with:
asset_pattern: "${{ steps.previous_receipt_download_pattern.outputs.build_filename }}"
search_depth: 1
repo: ${{ github.repository }}
output_path: "/github/workspace/${{ matrix.arch.name }}-previous-build-receipt-${{ matrix.stacks.name }}"
token: ${{ secrets.PAKETO_BOT_GITHUB_TOKEN }}
- name: Find and Download Previous Run Receipt
if: ${{ steps.check_previous.outputs.exists == 'true' && matrix.arch.is_new == false && matrix.stacks.is_new == false }}
uses: paketo-buildpacks/github-config/actions/release/find-and-download-asset@main
with:
asset_pattern: "${{ steps.previous_receipt_download_pattern.outputs.run_filename }}"
search_depth: 1
repo: ${{ github.repository }}
output_path: "/github/workspace/${{ matrix.arch.name }}-previous-run-receipt-${{ matrix.stacks.name }}"
token: ${{ secrets.PAKETO_BOT_GITHUB_TOKEN }}
- name: Compare Build Packages
id: build_diff
if: ${{ matrix.stacks.create_build_image == true }}
uses: paketo-buildpacks/github-config/actions/stack/diff-package-receipts@main
with:
previous: "/github/workspace/${{ matrix.arch.name }}-previous-build-receipt-${{ matrix.stacks.name }}"
current: "/github/workspace/${{ matrix.arch.name }}-current-build-receipt-${{ matrix.stacks.name }}"
added_diff_file: "/github/workspace/${{ env.BUILD_DIFF_ADDED_FILENAME }}"
modified_diff_file: "/github/workspace/${{ env.BUILD_DIFF_MODIFIED_FILENAME }}"
removed_diff_file: "/github/workspace/${{ env.BUILD_DIFF_REMOVED_FILENAME }}"
- name: Compare Run Packages
id: run_diff
uses: paketo-buildpacks/github-config/actions/stack/diff-package-receipts@main
with:
previous: "/github/workspace/${{ matrix.arch.name }}-previous-run-receipt-${{ matrix.stacks.name }}"
current: "/github/workspace/${{ matrix.arch.name }}-current-run-receipt-${{ matrix.stacks.name }}"
added_diff_file: "/github/workspace/${{ env.RUN_DIFF_ADDED_FILENAME }}"
modified_diff_file: "/github/workspace/${{ env.RUN_DIFF_MODIFIED_FILENAME }}"
removed_diff_file: "/github/workspace/${{ env.RUN_DIFF_REMOVED_FILENAME }}"
- name: Fail If Packages Removed
id: removed_with_force
run: |
if [ "${{ matrix.stacks.create_build_image }}" == "true" ]; then
build=$(jq '. | length' "${BUILD_REMOVED}")
echo "Build packages removed: ${build}"
else
build=0
fi
run=$(jq '. | length' "${RUN_REMOVED}")
echo "Run packages removed: ${run}"
# only fail if packages are removed AND the release has not been forced
if ( [ "${build}" -gt 0 ] && [ "${{ matrix.stacks.create_build_image }}" == "true" ] ) || [ "${run}" -gt 0 ]; then
if [ "${{ github.event.inputs.force }}" != 'true' ]; then
echo "Packages removed without authorization. Stack cannot be released."
exit 1
else
echo "packages_removed=true" >> "$GITHUB_OUTPUT"
fi
fi
env:
BUILD_REMOVED: "${{ github.workspace }}/${{ env.BUILD_DIFF_REMOVED_FILENAME }}"
RUN_REMOVED: "${{ github.workspace }}/${{ env.RUN_DIFF_REMOVED_FILENAME }}"
- name: Create/Upload variable artifacts
id: variable_artifacts
run: |
diffs_dir="diff-${{ matrix.arch.name }}-${{ matrix.stacks.name }}"
mkdir -p "$diffs_dir"
if [ "${{ matrix.stacks.create_build_image }}" == "true" ]; then
cp "${{ github.workspace }}/${{ env.BUILD_DIFF_ADDED_FILENAME }}" "$diffs_dir/build_added"
cp "${{ github.workspace }}/${{ env.BUILD_DIFF_MODIFIED_FILENAME }}" "$diffs_dir/build_modified"
cp "${{ github.workspace }}/${{ env.BUILD_DIFF_REMOVED_FILENAME }}" "$diffs_dir/build_removed_with_force"
else
# We generate empty build diffs for the release notes action not to break
echo null > "${{ github.workspace }}/${{ env.BUILD_DIFF_ADDED_FILENAME }}"
echo null > "${{ github.workspace }}/${{ env.BUILD_DIFF_MODIFIED_FILENAME }}"
echo null > "${{ github.workspace }}/${{ env.BUILD_DIFF_REMOVED_FILENAME }}"
fi
cp "${{ github.workspace }}/${{ env.RUN_DIFF_ADDED_FILENAME }}" "$diffs_dir/run_added"
cp "${{ github.workspace }}/${{ env.RUN_DIFF_MODIFIED_FILENAME }}" "$diffs_dir/run_modified"
cp "${{ github.workspace }}/${{ env.RUN_DIFF_REMOVED_FILENAME }}" "$diffs_dir/run_removed_with_force"
- name: Upload diff-${{ matrix.arch.name }}-${{ matrix.stacks.name }}
uses: actions/upload-artifact@v4
with:
name: diff-${{ matrix.arch.name }}-${{ matrix.stacks.name }}
path: diff-${{ matrix.arch.name }}-${{ matrix.stacks.name }}
if-no-files-found: error
- name: Download USN File(s)
if: ${{ needs.preparation.outputs.polling_type == 'usn' }}
uses: actions/download-artifact@v4
with:
path: "patched-usns"
pattern: ${{ matrix.arch.name }}-*${{ env.PATCHED_USNS_FILENAME }}
merge-multiple: true
- name: Get USNs
id: get-usns
if: ${{ needs.preparation.outputs.polling_type == 'usn' }}
run: |
usns=$(cat "patched-usns/${{ matrix.arch.name }}-${{ matrix.stacks.name }}-${{ env.PATCHED_USNS_FILENAME }}" | jq -c )
echo "usns=$usns" >> "$GITHUB_OUTPUT"
- name: Get Repository Name
id: repo_name
run: |
full=${{ github.repository }}
# Strip off the org and slash from repo name
# paketo-buildpacks/repo-name --> repo-name
repo=$(echo "${full}" | sed 's/^.*\///')
echo "github_repo_name=${repo}" >> "$GITHUB_OUTPUT"
# Strip off 'stack' suffix from repo name
# some-name-stack --> some-name
registry_repo="${repo//-stack/}"
echo "registry_repo_name=${registry_repo}" >> "$GITHUB_OUTPUT"
- name: Increment Tag
if: github.event.inputs.version == ''
id: semver
uses: paketo-buildpacks/github-config/actions/tag/increment-tag@main
with:
allow_head_tagged: true
- name: Set Release Tag
id: tag
run: |
tag="${{ github.event.inputs.version }}"
if [ -z "${tag}" ]; then
tag="${{ steps.semver.outputs.tag }}"
fi
echo "tag=${tag}" >> "$GITHUB_OUTPUT"
- name: Get registry build and run image names
id: registry_names
run: |
if [ "${{ matrix.stacks.create_build_image }}" == "true" ]; then
echo "build_image=${{ needs.preparation.outputs.repo_owner }}/${{ matrix.stacks.build_image }}-${{ needs.preparation.outputs.registry_repo_name }}:${{ steps.tag.outputs.tag }}" >> "$GITHUB_OUTPUT"
else
echo "build_image=" >> "$GITHUB_OUTPUT"
fi
echo "run_image=${{ needs.preparation.outputs.repo_owner }}/${{ matrix.stacks.run_image }}-${{ needs.preparation.outputs.registry_repo_name }}:${{ steps.tag.outputs.tag }}" >> "$GITHUB_OUTPUT"
- name: Create Release Notes per Arch and per Stack
id: notes_arc_stack
uses: paketo-buildpacks/github-config/actions/stack/release-notes@main
with:
build_image: ${{ steps.registry_names.outputs.build_image }}
run_image: ${{ steps.registry_names.outputs.run_image }}
build_packages_added: "/github/workspace/${{ env.BUILD_DIFF_ADDED_FILENAME }}"
build_packages_modified: "/github/workspace/${{ env.BUILD_DIFF_MODIFIED_FILENAME }}"
build_packages_removed_with_force: "/github/workspace/${{ env.BUILD_DIFF_REMOVED_FILENAME }}"
run_packages_added: "/github/workspace/${{ env.RUN_DIFF_ADDED_FILENAME }}"
run_packages_modified: "/github/workspace/${{ env.RUN_DIFF_MODIFIED_FILENAME }}"
run_packages_removed_with_force: "/github/workspace/${{ env.RUN_DIFF_REMOVED_FILENAME }}"
supports_usns: ${{ needs.preparation.outputs.support_usns }}
patched_usns: ${{ needs.get-usns.outputs.usns }}
release_body_file: "${{ matrix.arch.name }}-${{ matrix.stacks.name }}-release-notes.md"
- name: Upload ${{ matrix.arch.name }} release notes file for stack ${{ matrix.stacks.name }}
uses: actions/upload-artifact@v4
with:
name: "${{ matrix.arch.name }}-${{ matrix.stacks.name }}-release-notes.md"
path: "${{ matrix.arch.name }}-${{ matrix.stacks.name }}-release-notes.md"
packages_changed:
name: Determine If Packages Changed
needs: [ diff, preparation ]
runs-on: ubuntu-22.04
if: ${{ !cancelled() && !failure() && needs.diff.result != 'skipped' }}
strategy:
matrix:
stacks: ${{ fromJSON(needs.preparation.outputs.stacks) }}
arch: ${{ fromJSON(needs.preparation.outputs.architectures) }}
outputs:
packages_changed: ${{ steps.compare.outputs.packages_changed }}
steps:
- name: Download diff-${{ matrix.arch.name }}-${{ matrix.stacks.name }}
uses: actions/download-artifact@v4
with:
name: diff-${{ matrix.arch.name }}-${{ matrix.stacks.name }}
- name: Set env diff variables
run: |
if [ "${{ matrix.stacks.create_build_image }}" == "true" ]; then
BUILD_ADDED=$(cat ./build_added)
BUILD_MODIFIED=$(cat ./build_modified)
echo "BUILD_ADDED=$BUILD_ADDED" >> $GITHUB_ENV
echo "BUILD_MODIFIED=$BUILD_MODIFIED" >> $GITHUB_ENV
else
echo "BUILD_ADDED=$BUILD_ADDED" >> $GITHUB_ENV
echo "BUILD_MODIFIED=$BUILD_MODIFIED" >> $GITHUB_ENV
fi
RUN_ADDED=$(cat ./run_added)
RUN_MODIFIED=$(cat ./run_modified)
echo "RUN_ADDED=$RUN_ADDED" >> $GITHUB_ENV
echo "RUN_MODIFIED=$RUN_MODIFIED" >> $GITHUB_ENV
- name: Compare With Previous Release
id: compare
run: |
# shellcheck disable=SC2153
if [ "${{ matrix.stacks.create_build_image }}" == "true" ]; then
build_added=$(cat ./build_added | jq 'length')
echo "Build packages added: ${build_added}"
# shellcheck disable=SC2153
build_modified=$(cat ./build_modified | jq 'length')
echo "Build packages modified: ${build_modified}"
fi
# shellcheck disable=SC2153
run_added=$(jq '. | length' <<< "${RUN_ADDED}")
echo "Run packages added: ${run_added}"
# shellcheck disable=SC2153
run_modified=$(jq '. | length' <<< "${RUN_MODIFIED}")
echo "Run packages modified: ${run_modified}"
if [ "${build_added:-0}" -eq 0 ] && [ "${build_modified:-0}" -eq 0 ] && [ "${run_added}" -eq 0 ] && [ "${run_modified}" -eq 0 ]; then
echo "No packages changed."
# We ommit setting "packages_changed" variable to false,
# as there is an edge case scenario overriding any true value due to parallelization
else
echo "Packages changed."
echo "packages_changed=true" >> "$GITHUB_OUTPUT"
fi
test:
name: Acceptance Test
needs: [ preparation, create_stack ]
if: ${{ !cancelled() && !failure() && needs.create_stack.result != 'skipped' }}
runs-on: ubuntu-22.04
steps:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: stable
- name: Checkout
uses: actions/checkout@v4
- name: Download Build Image(s)
uses: actions/download-artifact@v4
with:
pattern: current-build-image-*
- name: Download Run Image(s)
uses: actions/download-artifact@v4
with:
pattern: current-run-image-*
- name: Create OCI artifacts destination directory
run: |
echo '${{ needs.preparation.outputs.stacks }}' | jq -c '.[]' | while read -r stack; do
name=$(echo "$stack" | jq -r '.name')
output_dir=$(echo "$stack" | jq -r '.output_dir')
create_build_image=$(echo "$stack" | jq -r '.create_build_image')
mkdir -p $output_dir
mv "current-run-image-${name}/run.oci" "${output_dir}/run.oci"
if [ $create_build_image == 'true' ]; then
mv "current-build-image-${name}/build.oci" "${output_dir}/build.oci"
fi
done
- name: Run Acceptance Tests
run: ./scripts/test.sh --validate-stack-builds
release:
name: Release
runs-on: ubuntu-22.04
needs: [create_stack, diff, stack_files_changed, test, preparation, packages_changed]
if: ${{ always() && needs.diff.result == 'success' && needs.test.result == 'success' && ( needs.packages_changed.outputs.packages_changed == 'true' || needs.stack_files_changed.outputs.stack_files_changed == 'true' || github.event.inputs.force == 'true' ) }}
outputs:
tag: ${{ steps.tag.outputs.tag }}
steps:
- name: Print Release Reasoning
run: |
printf "Diff Packages: %s\n" "${{ needs.diff.result }}"
printf "Acceptance Tests: %s\n" "${{ needs.test.result }}"
printf "Packages Changed: %s\n" "${{ needs.packages_changed.outputs.packages_changed }}"
printf "Packages Removed With Force: %s\n" "${{ needs.diff.outputs.removed_with_force == 'true' }}"
printf "Stack Files Changed: %s\n" "${{ needs.stack_files_changed.outputs.stack_files_changed }}"
printf "Force Release: %s\n" "${{ github.event.inputs.force }}"
- name: Checkout With History
uses: actions/checkout@v4
with:
fetch-depth: 0 # gets full history
- name: Download current build image(s)
uses: actions/download-artifact@v4
with:
path: image-files
pattern: current-build-image-*
- name: Download current run image(s)
uses: actions/download-artifact@v4
with:
path: image-files
pattern: current-run-image-*
- name: Display Build and Run Images
run: ls image-files
- name: Download Build Receipt(s)
uses: actions/download-artifact@v4
with:
path: receipt-files
pattern: current-build-receipt-*
merge-multiple: true
- name: Download Run Receipt(s)
uses: actions/download-artifact@v4
with:
path: receipt-files
pattern: current-run-receipt-*
merge-multiple: true
- name: Display Receipts
run: ls receipt-files