Skip to content

How can we record artifacts on failure too? #97

@markwhitfeld

Description

@markwhitfeld

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

- name: Uploading artifacts
uses: actions/upload-artifact@v3
if: ${{ inputs.artifacts-path != '' }}
with:
name: ${{ inputs.artifacts-name }}
path: ${{ inputs.artifacts-path }}
retention-days: ${{ inputs.artifacts-retention-days }}

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions