Skip to content
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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

franciszekjob
Copy link
Collaborator

@franciszekjob franciszekjob commented Jan 6, 2025

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

  • Linked relevant issue
  • Updated relevant documentation
  • Added relevant tests
  • Performed self-review of the code
  • Added changes to CHANGELOG.md

@franciszekjob franciszekjob changed the title Allow cancel-in-progress except for master Allow cancel-in-progress Jan 6, 2025
@@ -8,6 +8,10 @@ on:
- master
workflow_dispatch:

concurrency:
group: ${{ github.head_ref }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

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

Copy link
Collaborator

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

@franciszekjob franciszekjob requested a review from cptartur January 7, 2025 15:25
@@ -8,6 +8,10 @@ on:
- master
workflow_dispatch:

concurrency:
group: ${{ github.head_ref || github.run_id }}
cancel-in-progress: ${{ github.head_ref != 'master' }}
Copy link
Contributor

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?

Copy link
Member

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?

Copy link
Collaborator Author

@franciszekjob franciszekjob Jan 10, 2025

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 master
  • github.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 ?

Copy link
Member

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?

Copy link
Contributor

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' }}

Copy link
Collaborator Author

@franciszekjob franciszekjob Jan 10, 2025

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

Copy link
Contributor

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?

Copy link
Collaborator Author

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.

Copy link
Collaborator

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 master
  • github.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

Copy link
Contributor

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

Copy link
Member

@cptartur cptartur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants