🎓 A1Learner
🔍
0 of 50 lessons completed

GitHub Actions: Concurrency

Concurrency is a limit on how many runs of a workflow can run at the same time. It stops new pushes from piling up behind old runs, and it stops two deploys from clashing.

Cancel old test runs on a new push

A new push makes the old test run pointless. Cancel it and test the new code.

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

One deploy at a time

Two deploys at once can clash. This group lets only one deploy run, and it never cancels one.

concurrency:
  group: deploy-production
  cancel-in-progress: false

Example

name: Concurrency Demo

on: push

jobs:
  test:
    runs-on: ubuntu-latest
    concurrency:
      group: ${{ github.workflow }}-${{ github.ref }}
      cancel-in-progress: true
    steps:
      - uses: actions/checkout@v7
      - uses: actions/setup-node@v7
        with:
          node-version: '24'
      - run: npm test
  deploy:
    needs: test
    runs-on: ubuntu-latest
    concurrency:
      group: deploy-production
      cancel-in-progress: false
    steps:
      - run: echo "Deploying the tested code"

Key points

  • Concurrency: a limit on runs that may run at the same time.
  • Use a concurrency group to name the runs that share one limit.
  • Use cancel-in-progress true to stop the old run when a new one starts.
  • Use cancel-in-progress false for deploys so a deploy always finishes.
  • Use github.workflow and github.ref in a group name to limit per workflow and branch.
  • A concurrency group is one limit shared by the runs that name it.

In this example, the workflow runs on every push. The test job uses a group named after the workflow and the branch. A new push cancels the old test run. The deploy job needs the tests to pass. It uses the deploy-production group. That group never cancels a deploy. It waits, then prints its message.

Try it Yourself

Edit the code, then press Run.

Running is simulated · Rust Playground

Exercise

Why should a deploy concurrency group use cancel-in-progress false?