Skip to content

Commit 3b21da7

Browse files
committed
feat(continuous-integration)!: manage build artifact by id and not name anymore
Signed-off-by: Emilien Escalle <[email protected]>
1 parent 20aa960 commit 3b21da7

File tree

3 files changed

+21
-14
lines changed

3 files changed

+21
-14
lines changed

.github/workflows/__test-workflow-continuous-integration.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
3030
- uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0
3131
with:
32-
name: build
32+
artifact-ids: ${{ needs.act-without-container.outputs.build-artifact-id }}
3333
path: "/"
3434

3535
- name: Check the build artifacts
@@ -71,7 +71,7 @@ jobs:
7171
working-directory: /usr/src/app/
7272
build: |
7373
{
74-
"artifact": { "name": "build-in-container", "paths": "dist" }
74+
"artifact": "dist"
7575
}
7676
7777
assert-with-container:
@@ -82,7 +82,7 @@ jobs:
8282
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
8383
- uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0
8484
with:
85-
name: build-in-container
85+
artifact-ids: ${{ needs.act-with-container.outputs.build-artifact-id }}
8686
path: ${{ runner.temp }}
8787

8888
- name: Check the build artifacts

.github/workflows/continuous-integration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ jobs:
218218
- name: Download build artifact
219219
uses: actions/download-artifact@v2
220220
with:
221-
name: build
221+
artifact-ids: ${{ needs.continuous-integration.outputs.build-artifact-id }}
222222
path: /
223223
224224
- name: Publish

.github/workflows/continuous-integration.yml

Lines changed: 17 additions & 10 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

@@ -210,7 +214,7 @@ jobs:
210214
.filter(Boolean)
211215
.map(artifact => {
212216
// FIXME: Workaround to preserve full path to artifact
213-
const fullpath = artifact.startsWith('/') ? artifact : `${workingDirectory}/${artifact}`;
217+
const fullpath = artifact.startsWith('/') ? artifact : path.join(workingDirectory, artifact);
214218
215219
// Add a wildcard to the first folder of the path
216220
return fullpath.replace(/\/([^/]+)/, '/*$1');
@@ -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 = `${process.env.GITHUB_JOB}-build-${process.env.GITHUB_RUN_ID}-${Math.random().toString(36).substring(2, 8)}`;
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)