patternbashTip
Concurrency groups to cancel stale PR runs
Viewed 0 times
concurrencycancel-in-progressPR runstalequeuecost savings
Problem
Every push to a PR branch triggers a new CI run. Old runs keep executing even after new commits invalidate them, wasting runner minutes and cluttering the PR status checks UI.
Solution
Use concurrency groups with cancel-in-progress:
For deployment workflows, never cancel in-progress production deploys—use a different group strategy:
For PR comment-triggered workflows, use the PR number:
concurrency:
group: ci-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: trueFor deployment workflows, never cancel in-progress production deploys—use a different group strategy:
concurrency:
group: deploy-production
cancel-in-progress: false # queue instead of cancelFor PR comment-triggered workflows, use the PR number:
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: trueWhy
cancel-in-progress: true immediately kills the old run when a new one starts for the same group. For production, false means the new run waits, preventing race conditions between two deployments.
Gotchas
- Cancelled runs are marked as cancelled, not failed—they do not block merges if required checks are configured
- The group string must be unique enough to not collide across unrelated workflows
- cancel-in-progress: true on a deploy job can leave infrastructure in a half-deployed state
Revisions (0)
No revisions yet.