ci icon indicating copy to clipboard operation
ci copied to clipboard

How can we record artifacts on failure too?

Open markwhitfeld opened this issue 6 months ago • 3 comments

I have a project that uses the nrwl/ci/.github/workflows/nx-cloud-main.yml@refs/tags/v0.14 action and some agents to run my Playwright tests for my project.

In my previous setup, I used playwright's sharding feature, where you gather the blob reports from each shard job as artifacts and then consolidate then in a subsequent job.

With using the nx-cloud-main workflow mentioned above, I set the input values for collecting some artifacts. But unfortunately the Upload Artifacts step only runs if the main job was successful. See https://github.com/nrwl/ci/blob/81f119483401ffde8275edf4c089b42e24b92cf4/.github/workflows/nx-cloud-main.yml#L368-L374

The Playwright sharding docs recommend to use if: always() in the "Upload Artifact" step:

    - name: Upload blob report to GitHub Actions Artifacts
      if: always()
      uses: actions/upload-artifact@v4
      with:
        name: blob-report-${{ matrix.shardIndex }}
        path: blob-report
        retention-days: 1

This will allow for artifacts for failed tests to be uploaded too, which is pretty essential.

Is there a recommended approach here, or is this a change that needs to be made to the nx-cloud-main workflow?

Potential solutions:

  1. Provide some guidance to your users that they should include || true to the end of the command where failures are acceptable
  • This will unfortunately give a false signal of success for the main job
  1. Add the always() expression to the condition in the "Upload Artifacts" step
  • This may be an unexpected behaviour for some users
  1. Add an input artifacts-always-upload to the workflow that allows a user to conditionally turn this behaviour on.
  • The condition in the step would become: if: ${{ inputs.artifacts-path != '' && (success() || (failure() && inputs.artifacts-always-upload)) }}
  1. Extract the steps of this workflow as a github action (which would exclude the artifact bit) so that users can leverage this code within their own job and handle artifacts how they wish. The nx-could-main workflow in your repository would then also use this extracted action.

What do you think?

markwhitfeld avatar Jan 25 '24 13:01 markwhitfeld