How can we record artifacts on failure too?
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:
- Provide some guidance to your users that they should include
|| trueto the end of the command where failures are acceptable
- This will unfortunately give a false signal of success for the main job
- Add the
always()expression to the condition in the "Upload Artifacts" step
- This may be an unexpected behaviour for some users
- Add an input
artifacts-always-uploadto 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)) }}
- 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-mainworkflow in your repository would then also use this extracted action.
What do you think?
Hello @markwhitfeld ! Thanks for creating this feature request! Do you think you can create a PR with your suggested implementation? If not, maybe I can try to put together something at some point, but it will not be very soon!
Thank you for your patience!
Which of the potential solutions sound the best to you?
I think option (3) Add an input artifacts-always-upload to the workflow sounds like the best one, since it seems like the less disruptive of existing functionality.