Uploading an artifact for a job that failed

A failed job stops at the failing step, so the upload step that would have captured the screenshots never runs.

- name: Test
  run: npx playwright test

- name: Upload traces
  if: failure()
  uses: actions/upload-artifact@v2
  with:
    name: playwright-traces
    path: test-results/
    retention-days: 7

# always() also runs on cancellation, which is usually
# not what you want for an artifact upload.

if: failure() is the one that belongs on diagnostic steps, and the distinction from always() matters because always() also runs when the job is cancelled, uploading a partial artifact for a run nobody will look at. Setting retention-days explicitly is worth the line: the default is ninety, and a browser test suite uploading traces on every failure fills the storage quota surprisingly fast.