Skip to content
Latchkey

How to Run Only Affected E2E Tests in GitHub Actions

On pull requests, run only the specs affected by the diff; run the full suite on main to keep coverage honest.

Use Playwright --only-changed=<base> on PRs to limit the run to tests touched since the base branch, with a full-suite fallback for pushes to protected branches.

Steps

  • Fetch enough history so the base branch is available (fetch-depth: 0).
  • On pull_request, run --only-changed=origin/${{ github.base_ref }}.
  • On push to main, run the full suite.

Workflow

.github/workflows/ci.yml
jobs:
  e2e:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with: { fetch-depth: 0 }
      - uses: actions/setup-node@v4
        with: { node-version: 20, cache: npm }
      - run: npm ci
      - run: npx playwright install --with-deps
      - name: Affected on PR
        if: github.event_name == 'pull_request'
        run: npx playwright test --only-changed=origin/${{ github.base_ref }}
      - name: Full suite on main
        if: github.event_name == 'push'
        run: npx playwright test

Gotchas

  • --only-changed needs the base commit fetched, so shallow clones miss it; use fetch-depth: 0.
  • Always run the full suite on the default branch so nothing rots undetected.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →