Skip to content

Commit 36b3b98

Browse files
committed
feat(continuous-integration)!: manage build artifact by id and not name anymore
Signed-off-by: Emilien Escalle <emilien.escalle@escemi.com>
1 parent 20aa960 commit 36b3b98

1 file changed

Lines changed: 16 additions & 9 deletions

File tree

.github/workflows/continuous-integration.yml

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ on:
9696
SECRET_EXAMPLE=$\{{ secrets.SECRET_EXAMPLE }}
9797
```
9898
required: false
99+
outputs:
100+
build-artifact-id:
101+
description: "ID of the build artifact) uploaded during the build step."
102+
value: ${{ jobs.build.outputs.artifact-id }}
99103

100104
permissions: {}
101105

@@ -220,11 +224,8 @@ jobs:
220224
return core.setFailed('No valid build artifact paths found');
221225
}
222226
223-
if (!buildArtifact.name) {
224-
buildArtifact.name = 'build';
225-
} else if (typeof buildArtifact.name !== 'string') {
226-
return core.setFailed('Build artifact name must be a string');
227-
}
227+
// Generate a unique name for the artifact
228+
buildArtifact.name = `build-${process.env.GITHUB_RUN_ID}`;
228229
229230
core.setOutput('artifact', JSON.stringify(buildArtifact));
230231
}
@@ -309,6 +310,8 @@ jobs:
309310
contents: read
310311
# FIXME: This is a workaround for having workflow ref. See https://github.com/orgs/community/discussions/38659
311312
id-token: write
313+
outputs:
314+
artifact-id: ${{ steps.build-artifact-id.outputs.artifact-id }}
312315
steps:
313316
- uses: hoverkraft-tech/ci-github-common/actions/checkout@5f11437c716059f30c635f90055060e4ef8b31a0 # 0.28.0
314317
if: needs.setup.outputs.build-commands && inputs.container == ''
@@ -325,7 +328,8 @@ jobs:
325328
ref: ${{ steps.oidc.outputs.job_workflow_repo_ref }}
326329
sparse-checkout: |
327330
actions
328-
- run: |
331+
- if: needs.setup.outputs.build-commands
332+
run: |
329333
if [ -f .gitignore ]; then grep -q "self-workflow" .gitignore || echo "self-workflow" >> .gitignore; else echo "self-workflow" >> .gitignore; fi
330334
if [ -f .dockerignore ]; then grep -q "self-workflow" .dockerignore || echo "self-workflow" >> .dockerignore; else echo "self-workflow" >> .dockerignore; fi
331335
# jscpd:ignore-end
@@ -395,11 +399,13 @@ jobs:
395399
$RUN_SCRIPT_COMMAND "$COMMAND"
396400
done
397401
398-
- if: needs.setup.outputs.build-commands && needs.setup.outputs.build-artifact
402+
- id: build-artifact-id
403+
if: needs.setup.outputs.build-commands && needs.setup.outputs.build-artifact
399404
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
400405
with:
401406
name: ${{ fromJSON(needs.setup.outputs.build-artifact).name }}
402407
path: ${{ fromJSON(needs.setup.outputs.build-artifact).paths }}
408+
if-no-files-found: error
403409

404410
test:
405411
name: 🧪 Test
@@ -420,11 +426,12 @@ jobs:
420426
- uses: hoverkraft-tech/ci-github-common/actions/checkout@5f11437c716059f30c635f90055060e4ef8b31a0 # 0.28.0
421427
if: inputs.container == ''
422428

423-
- if: needs.setup.outputs.build-artifact && inputs.container == ''
429+
- if: needs.build.outputs.artifact-id && inputs.container == ''
424430
uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0
425431
with:
426-
name: build
432+
artifact-ids: ${{ needs.build.outputs.artifact-id }}
427433
path: "/"
434+
428435
# FIXME: This is a workaround for having workflow ref. See https://github.com/orgs/community/discussions/38659
429436
- id: oidc
430437
uses: ChristopherHX/oidc@73eee1ff03fdfce10eda179f617131532209edbd # v3

0 commit comments

Comments
 (0)