Skip to content
Latchkey

How to Use a Concurrency Group Per Pull Request in GitHub Actions

Keying the concurrency group on the PR number cancels stale runs for that PR without touching any other PR.

On pull_request events, use github.event.pull_request.number (or github.head_ref) in the group. Each PR gets its own lane, so a fresh push cancels only the outdated run for that same PR.

Steps

  • Trigger on pull_request.
  • Key group on the PR number or github.head_ref.
  • Set cancel-in-progress: true to drop superseded PR runs.

Workflow

.github/workflows/ci.yml
on: [pull_request]
concurrency:
  group: pr-${{ github.event.pull_request.number }}
  cancel-in-progress: true
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: npm test

Gotchas

  • github.head_ref is empty on push events, so this pattern is for pull_request workflows.
  • Add github.workflow to the key if several workflows share the PR number space.

Related guides

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