Skip to content

Latest commit

 

History

History
90 lines (72 loc) · 3.23 KB

File metadata and controls

90 lines (72 loc) · 3.23 KB
description How to set up failed test reruns for sharded Playwright runs on GitHub Actions

Re-run Only Failed Tests — Sharded runs

When using native Playwright --shard parallelism, the Last Failed GitHub Action can fetch and rerun failed tests from the last workflow run.

Step-by-step guide:

Add the currents-dev/playwright-last-failed step

Add a step to the workflow before the test step runs.

- name: Playwright Last Failed action
  id: last-failed-action
  uses: currents-dev/playwright-last-failed@v2
  with:
    pw-output-dir: basic/test-results
    matrix-index: ${{ matrix.shard }}
    matrix-total: ${{ strategy.job-total }}

See the action configuration for details.

A full example
name: failed-only-reruns

on:
  push:

jobs:
  test-reporter:
    strategy:
      fail-fast: false
      matrix:
        shard: [1, 2, 3]
    timeout-minutes: 60
    runs-on: ubuntu-latest
    container: space.vars.PW_IMAGE_ROUTE + ":" + space.vars.LATEST_PW_IMAGE_VERSION
    env:
      CURRENTS_PROJECT_ID: ${{ vars.CURRENTS_PROJECT_ID }}
      CURRENTS_RECORD_KEY: ${{ secrets.CURRENTS_RECORD_KEY }}
      CURRENTS_CI_BUILD_ID: ${{ github.repository }}-${{ github.run_id }}-${{ github.run_attempt }}
    steps:
      - uses: actions/checkout@v4
        with:
          ref: ${{ github.ref }}
      - run: |
          echo "$GITHUB_WORKSPACE"
          git config --global --add safe.directory "$GITHUB_WORKSPACE"
      - uses: actions/setup-node@v4
        with:
          node-version: "24.x"
      - name: Install dependencies
        run: |
          npm ci
          npx playwright install chrome
      - name: Playwright Last Failed action
        id: last-failed-action
        uses: currents-dev/playwright-last-failed@v2
        with:
          pw-output-dir: basic/test-results
          matrix-index: ${{ matrix.shard }}
          matrix-total: ${{ strategy.job-total }}
      - name: Playwright Tests
        working-directory: ./basic
        run: |
          COMMAND="npx playwright test --config playwright.config.reporter.ts ${{ steps.last-failed-action.outputs.extra-pw-flags }}"
          echo "Running command: $COMMAND"
          $COMMAND

{% hint style="info" %} For a workflow with a custom CI build ID, see custom-ci-build-id-for-reruns.md. {% endhint %}

Full examples:

  • rerun-shards-pwc.yml - rerun only the tests that failed in the previous run, using the pwc helper command from @currents/playwright.
  • rerun-shards-reporter.yml - rerun only the tests that failed in the previous run, using reporter setup in playwright.config.ts.