-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
chore: auto cancel previous branch or PR runs #16076
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
acolombier
wants to merge
2
commits into
mixxxdj:2.6
Choose a base branch
from
acolombier:chore/auto-cancel-new-pushes
base: 2.6
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's a Gemini Pro review, does this make sense?
A Minor Optimization to Consider (The github.ref Gotcha)
The code you provided uses this group logic:
This will work fine, but there is a slight quirk with how GitHub Actions handles github.ref:
github.refevaluates to something likerefs/heads/feature-branch.github.refevaluates to a system ref likerefs/pull/123/merge.Because these refs are different, if a contributor pushes a new commit to a branch that currently has a PR open, GitHub Actions actually fires two workflows in two different concurrency groups.
GitHub's widely recommended best practice to group these together seamlessly is to use
github.head_ref || github.ref:Why this is better:
github.head_refis only available during pull_request events and contains the actual branch name (e.g.,feature-branch). If it's a standard push event, it falls back togithub.ref. This ensures that PR updates and direct branch pushes are grouped together much more cleanly, reducing the chance of edge-case race conditions where a PR build and a push build try to run at the same time.Combined with your
stop-buildscript, either method will successfully save you CI time, but thegithub.head_refaddition is the standard way to make it bulletproof.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have previously decided that push trigger and pull request trigger are separated and should run independently.
By default, we have already made it so if one has a PR open for a given branch, the CI will not run. This allows contributor that matures the work in branches before submitting a PR to still get the automation to work.
Now, Gemini suggestion wouldn't work anyway because the concurrency group is specific to the repo. In other term, the PR one would be as
mixxxdj/mixxx:${{ github.workflow }}-${{ github.ref }}, and the branch push would beronso0/mixxx:${{ github.workflow }}-${{ github.ref }}, so both wouldn't cancel each otherThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, thanks for the explanation (though must admit that I'm not into it to fully understand everything).