diff --git a/README.md b/README.md index 67b95939..2e9caa56 100644 --- a/README.md +++ b/README.md @@ -680,6 +680,21 @@ See also [`config-gradle`](#config-gradle) input environment variables. | `provenance` | Whether to generate provenance attestation for built artifacts | `false` | | `provenance-artifact-paths` | Relative paths of artifacts for provenance attestation (glob pattern). See [Provenance Attestation](#provenance-attestation) | (optional) | | `generate-summary` | Whether to generate a workflow summary after the build | `true` | +| `job-identifier` | Unique identifier for the problems-report artifact name. Set to a matrix dimension (e.g. `${{ matrix.module }}`) when using this action inside a reusable workflow invoked in a matrix. Auto-generated UUID when omitted. | (optional) | + +> [!TIP] +> When using this action inside a reusable workflow that is itself called in a matrix, set +> `job-identifier` to a matrix dimension to produce readable artifact names: +> +> ```yaml +> - uses: SonarSource/ci-github-actions/build-gradle@v1 +> with: +> job-identifier: ${{ matrix.module }} +> ``` +> +> Without this, a UUID is generated automatically — artifact names will be unique but opaque. + + > [!TIP] > When using `working-directory`, Java must be available at root due to a limitation @@ -957,6 +972,19 @@ See also [`config-npm`](#config-npm) input environment variables. | `provenance` | Whether to generate provenance attestation for built artifacts | `false` | | `provenance-artifact-paths` | Relative paths of artifacts for provenance attestation (glob pattern). See [Provenance Attestation](#provenance-attestation) | (optional) | | `generate-summary` | Whether to generate a workflow summary after the build | `true` | +| `job-identifier` | Unique identifier for the npm-logs artifact name. Set to a matrix dimension (e.g. `${{ matrix.module }}`) when using this action inside a reusable workflow invoked in a matrix. Auto-generated UUID when omitted. | (optional) | + +> [!TIP] +> When using this action inside a reusable workflow that is itself called in a matrix, set +> `job-identifier` to a matrix dimension to produce readable artifact names: +> +> ```yaml +> - uses: SonarSource/ci-github-actions/build-npm@v1 +> with: +> job-identifier: ${{ matrix.module }} +> ``` +> +> Without this, a UUID is generated automatically — artifact names will be unique but opaque. ### Outputs diff --git a/build-gradle/action.yml b/build-gradle/action.yml index 99fceea7..8c2e517d 100644 --- a/build-gradle/action.yml +++ b/build-gradle/action.yml @@ -67,6 +67,13 @@ inputs: generate-summary: description: Whether to generate a workflow summary after the build. default: 'true' + job-identifier: + description: >- + Unique identifier appended to the artifact name (`problems-report-`). + Set this to a matrix dimension value (e.g. the value of `matrix.module`) when calling this action + from a reusable workflow that is invoked in a matrix, to produce human-readable artifact + names. When omitted, a random value is generated to guarantee uniqueness. + default: '' outputs: project-version: @@ -175,11 +182,17 @@ runs: working-directory: ${{ inputs.working-directory }} run: $ACTION_PATH_BUILD_GRADLE/build.sh + - name: Generate unique job ID + id: uid + if: always() + shell: bash + run: echo "value=$RANDOM$RANDOM" >> "$GITHUB_OUTPUT" + - name: Archive problems report if: always() uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 with: - name: problems-report-${{ github.job }}${{ strategy.job-index }} + name: problems-report-${{ inputs.job-identifier != '' && inputs.job-identifier || steps.uid.outputs.value }} path: build/reports/problems/problems-report.html if-no-files-found: ignore diff --git a/build-npm/action.yml b/build-npm/action.yml index c85288a1..b703eb2b 100644 --- a/build-npm/action.yml +++ b/build-npm/action.yml @@ -59,6 +59,13 @@ inputs: generate-summary: description: Whether to generate a workflow summary after the build. default: 'true' + job-identifier: + description: >- + Unique identifier appended to the artifact name (`npm-logs-`). + Set this to a matrix dimension value (e.g. the value of `matrix.module`) when calling this action + from a reusable workflow that is invoked in a matrix, to produce human-readable artifact + names. When omitted, a random value is generated to guarantee uniqueness. + default: '' outputs: BUILD_NUMBER: @@ -173,11 +180,17 @@ runs: working-directory: ${{ inputs.working-directory }} run: $ACTION_PATH_BUILD_NPM/build.sh + - name: Generate unique job ID + id: uid + if: always() + shell: bash + run: echo "value=$RANDOM$RANDOM" >> "$GITHUB_OUTPUT" + - name: Archive logs if: failure() uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 with: - name: npm-logs-${{ github.job }}${{ strategy.job-index }} + name: npm-logs-${{ inputs.job-identifier != '' && inputs.job-identifier || steps.uid.outputs.value }} path: ~/.npm/_logs/ if-no-files-found: ignore