Skip to content

Commit 5e45eca

Browse files
committed
opt to merge output for multi-platforms build into a single artifact
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
1 parent cf2bccf commit 5e45eca

File tree

6 files changed

+193
-17
lines changed

6 files changed

+193
-17
lines changed

.github/workflows/.test-bake.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,3 +543,77 @@ jobs:
543543
- registry: registry-1-stage.docker.io
544544
username: ${{ vars.DOCKERHUB_STAGE_USERNAME }}
545545
password: ${{ secrets.DOCKERHUB_STAGE_TOKEN }}
546+
547+
bake-local-nomerge:
548+
uses: ./.github/workflows/bake.yml
549+
permissions:
550+
contents: read
551+
id-token: write
552+
with:
553+
artifact-name: bake-nomerge-output
554+
artifact-upload: true
555+
artifact-merge: false
556+
context: test
557+
output: local
558+
sbom: true
559+
sign: ${{ github.event_name != 'pull_request' }}
560+
target: hello-cross
561+
562+
bake-local-nomerge-verify:
563+
uses: ./.github/workflows/verify.yml
564+
needs:
565+
- bake-local-nomerge
566+
with:
567+
builder-outputs: ${{ toJSON(needs.bake-local-nomerge.outputs) }}
568+
569+
bake-local-nomerge-outputs:
570+
runs-on: ubuntu-24.04
571+
needs:
572+
- bake-local-nomerge
573+
steps:
574+
-
575+
name: Builder outputs
576+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
577+
env:
578+
INPUT_BUILDER-OUTPUTS: ${{ toJSON(needs.bake-local-nomerge.outputs) }}
579+
with:
580+
script: |
581+
const builderOutputs = JSON.parse(core.getInput('builder-outputs'));
582+
core.info(JSON.stringify(builderOutputs, null, 2));
583+
584+
bake-local-single-nomerge:
585+
uses: ./.github/workflows/bake.yml
586+
permissions:
587+
contents: read
588+
id-token: write
589+
with:
590+
artifact-name: bake-single-nomerge-output
591+
artifact-upload: true
592+
artifact-merge: false
593+
context: test
594+
output: local
595+
sbom: true
596+
sign: ${{ github.event_name != 'pull_request' }}
597+
target: hello
598+
599+
bake-local-single-nomerge-verify:
600+
uses: ./.github/workflows/verify.yml
601+
needs:
602+
- bake-local-single-nomerge
603+
with:
604+
builder-outputs: ${{ toJSON(needs.bake-local-single-nomerge.outputs) }}
605+
606+
bake-local-single-nomerge-outputs:
607+
runs-on: ubuntu-24.04
608+
needs:
609+
- bake-local-single-nomerge
610+
steps:
611+
-
612+
name: Builder outputs
613+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
614+
env:
615+
INPUT_BUILDER-OUTPUTS: ${{ toJSON(needs.bake-local-single-nomerge.outputs) }}
616+
with:
617+
script: |
618+
const builderOutputs = JSON.parse(core.getInput('builder-outputs'));
619+
core.info(JSON.stringify(builderOutputs, null, 2));

.github/workflows/.test-build.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,3 +574,76 @@ jobs:
574574
- registry: registry-1-stage.docker.io
575575
username: ${{ vars.DOCKERHUB_STAGE_USERNAME }}
576576
password: ${{ secrets.DOCKERHUB_STAGE_TOKEN }}
577+
578+
build-local-nomerge:
579+
uses: ./.github/workflows/build.yml
580+
permissions:
581+
contents: read
582+
id-token: write
583+
with:
584+
artifact-name: build-nomerge-output
585+
artifact-upload: true
586+
artifact-merge: false
587+
file: test/hello.Dockerfile
588+
output: local
589+
platforms: linux/amd64,linux/arm64
590+
sbom: true
591+
sign: ${{ github.event_name != 'pull_request' }}
592+
593+
build-local-nomerge-verify:
594+
uses: ./.github/workflows/verify.yml
595+
needs:
596+
- build-local-nomerge
597+
with:
598+
builder-outputs: ${{ toJSON(needs.build-local-nomerge.outputs) }}
599+
600+
build-local-nomerge-outputs:
601+
runs-on: ubuntu-24.04
602+
needs:
603+
- build-local-nomerge
604+
steps:
605+
-
606+
name: Builder outputs
607+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
608+
env:
609+
INPUT_BUILDER-OUTPUTS: ${{ toJSON(needs.build-local-nomerge.outputs) }}
610+
with:
611+
script: |
612+
const builderOutputs = JSON.parse(core.getInput('builder-outputs'));
613+
core.info(JSON.stringify(builderOutputs, null, 2));
614+
615+
build-local-single-nomerge:
616+
uses: ./.github/workflows/build.yml
617+
permissions:
618+
contents: read
619+
id-token: write
620+
with:
621+
artifact-name: build-single-nomerge-output
622+
artifact-upload: true
623+
artifact-merge: false
624+
file: test/hello.Dockerfile
625+
output: local
626+
sbom: true
627+
sign: ${{ github.event_name != 'pull_request' }}
628+
629+
build-local-single-nomerge-verify:
630+
uses: ./.github/workflows/verify.yml
631+
needs:
632+
- build-local-single-nomerge
633+
with:
634+
builder-outputs: ${{ toJSON(needs.build-local-single-nomerge.outputs) }}
635+
636+
build-local-single-nomerge-outputs:
637+
runs-on: ubuntu-24.04
638+
needs:
639+
- build-local-nomerge
640+
steps:
641+
-
642+
name: Builder outputs
643+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
644+
env:
645+
INPUT_BUILDER-OUTPUTS: ${{ toJSON(needs.build-local-single-nomerge.outputs) }}
646+
with:
647+
script: |
648+
const builderOutputs = JSON.parse(core.getInput('builder-outputs'));
649+
core.info(JSON.stringify(builderOutputs, null, 2));

