Older workflow runs overriding newer deployments when pushing multiple commits quickly #199398
🏷️ Discussion TypeBug 💬 Feature/Topic AreaARC (Actions Runner Controller) Discussion DetailsHey everyone, Ran into a massive headache with our GitHub Actions deployment pipeline today and wanted to see if anyone has a clean workaround. Our workflow is set up to build and deploy our frontend to AWS S3 whenever code is pushed to the main branch. Today, a teammate pushed a hotfix, and then immediately pushed a quick typo fix about 30 seconds later. Because the first run (the hotfix) took slightly longer to build due to a cold cache, it ended up finishing after the typo fix run. This completely overrode the typo fix on the live site with the older build. Obviously, having older commits override newer ones in production is a nightmare. Is there a built-in way in GitHub Actions to automatically kill or queue older runs if a newer push happens? |
Replies: 2 comments
|
💬 Your Product Feedback Has Been Submitted 🎉 Thank you for taking the time to share your insights with us! Your feedback is invaluable as we build a better GitHub experience for all our users. Here's what you can expect moving forward ⏩
Where to look to see what's shipping 👀
What you can do in the meantime 💻
As a member of the GitHub community, your participation is essential. While we can't promise that every suggestion will be implemented, we want to emphasize that your feedback is instrumental in guiding our decisions and priorities. Thank you once again for your contribution to making GitHub even better! We're grateful for your ongoing support and collaboration in shaping the future of our platform. ⭐ |
|
Oh man, the classic deployment race condition. I had this exact nightmare burn down a production release before we fixed it. The good news is you don’t need to write any complex scripts to fix this. GitHub actually added a built-in feature specifically for this scenario called concurrency. You can group your workflow runs together and tell GitHub to automatically cancel any older, in-progress runs the second a new push comes in. The Fix Here is exactly how to set it up: on: This is the magic snippet right here 👇 jobs: group: This names the bottleneck. By using ${{ github.workflow }}-${{ github.ref }}, you are ensuring that this rule only applies to runs of this specific workflow on this specific branch. cancel-in-progress: true: This is the killer setting. The moment you push Commit B, GitHub looks at the group name. If it sees Commit A is still running under that same group name, it immediately terminates Commit A on the spot and lets Commit B run. 💡 One quick warning: Only use cancel-in-progress: true on workflows where it's safe to interrupt the steps mid-way (like builds or tests). If your workflow actually alters database states or state files (like Terraform), you might want to leave cancel-in-progress out so they just queue up sequentially instead of cutting off mid-migration. Drop that into your YAML and you won't have to worry about out-of-order deployments again! |
Oh man, the classic deployment race condition. I had this exact nightmare burn down a production release before we fixed it.
The good news is you don’t need to write any complex scripts to fix this. GitHub actually added a built-in feature specifically for this scenario called concurrency.
You can group your workflow runs together and tell GitHub to automatically cancel any older, in-progress runs the second a new push comes in.
The Fix
All you need to do is add a concurrency block right at the top of your workflow YAML file (below your on: triggers).
Here is exactly how to set it up:
on:
push:
branches:
- main
This is the magic snippet right here 👇
concurrency:
gro…