How to Cancel In-Progress Runs on a New Push in GitHub Actions
A top-level concurrency block with cancel-in-progress: true cancels the previous run in the same group when a newer push arrives.
Set concurrency.group to a per-ref key and cancel-in-progress: true. When you push again to the same branch, GitHub cancels the older run before starting the new one.
Steps
- Add a top-level
concurrency:block. - Key
groupon${{ github.workflow }}-${{ github.ref }}so each ref queues separately. - Set
cancel-in-progress: trueto kill the superseded run.
Workflow
.github/workflows/ci.yml
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm ci && npm run buildGotchas
- The canceled run shows the conclusion
cancelled, notfailure, so required checks may need aif: always()guard. - Include
github.workflowin the group so unrelated workflows on the same ref do not cancel each other.
Related guides
How to Run Only the Latest Commit in a Pull Request in GitHub ActionsEnsure a GitHub Actions PR pipeline runs only the newest commit by canceling superseded runs with a per-PR co…
How to Set a Concurrency Group Per Branch in GitHub ActionsScope a GitHub Actions concurrency group to each branch so runs on one branch never cancel or block runs on a…