.github/workflows/bake.yml

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ on:
2828
description: "Upload build output GitHub artifact (for local output)"
2929
required: false
3030
default: false
31+
artifact-merge:
32+
type: boolean
33+
description: "Merge output for multi-platforms build into a single artifact (for local output)"
34+
required: false
35+
default: true
3136
cache:
3237
type: boolean
3338
description: "Enable cache to GitHub Actions cache backend"
@@ -138,6 +143,9 @@ on:
138143
artifact-name:
139144
description: "Name of the uploaded artifact (for local output)"
140145
value: ${{ jobs.finalize.outputs.artifact-name }}
146+
artifact-merge:
147+
description: "Whether multiple artifacts were merged (for local output)"
148+
value: ${{ jobs.finalize.outputs.artifact-merge }}
141149
output-type:
142150
description: "Build output type"
143151
value: ${{ jobs.finalize.outputs.output-type }}
@@ -560,6 +568,7 @@ jobs:
560568
INPUT_PLATFORM: ${{ matrix.platform }}
561569
INPUT_SBOM-IMAGE: ${{ env.SBOM_IMAGE }}
562570
INPUT_LOCAL-EXPORT-DIR: ${{ env.LOCAL_EXPORT_DIR }}
571+
INPUT_ARTIFACT-MERGE: ${{ inputs.artifact-merge }}
563572
INPUT_CACHE: ${{ inputs.cache }}
564573
INPUT_CACHE-SCOPE: ${{ inputs.cache-scope }}
565574
INPUT_CACHE-MODE: ${{ inputs.cache-mode }}
@@ -587,10 +596,10 @@ jobs:
587596
588597
const inpPlatform = core.getInput('platform');
589598
const platformPairSuffix = inpPlatform ? `-${inpPlatform.replace(/\//g, '-')}` : '';
590-
core.setOutput('platform-pair-suffix', platformPairSuffix);
591599
592600
const inpSbomImage = core.getInput('sbom-image');
593601
const inpLocalExportDir = core.getInput('local-export-dir');
602+
const inpArtifactMerge = core.getBooleanInput('artifact-merge');
594603
595604
const inpCache = core.getBooleanInput('cache');
596605
const inpCacheScope = core.getInput('cache-scope');
@@ -617,6 +626,12 @@ jobs:
617626
core.setOutput('source', bakeSource);
618627
});
619628
629+
if (platformPairSuffix) {
630+
core.setOutput('artifact-suffix', platformPairSuffix);
631+
} else if (inpArtifactMerge) {
632+
core.setOutput('artifact-suffix', '0');
633+
}
634+
620635
const sbom = inpSbom ? `generator=${inpSbomImage}` : 'false';
621636
await core.group(`Set sbom`, async () => {
622637
core.info(sbom);
@@ -852,7 +867,7 @@ jobs:
852867
if: ${{ inputs.output == 'local' && inputs.artifact-upload }}
853868
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
854869
with:
855-
name: ${{ inputs.artifact-name }}${{ steps.prepare.outputs.platform-pair-suffix || '0' }}
870+
name: ${{ inputs.artifact-name }}${{ steps.prepare.outputs.artifact-suffix }}
856871
path: ${{ env.LOCAL_EXPORT_DIR }}
857872
if-no-files-found: error
858873
-
@@ -863,22 +878,17 @@ jobs:
863878
INPUT_INDEX: ${{ matrix.index }}
864879
INPUT_VERIFY-COMMANDS: ${{ steps.signing-attestation-manifests.outputs.verify-commands || steps.signing-local-artifacts.outputs.verify-commands }}
865880
INPUT_IMAGE-DIGEST: ${{ steps.get-image-digest.outputs.digest }}
866-
INPUT_ARTIFACT-NAME: ${{ inputs.artifact-name }}${{ steps.prepare.outputs.platform-pair-suffix }}
867-
INPUT_ARTIFACT-UPLOAD: ${{ inputs.artifact-upload }}
868881
INPUT_SIGNED: ${{ needs.prepare.outputs.sign }}
869882
with:
870883
script: |
871884
const inpIndex = core.getInput('index');
872885
const inpVerifyCommands = core.getInput('verify-commands');
873886
const inpImageDigest = core.getInput('image-digest');
874-
const inpArtifactName = core.getInput('artifact-name');
875-
const inpArtifactUpload = core.getBooleanInput('artifact-upload');
876887
const inpSigned = core.getBooleanInput('signed');
877888
878889
const result = {
879890
verifyCommands: inpVerifyCommands,
880891
imageDigest: inpImageDigest,
881-
artifactName: inpArtifactUpload ? inpArtifactName : '',
882892
signed: inpSigned
883893
}
884894
core.info(JSON.stringify(result, null, 2));
@@ -892,6 +902,7 @@ jobs:
892902
cosign-version: ${{ env.COSIGN_VERSION }}
893903
cosign-verify-commands: ${{ steps.set.outputs.cosign-verify-commands }}
894904
artifact-name: ${{ inputs.artifact-upload && inputs.artifact-name || '' }}
905+
artifact-merge: ${{ inputs.artifact-merge }}
895906
output-type: ${{ inputs.output }}
896907
signed: ${{ needs.prepare.outputs.sign }}
897908
needs:
@@ -973,7 +984,7 @@ jobs:
973984
}
974985
-
975986
name: Merge artifacts
976-
if: ${{ inputs.output == 'local' && inputs.artifact-upload }}
987+
if: ${{ inputs.output == 'local' && inputs.artifact-upload && inputs.artifact-merge }}
977988
uses: actions/upload-artifact/merge@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
978989
with:
979990
name: ${{ inputs.artifact-name }}

.github/workflows/build.yml

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ on:
2828
description: "Upload build output GitHub artifact (for local output)"
2929
required: false
3030
default: false
31+
artifact-merge:
32+
type: boolean
33+
description: "Merge output for multi-platforms build into a single artifact (for local output)"
34+
required: false
35+
default: true
3136
annotations:
3237
type: string
3338
description: "List of annotations to set to the image (for image output)"
@@ -141,6 +146,9 @@ on:
141146
artifact-name:
142147
description: "Name of the uploaded artifact (for local output)"
143148
value: ${{ jobs.finalize.outputs.artifact-name }}
149+
artifact-merge:
150+
description: "Whether multiple artifacts were merged (for local output)"
151+
value: ${{ jobs.finalize.outputs.artifact-merge }}
144152
output-type:
145153
description: "Build output type"
146154
value: ${{ jobs.finalize.outputs.output-type }}
@@ -497,6 +505,7 @@ jobs:
497505
INPUT_SBOM-IMAGE: ${{ env.SBOM_IMAGE }}
498506
INPUT_LOCAL-EXPORT-DIR: ${{ env.LOCAL_EXPORT_DIR }}
499507
INPUT_DISTRIBUTE: ${{ inputs.distribute }}
508+
INPUT_ARTIFACT-MERGE: ${{ inputs.artifact-merge }}
500509
INPUT_ANNOTATIONS: ${{ inputs.annotations }}
501510
INPUT_CACHE: ${{ inputs.cache }}
502511
INPUT_CACHE-SCOPE: ${{ inputs.cache-scope }}
@@ -519,11 +528,11 @@ jobs:
519528
520529
const inpPlatform = core.getInput('platform');
521530
const platformPairSuffix = inpPlatform ? `-${inpPlatform.replace(/\//g, '-')}` : '';
522-
core.setOutput('platform-pair-suffix', platformPairSuffix);
523531
524532
const inpSbomImage = core.getInput('sbom-image');
525533
const inpLocalExportDir = core.getInput('local-export-dir');
526534
const inpDistribute = core.getBooleanInput('distribute');
535+
const inpArtifactMerge = core.getBooleanInput('artifact-merge');
527536
528537
const inpAnnotations = core.getMultilineInput('annotations');
529538
const inpCache = core.getBooleanInput('cache');
@@ -546,6 +555,12 @@ jobs:
546555
const buildContext = `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}.git#${process.env.GITHUB_REF}:${inpContext}`;
547556
core.setOutput('context', buildContext);
548557
558+
if (platformPairSuffix) {
559+
core.setOutput('artifact-suffix', platformPairSuffix);
560+
} else if (inpArtifactMerge) {
561+
core.setOutput('artifact-suffix', '0');
562+
}
563+
549564
switch (inpOutput) {
550565
case 'image':
551566
if (inpMetaImages.length == 0) {
@@ -717,7 +732,7 @@ jobs:
717732
if: ${{ inputs.output == 'local' && inputs.artifact-upload }}
718733
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
719734
with:
720-
name: ${{ inputs.artifact-name }}${{ steps.prepare.outputs.platform-pair-suffix || '0' }}
735+
name: ${{ inputs.artifact-name }}${{ steps.prepare.outputs.artifact-suffix }}
721736
path: ${{ env.LOCAL_EXPORT_DIR }}
722737
if-no-files-found: error
723738
-
@@ -728,22 +743,17 @@ jobs:
728743
INPUT_INDEX: ${{ matrix.index }}
729744
INPUT_VERIFY-COMMANDS: ${{ steps.signing-attestation-manifests.outputs.verify-commands || steps.signing-local-artifacts.outputs.verify-commands }}
730745
INPUT_IMAGE-DIGEST: ${{ steps.build.outputs.digest }}
731-
INPUT_ARTIFACT-NAME: ${{ inputs.artifact-name }}${{ steps.prepare.outputs.platform-pair-suffix }}
732-
INPUT_ARTIFACT-UPLOAD: ${{ inputs.artifact-upload }}
733746
INPUT_SIGNED: ${{ needs.prepare.outputs.sign }}
734747
with:
735748
script: |
736749
const inpIndex = core.getInput('index');
737750
const inpVerifyCommands = core.getInput('verify-commands');
738751
const inpImageDigest = core.getInput('image-digest');
739-
const inpArtifactName = core.getInput('artifact-name');
740-
const inpArtifactUpload = core.getBooleanInput('artifact-upload');
741752
const inpSigned = core.getBooleanInput('signed');
742753
743754
const result = {
744755
verifyCommands: inpVerifyCommands,
745756
imageDigest: inpImageDigest,
746-
artifactName: inpArtifactUpload ? inpArtifactName : '',
747757
signed: inpSigned
748758
}
749759
core.info(JSON.stringify(result, null, 2));
@@ -757,6 +767,7 @@ jobs:
757767
cosign-version: ${{ env.COSIGN_VERSION }}
758768
cosign-verify-commands: ${{ steps.set.outputs.cosign-verify-commands }}
759769
artifact-name: ${{ inputs.artifact-upload && inputs.artifact-name || '' }}
770+
artifact-merge: ${{ inputs.artifact-merge }}
760771
output-type: ${{ inputs.output }}
761772
signed: ${{ needs.prepare.outputs.sign }}
762773
needs:
@@ -837,7 +848,7 @@ jobs:
837848
}
838849
-
839850
name: Merge artifacts
840-
if: ${{ inputs.output == 'local' && inputs.artifact-upload }}
851+
if: ${{ inputs.output == 'local' && inputs.artifact-upload && inputs.artifact-merge }}
841852
uses: actions/upload-artifact/merge@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
842853
with:
843854
name: ${{ inputs.artifact-name }}

.github/workflows/verify.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ jobs:
3333
const cosignVersion = builderOutputs['cosign-version'];
3434
const cosignVerifyCommands = builderOutputs['cosign-verify-commands'];
3535
const artifactName = builderOutputs['artifact-name'];
36+
const artifactMerge = builderOutputs['artifact-merge'] === 'true';
3637
const outputType = builderOutputs['output-type'];
3738
const signed = builderOutputs['signed'] === 'true';
3839
if (!signed) {
@@ -44,7 +45,9 @@ jobs:
4445
4546
core.setOutput('cosign-version', cosignVersion);
4647
core.setOutput('cosign-verify-commands', cosignVerifyCommands);
47-
core.setOutput('artifact-name', artifactName);
48+
core.setOutput('artifact-name', artifactMerge ? artifactName : '');
49+
core.setOutput('artifact-pattern', artifactMerge ? '' : `${artifactName}*`);
50+
core.setOutput('artifact-merge-multiple', artifactMerge ? 'false' : 'true');
4851
core.setOutput('output-type', outputType);
4952
core.setOutput('signed', signed);
5053
-
@@ -92,6 +95,8 @@ jobs:
9295
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
9396
with:
9497
name: ${{ steps.vars.outputs.artifact-name }}
98+
pattern: ${{ steps.vars.outputs.artifact-pattern }}
99+
merge-multiple: ${{ steps.vars.outputs.artifact-merge-multiple }}
95100
-
96101
name: Verify signatures
97102
if: ${{ steps.vars.outputs.signed == 'true' }}

0 commit comments

Comments
 (0)