CI/CDGitHub Actions
Concurrency groups: stop two deploys from running at once
By default GitHub Actions lets several runs of the same workflow run at the same time, so two pushes can start two deploys. A concurrency group lets one run at a time proceed, and you choose whether the others wait, get replaced or get canceled.

What a concurrency group does
The concurrency key puts a workflow or a job in a named group. Within a repository, at most one job or workflow run in a group is running at any time.
concurrency:
group: production-deployThe name is any string or expression. It is case insensitive, so prod and Prod are the same group. Group names are shared across the workflows of a repository: two workflows that use the same name are in one group.
What happens to a pending run
The default is not a queue. Take three runs in one group:
- Run A is in progress. Run B is queued in the same group and becomes
pending. - Run C is queued. GitHub cancels B, and C takes its place as the pending run.
- A is not canceled. Only the pending run was replaced.
By default a group has at most one running and one pending run. Two options change this:
cancel-in-progress: truealso cancels the run that is in progress. In the example, B cancels A.queue: maxlets up to 100 jobs or runs be pending in the group. When the queue is full, additional ones are canceled. The default value isqueue: single.
queue: max and cancel-in-progress: true cannot be combined. GitHub rejects the workflow with a validation error.
Pending runs are processed first in, first out, by the time each one started waiting on the group. GitHub adds that the order is not guaranteed, because the actual start time of a run varies.
Outdated pull request runs
GitHub's own example of this use is canceling linters that check outdated commits. For pull requests:
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: truegithub.head_ref is the source branch of a pull request, and it is defined only on pull request events. On any other event the expression falls back to github.run_id, which is unique for the run, so the group cancels in-progress runs on pull request events only.
github.workflow belongs in the name. With several workflows in a repository, group names must be unique across workflows, or a run cancels in-progress runs of the other workflows.
A production deploy that is never canceled
A run that is in progress is canceled only when cancel-in-progress is true. For a deploy job, leave the option out. This is GitHub's deployment example with a job-level group:
jobs:
deployment:
runs-on: ubuntu-latest
environment: production
concurrency: production
steps:
- uses: actions/checkout@v7
- run: ./deploy.shA second deploy waits as pending while the first one runs, and a third one cancels the pending second. GitHub describes the result as a maximum of one running and one pending job in the group. ./deploy.sh stands for your own deploy steps.
If every run has to execute, in sequence and with none canceled, opt in to queuing:
concurrency:
group: production-deploy
queue: maxWorkflow level versus job level
At the workflow level, the group covers the whole run. The group expression can use the github, inputs and vars contexts.
At the job level, only that job is held as pending, and the other jobs in the workflow proceed. The expression can also use the needs, strategy and matrix contexts.
cancel-in-progress accepts an expression too. GitHub's example cancels in-progress runs on every branch that is not a release branch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ !contains(github.ref, 'release/')}}Pushes to a release/1.2.3 branch do not cancel in-progress runs. Pushes to another branch, such as main, do.
Mistakes to avoid
- Expecting a queue by default. One run can be pending. A newer run replaces it unless the group sets
queue: max. - One group name in two workflows. Put
github.workflowin the name unless the workflows are meant to share the group. - Expecting the environment to limit runs. GitHub states that
concurrencyandenvironmentare not connected. A workflow that uses the same environment and does not specifyconcurrencyis not subject to any concurrency rules. Give every workflow that deploys to the environment the same group name. - The same group in a reusable workflow and its caller. A called workflow has its caller's name in
github.workflow. If both use it as the group withcancel-in-progress: true, the caller is canceled when the called workflow runs.
Sources
Want a second pair of eyes on yours? We do this work for a living.
More guides

GitHub environments: approvals, secrets and deployment rules
CI/CD · 4 min read
Required reviewers, wait timers, branch rules and secrets that a job gets only after approval.

GitHub Actions minutes: where they go and how to cut them
CI/CD · 4 min read
How runner time is billed, and the settings that reduce it.

Database migrations in a pipeline: expand, then contract
CI/CD · 4 min read
Change a schema in phases, run the migration as its own step, and keep PostgreSQL locks short.