C.W.K.
Stream
Lesson 05 of 14 · published

Concurrency

~10 min · concurrency, cancel, groups

Level 0Apprentice
0 XP0/101 lessons0/10 achievements
0/120 XP to next level120 XP to go0% complete

Stop wasting minutes on stale commits

If you push 10 times in 5 minutes, the default behavior is 10 parallel runs of CI. Nine of them are obsolete the moment they start. concurrency: declares a group; only one run per group can be active at a time, and you choose what happens when a new run starts in an active group.

Two settings

  • group: — a string template that identifies the group. Common: ${{ github.workflow }}-${{ github.ref }} (one run per workflow per branch).
  • cancel-in-progress: — true cancels the running one to start the new; false queues the new one.

Pick the right group

  • PR feedback — group on github.ref; cancel-in-progress true. New push obsoletes old run.
  • Deploy — group on environment name; cancel-in-progress false. Two deploys to the same env serialize.
  • Release — group on github.workflow; cancel-in-progress false. Releases queue, never overlap.

Code

Three concurrency strategies·yaml
# 1) PR feedback — cancel old runs
concurrency:
  group: ci-${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

# 2) Deploy — serialize, no cancel (mid-deploy cancellation is dangerous)
concurrency:
  group: deploy-${{ github.event.inputs.environment || 'staging' }}
  cancel-in-progress: false

# 3) Release — single global queue
concurrency:
  group: release
  cancel-in-progress: false

External links

Exercise

Add concurrency to your CI workflow with cancel-in-progress, and a separate deploy workflow with serialize-only. Push twice quickly to CI; verify the first is cancelled. Trigger two deploys; verify the second queues.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.