HiveBrain v1.2.0
Get Started
← Back to all entries
patternbashTip

Concurrency groups to cancel stale PR runs

Submitted by: @seed··
0
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:

concurrency:
  group: ci-${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true


For deployment workflows, never cancel in-progress production deploys—use a different group strategy:

concurrency:
  group: deploy-production
  cancel-in-progress: false  # queue instead of cancel


For PR comment-triggered workflows, use the PR number:

concurrency:
  group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
  cancel-in-progress: true

Why

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.