diff --git a/.github/workflows/ci-pr-checks-image.yml b/.github/workflows/ci-pr-checks-image.yml index a6bd9444..f2599560 100644 --- a/.github/workflows/ci-pr-checks-image.yml +++ b/.github/workflows/ci-pr-checks-image.yml @@ -144,6 +144,11 @@ on: type: string required: false default: '' + test-report-path: + description: Only for Spring Boot. Path(s) to test reports (e.g. Cucumber, Surefire, Failsafe) to upload as an artifact if the Maven build fails. One path per line, relative to the repository root. Requires maven-skip-tests to be false + type: string + required: false + default: '' trivy-library-disable-scan: description: Disable Trivy library scan type: boolean @@ -201,7 +206,7 @@ jobs: if: | inputs.enable-container-image-scan == true && inputs.application-type == 'spring-boot' - uses: felleslosninger/github-workflows/.github/workflows/ci-spring-boot-container-scan.yml@main + uses: felleslosninger/github-workflows/.github/workflows/ci-spring-boot-container-scan.yml@PF-2710 permissions: contents: read with: @@ -215,6 +220,7 @@ jobs: maven-skip-tests: ${{ inputs.maven-skip-tests }} application-path: ${{ inputs.application-path }} module-name: ${{ inputs.module-name }} + test-report-path: ${{ inputs.test-report-path }} trivy-library-disable-scan: ${{ inputs.trivy-library-disable-scan }} trivy-library-ignore-unfixed: ${{ inputs.trivy-library-ignore-unfixed }} trivy-library-severity: ${{ inputs.trivy-library-severity }} diff --git a/.github/workflows/ci-spring-boot-container-scan.yml b/.github/workflows/ci-spring-boot-container-scan.yml index e7d1bdb9..2f14998b 100644 --- a/.github/workflows/ci-spring-boot-container-scan.yml +++ b/.github/workflows/ci-spring-boot-container-scan.yml @@ -18,7 +18,9 @@ # 3. Set up JDK # 4. Build Spring Boot image using Paketo buildpacks. The image will be # built based on the application path or module name (if provided) -# 5. Run Trivy vulnerability scan on the built image +# 5. Upload test reports as an artifact if the build fails and +# 'test-report-path' is set +# 6. Run Trivy vulnerability scan on the built image # # Trigger: # Triggered by workflow calls (workflow_call) @@ -86,6 +88,11 @@ on: default: "" required: false type: string + test-report-path: + description: Path(s) to test reports (e.g. Cucumber, Surefire, Failsafe) to upload as an artifact if the Maven build fails. One path per line, relative to the repository root. If not provided, nothing is uploaded + type: string + required: false + default: "" trivy-library-disable-scan: description: Disable Trivy library scan type: boolean @@ -204,6 +211,28 @@ jobs: -Dspring-boot.build-image.imageName="$IMAGE_NAME:$IMAGE_TAG" \ -Dspring-boot.build-image.builder="paketobuildpacks/$IMAGE_PACK:$IMAGE_PACK_TAG" + - name: Set test report artifact name + id: test-report-artifact + if: | + failure() && + inputs.test-report-path != '' + env: + IMAGE_NAME: ${{ inputs.image-name || github.event.repository.name }} + run: | + # Image names may contain characters not allowed in artifact names (e.g. '/' and ':') + SAFE_NAME=$(printf '%s' "$IMAGE_NAME" | tr -c 'A-Za-z0-9._-' '-') + echo "name=test-reports-${SAFE_NAME}" >> "$GITHUB_OUTPUT" + + - name: Upload test reports + if: | + failure() && + inputs.test-report-path != '' + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # pin@v7.0.2 + with: + name: ${{ steps.test-report-artifact.outputs.name }} + path: ${{ inputs.test-report-path }} + if-no-files-found: ignore + - name: Run Trivy vulnerability scanner (image) uses: felleslosninger/github-workflows/.github/actions/trivy-scan@main with: diff --git a/docs/pull-request-image.md b/docs/pull-request-image.md index 5ea90e43..8f1d35a9 100644 --- a/docs/pull-request-image.md +++ b/docs/pull-request-image.md @@ -219,6 +219,7 @@ These are applicable to Spring Boot and Quarkus application types. | `maven-lifecycle` | `string` | `install` | | `maven-skip-tests` | `boolean` | `true` | | `module-name` | `string` | Not set | +| `test-report-path` | `string` | Not set | > [!NOTE] > **Multi-module projects:** If your application is part of a multi-module Maven @@ -226,6 +227,31 @@ These are applicable to Spring Boot and Quarkus application types. > workflow will automatically append the `-pl -am` flags to ensure > required internal dependencies are built before generating the image. +##### Test reports + +Set `test-report-path` to upload test reports (for example Cucumber HTML, +Surefire or Failsafe reports) as the artifact `test-reports-` when +the Maven build fails. Characters in the image name that are not allowed in +artifact names (such as `/` and `:`) are replaced with `-`. Use one path per +line: + +```yaml +maven-skip-tests: false +test-report-path: | + target/cucumber-reports/ + target/failsafe-reports/ +``` + +- `maven-skip-tests` must be `false`, otherwise the tests do not run and no + reports are generated. +- Paths are relative to the repository root, not to `application-path`. If + `application-path` is not the root, prefix the paths with it, for example + `apps/my-app/target/cucumber-reports/`. +- For multi-module projects built with `module-name`, the reports end up in + each module's `target` folder. Use a glob such as + `**/target/cucumber-reports/`. +- If no files match, nothing is uploaded and the step does not fail. + #### Container image scanning (Quarkus overrides) | Override | Type | Workflow default |