AI Hints
Home›CI/CD with GitHub Actions Tutorial›Concurrency and Practice
CI/CD with GitHub Actions · Lesson 55 of 138

Concurrency

One run at a time.

⏱ 2 min read▶ Video at 1:02:05🎓 Free
Watch this lesson in the CI/CD with GitHub Actions courseWatch on YouTube ↗Full CI/CD with GitHub Actions course

Imagine pushing three commits in a minute. Three runs start, and the first two are already out of date. Worse, two deploys could run at the same time, and fight each other. The concurrency key stops that.

Concurrency
From the video: Concurrency
  • Three quick pushes
  • Out-of-date runs
  • Deploys that fight

A concurrency group

Runs in the same group never run at the same time. The group name here includes the workflow and the branch, so each branch has its own queue. Cancel in progress, set to true, cancels the older run when a newer one starts, so you only pay for the latest commit.

.github/workflows/ci.ymlyaml
name: CI
on: push
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - run: pytest -q

When to cancel

For tests, cancelling older runs is great. Only the newest commit matters. For deployments, don't cancel a deploy halfway through, because that could leave a server half updated. Instead, use a group without cancel in progress, so deploys wait in line, one after another.

keyvalue
Testscancel-in-progress: true
Deploysqueue, don't cancel
Group nameworkflow + branch
Savesminutes and money

Summary

Concurrency groups stop runs from overlapping, and cancel in progress drops out of date runs. Next, choosing where and how steps run.

Key takeaways
  • concurrency: group
  • cancel-in-progress
  • Queue deploys
Next up: Working Directory and Shell — where and how steps run