Skip to content

About

The action helps to run last failed Playwright tests using Currents cache

Resources

Stars

3 stars

Watchers

3 watching

Forks

Repository files navigation

Playwright Last Failed (GitHub Action)

This action supports re-running only the Playwright tests that failed when GitHub Actions runs “re-run failed jobs” (or similar retries). It works together with Currents and the @currents/cmd CLI.

Full setup, sharding, orchestration, and CI build ID details: Re-run only failed tests (GitHub Actions) on docs.currents.dev. For background on why re-runs need extra configuration, see the guide Re-run only failed tests.

Purpose

  • Before the Playwright test step: restores last run metadata (via Currents cache or the Currents API) and exposes extra Playwright CLI flags as a step output.
  • After the job (cache mode only): saves updated last run metadata so the next retry can target failures again.

The step output is passed into the Playwright command—for example npx playwright test … ${{ steps.<id>.outputs.extra-pw-flags }}—so only failed tests run on retry.

How it works

The action runs on Node 24 and installs @currents/cmd@^3.3.0 globally (npm install -g @currents/cmd@^3.3.0). It then behaves in one of two ways:

1. Cache mode (default)

Suited to workflows that report runs to Currents with a record key (typical Playwright reporter + sharding flow).

  1. Main step: runs npx currents cache get with the last-run preset. On success, it reads a generated preset file and sets the output extra-pw-flags.
  2. Post step: runs npx currents cache set with the same preset so the next workflow attempt can read an updated snapshot.

Authentication and targeting use the Currents record key (input key or CURRENTS_RECORD_KEY). Optional id, path, matrix inputs, and pw-output-dir tune what is cached.

2. API / orchestration mode (use-api or or8n)

Suited to workflows that rely on Currents Orchestration (or otherwise need the CLI to resolve failures via the API). In this mode the post-cache step is skipped.

On re-run attempts (GITHUB_RUN_ATTEMPT > 1), the main step runs npx currents api get-run to fetch the previous run and, when successful, sets extra-discovery-flags to --last-failed. The workflow should define CURRENTS_API_KEY, CURRENTS_PROJECT_ID (and related environment variables as in the docs), and set or8n: true (or use-api: true) as shown in the orchestration section of the documentation. The api-key and project-id inputs are passed to the CLI as CURRENTS_API_KEY and CURRENTS_PROJECT_ID.

The previous run's failed tests are the whole run's. If you also pass your own --shard, each shard reruns the failed tests in its share, which covers every failed test with "Re-run all jobs". With "Re-run failed jobs" it does only when the re-run is linked to the attempt before it, so every shard gets the same tests again: keep the default CI build ID, or set previous-ci-build-id.

Outputs

Name Description
extra-pw-flags Flags to append to the Playwright test command.
extra-discovery-flags Flags to append to the pwc-p discover command.

If restoration fails, the output may be empty; the workflow can still run tests normally.

Inputs (options)

  • key (optional, default ''). Currents record key, or set CURRENTS_RECORD_KEY. Used in cache mode.
  • debug (optional, default false). Enables debug logging for CLI commands.
  • id (optional, default ''). Cache ID namespace for cache get / cache set.
  • path (optional, default ''). Comma-separated paths to include when writing cache (post step).
  • output-dir (optional, default ''). Directory for preset output during cache get.
  • pw-output-dir (optional, default test-results). Playwright output directory; used for API mode .last-run.json path and for --pw-output-dir on cache set.
  • matrix-index (optional, default 1). Shard index for parallel runs (cache get / cache set).
  • matrix-total (optional, default 1). Total shards.
  • use-api (optional, default false). API-based last-failed resolution (same code path as or8n).
  • or8n (optional, default false). Orchestration-oriented behavior (API path; no post-cache step).
  • api-key (optional, default ''). API key, or set CURRENTS_API_KEY in the environment.
  • project-id (optional, default ''). Currents project ID, or set CURRENTS_PROJECT_ID. Selects the project for API calls.
  • previous-ci-build-id (optional, default ''). Override for the previous CI build ID when resolving the prior run (see custom CI build ID). On a re-run the action also exports it as CURRENTS_PREVIOUS_CI_BUILD_ID, in both modes, so the reporter links the run to the attempt before it. Set it when you use a custom CI build ID: a re-run that is not linked can split the tests across shards differently from the first attempt.

*In cache mode a record key (input or environment) is required for cache reads/writes.

Without a stored record key

The action takes no OIDC inputs. To use GitHub Actions OIDC instead of a stored record key, get a record key with @currents/cmd in a step before this action and export it as CURRENTS_RECORD_KEY. The job needs permissions: id-token: write. Get an API key for API mode the same way with currents ci auth get-api-token, exported as CURRENTS_API_KEY.

permissions:
  id-token: write
  contents: read

steps:
  - name: Get a Currents record key
    env:
      CURRENTS_OIDC_POLICY_ID: ${{ vars.CURRENTS_OIDC_POLICY_ID }}
    run: |
      key=$(npx --yes --ignore-scripts --package @currents/cmd@3.4.0 \
        currents ci auth get-record-key --oidc-provider github-actions)
      echo "::add-mask::$key"
      echo "CURRENTS_RECORD_KEY=$key" >> "$GITHUB_ENV"

  - name: Playwright Last Failed
    id: last-failed
    uses: currents-dev/playwright-last-failed@v1
    with:
      matrix-index: ${{ matrix.shard }}
      matrix-total: ${{ strategy.job-total }}

The key stays valid until it expires or currents ci auth revoke revokes it.

Setup

  1. Add @currents/cmd to the repository as a dev dependency and install with a frozen lockfile in CI (npm ci, etc.). The action installs a global CLI for convenience; pinning @currents/cmd in the repository keeps CI reproducible. See the note in the official docs.
  2. Configure Currents (record key, and for API mode, API key and project ID) using secrets and env as described in the documentation.
  3. Add this action before the Playwright step and pass extra-pw-flags into the test command.
  4. Sharding: set matrix-index and matrix-total from the job matrix (for example ${{ matrix.shard }} and ${{ strategy.job-total }}).

Minimal example (cache mode, sharded)

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

- name: Run Playwright
  run: npx playwright test ${{ steps.last-failed.outputs.extra-pw-flags }}

For orchestration (or8n: true), environment variables, custom CURRENTS_CI_BUILD_ID, and copypaste workflows, see Re-run only failed tests (GitHub Actions).

Action metadata

Input/output definitions are in action.yml.

Developing this repository

This action is implemented in TypeScript (src/index.ts, src/post.ts). After changing sources, run npm run all to format, lint, test, and rebuild dist/ before committing.

Releases

The action is consumed by tag, and releases move the major tag (v2), so @v2 picks up fixes. See action versioning.

Bump version in package.json, merge that to main, then cut the release:

script/release

The script reads the version from package.json — it refuses to run on a dirty tree, off main, behind the remote, or with a version that is not above the last release — then tags vX.Y.Z, moves the major tag to it, and publishes the release notes with gh.

Both tags go up in one atomic push, so a rejected major tag cannot leave a published vX.Y.Z behind. If a release does fail part way, fix the cause and run script/release again on the same commit: it picks up where it stopped. A new major leaves the previous one on a releases/v# branch so it stays patchable.

About

The action helps to run last failed Playwright tests using Currents cache

Resources

Stars

3 stars

Watchers

3 watching

Forks

Releases

Packages

Used by

Contributors

Languages