diff --git a/.github/workflows/__test-workflow-continuous-integration.yml b/.github/workflows/__test-workflow-continuous-integration.yml index 96c95cd..94899e2 100644 --- a/.github/workflows/__test-workflow-continuous-integration.yml +++ b/.github/workflows/__test-workflow-continuous-integration.yml @@ -29,7 +29,7 @@ jobs: - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0 with: - name: build + artifact-ids: ${{ needs.act-without-container.outputs.build-artifact-id }} path: "/" - name: Check the build artifacts @@ -71,7 +71,7 @@ jobs: working-directory: /usr/src/app/ build: | { - "artifact": { "name": "build-in-container", "paths": "dist" } + "artifact": "dist" } assert-with-container: @@ -82,7 +82,7 @@ jobs: - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0 with: - name: build-in-container + artifact-ids: ${{ needs.act-with-container.outputs.build-artifact-id }} path: ${{ runner.temp }} - name: Check the build artifacts diff --git a/.github/workflows/continuous-integration.md b/.github/workflows/continuous-integration.md index 1d245ae..18aee65 100644 --- a/.github/workflows/continuous-integration.md +++ b/.github/workflows/continuous-integration.md @@ -218,7 +218,7 @@ jobs: - name: Download build artifact uses: actions/download-artifact@v2 with: - name: build + artifact-ids: ${{ needs.continuous-integration.outputs.build-artifact-id }} path: / - name: Publish diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 3f824f9..241a9c0 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -96,6 +96,10 @@ on: SECRET_EXAMPLE=$\{{ secrets.SECRET_EXAMPLE }} ``` required: false + outputs: + build-artifact-id: + description: "ID of the build artifact) uploaded during the build step." + value: ${{ jobs.build.outputs.artifact-id }} permissions: {} @@ -210,7 +214,7 @@ jobs: .filter(Boolean) .map(artifact => { // FIXME: Workaround to preserve full path to artifact - const fullpath = artifact.startsWith('/') ? artifact : `${workingDirectory}/${artifact}`; + const fullpath = artifact.startsWith('/') ? artifact : path.join(workingDirectory, artifact); // Add a wildcard to the first folder of the path return fullpath.replace(/\/([^/]+)/, '/*$1'); @@ -220,11 +224,8 @@ jobs: return core.setFailed('No valid build artifact paths found'); } - if (!buildArtifact.name) { - buildArtifact.name = 'build'; - } else if (typeof buildArtifact.name !== 'string') { - return core.setFailed('Build artifact name must be a string'); - } + // Generate a unique name for the artifact + buildArtifact.name = `${process.env.GITHUB_JOB}-build-${process.env.GITHUB_RUN_ID}-${Math.random().toString(36).substring(2, 8)}`; core.setOutput('artifact', JSON.stringify(buildArtifact)); } @@ -309,6 +310,8 @@ jobs: contents: read # FIXME: This is a workaround for having workflow ref. See https://github.com/orgs/community/discussions/38659 id-token: write + outputs: + artifact-id: ${{ steps.build-artifact-id.outputs.artifact-id }} steps: - uses: hoverkraft-tech/ci-github-common/actions/checkout@5f11437c716059f30c635f90055060e4ef8b31a0 # 0.28.0 if: needs.setup.outputs.build-commands && inputs.container == '' @@ -325,7 +328,8 @@ jobs: ref: ${{ steps.oidc.outputs.job_workflow_repo_ref }} sparse-checkout: | actions - - run: | + - if: needs.setup.outputs.build-commands + run: | if [ -f .gitignore ]; then grep -q "self-workflow" .gitignore || echo "self-workflow" >> .gitignore; else echo "self-workflow" >> .gitignore; fi if [ -f .dockerignore ]; then grep -q "self-workflow" .dockerignore || echo "self-workflow" >> .dockerignore; else echo "self-workflow" >> .dockerignore; fi # jscpd:ignore-end @@ -395,11 +399,13 @@ jobs: $RUN_SCRIPT_COMMAND "$COMMAND" done - - if: needs.setup.outputs.build-commands && needs.setup.outputs.build-artifact + - id: build-artifact-id + if: needs.setup.outputs.build-commands && needs.setup.outputs.build-artifact uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0 with: name: ${{ fromJSON(needs.setup.outputs.build-artifact).name }} path: ${{ fromJSON(needs.setup.outputs.build-artifact).paths }} + if-no-files-found: error test: name: 🧪 Test @@ -420,11 +426,12 @@ jobs: - uses: hoverkraft-tech/ci-github-common/actions/checkout@5f11437c716059f30c635f90055060e4ef8b31a0 # 0.28.0 if: inputs.container == '' - - if: needs.setup.outputs.build-artifact && inputs.container == '' + - if: needs.build.outputs.artifact-id && inputs.container == '' uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0 with: - name: build + artifact-ids: ${{ needs.build.outputs.artifact-id }} path: "/" + # FIXME: This is a workaround for having workflow ref. See https://github.com/orgs/community/discussions/38659 - id: oidc uses: ChristopherHX/oidc@73eee1ff03fdfce10eda179f617131532209edbd # v3