-
Notifications
You must be signed in to change notification settings - Fork 196
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
Allow cancel-in-progress #2825
base: master
Are you sure you want to change the base?
Allow cancel-in-progress #2825
Conversation
master
.github/workflows/ci.yml
Outdated
@@ -8,6 +8,10 @@ on: | |||
- master | |||
workflow_dispatch: | |||
|
|||
concurrency: | |||
group: ${{ github.head_ref }} |
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.
For example, github.head_ref is only defined on pull_request events.
Won't this cause problems?
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.
Right, it looks like we should add github.run_id
as fallback
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.
github.run_id
is different for each workflow run, so grouping won;t be proper
@@ -8,6 +8,10 @@ on: | |||
- master | |||
workflow_dispatch: | |||
|
|||
concurrency: | |||
group: ${{ github.head_ref || github.run_id }} | |||
cancel-in-progress: ${{ github.head_ref != 'master' }} |
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.
If github.head_ref
is only defined for a pull_request event, isn't this condition always true? Should we use github.ref_name
or something else here?
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.
Perhaps ${{ !!github.head_ref }}
would work?
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.
It looks to me such configuration will be sufficient:
concurrency:
group: ${{ github.head_ref || github.ref_name }}
cancel-in-progress: ${{ (github.head_ref && github.head_ref != 'master') || (github.ref_name && github.ref_name != 'master') }}
Workflow will be canceled in two cases:
github.head_ref
is defined (PR) and it's not mastergithub.ref_name
is defined (commits on branch) and it's not master
Workflow won't be cancelled if action applies to master. And basically that's all we need.
Wdyt @ddoktorski @cptartur ?
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.
I think it should be okay. Though if head_ref
is pretty much only defined for pull requests, shouldn't it be sufficient to just check if it's defined?
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.
Maybe keep it simple?
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
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.
I think it should be okay. Though if
head_ref
is pretty much only defined for pull requests, shouldn't it be sufficient to just check if it's defined?
Maybe keep it simple?
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
Checking only if head_ref
or github.event_name == 'pull_request'
will not cancel CI runs without a PR so I think we should leave both. @cptartur @ddoktorski
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.
will not cancel CI runs without a PR
What are other cases in which we want to cancel it other than PRs?
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.
For instance when someone doesn't open a PR but has a branch and pushes commits to it.
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.
It looks to me such configuration will be sufficient:
concurrency: group: ${{ github.head_ref || github.ref_name }} cancel-in-progress: ${{ (github.head_ref && github.head_ref != 'master') || (github.ref_name && github.ref_name != 'master') }}Workflow will be canceled in two cases:
github.head_ref
is defined (PR) and it's not mastergithub.ref_name
is defined (commits on branch) and it's not master
Workflow won't be cancelled if action applies to master. And basically that's all we need.Wdyt @ddoktorski @cptartur ?
I suppose that we can skip head_ref
because there will always be only one workflow in this group (triggered by pr), group: ${{ github.ref_name }}
should be sufficient
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.
For instance when someone doesn't open a PR but has a branch and pushes commits to it.
CI doesn't run in such cases anyway
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.
See my comment
Closes #
Introduced changes
This configuration enables the cancellation of previous workflow runs when a new commit is pushed to the same branch, optimizing CI resource usage (except for
master
)Checklist
CHANGELOG.md