Adding Concurrency Cancellation to GitHub Actions Workflows to Save CI Minutes
Adding Concurrency Cancellation to GitHub Actions Workflows to Save CI Minutes TL;DR: I added the concurrency feature with cancel-in-progress to the CI and E2E GitHub Actions workflows of the lavanderia-crm repo. This prevents overlapping runs on the same branch/PR, cutting down wasted minutes and keeping the pipeline fast. The Problem Our CI pipeline ( .github/workflows/ci.yml ) and the nightly…
The author added concurrency cancellation to GitHub Actions workflows to save CI minutes by preventing overlapping runs on the same branch or pull request. The CI and E2E GitHub Actions workflows of the lavanderia-crm repository were previously triggered on every push, even when a previous run for the same branch was still executing, causing wasted minutes and slower pipelines.
The author first tried a manual gate using if conditions but found it had race conditions and state persistence issues. After researching, they discovered the concurrency feature introduced by GitHub Actions. By adding the concurrency keyword with cancel-in-progress set to true, any in-flight run with the same key is automatically cancelled when a new run is queued.
They updated the ci.yml and e2e-production.yml workflows to include concurrency group keys based on the branch name or pull request. This ensures each branch has its own concurrency group, preventing multiple parallel jobs from fighting for resources. The implementation resulted in only one active run at a time, with previous runs automatically cancelled when a new one is queued.
The author verified the change by pushing multiple pushes to a feature branch and observing only one active run. A similar behavior was observed for the nightly e2e-production workflow when a push to main occurred while a nightly run was still processing. The key takeaway is that concurrency with cancel-in-progress is a lightweight, built-in way to de-duplicate workflow runs, reducing CI cost without sacrificing test coverage.
Future improvements include adding Slack notifications for cancelled runs, fine-tuning concurrency groups for matrix jobs, and monitoring saved minutes via the GitHub Billing API to quantify the return on investment.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.
This story
This is one outlet's version. Read the fullest account.