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

Replace styfle/cancel-workflow-action with new GitHub concurrency: standard #2316

Merged
merged 4 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ env:
GRADLE_BUILD_ACTION_CACHE_DEBUG_ENABLED: true
GRADLE_BUILD_ACTION_CACHE_KEY_PREFIX: "fhir" # change this to invalidate cache

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref || github.run_id }}
Copy link
Collaborator

Choose a reason for hiding this comment

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

if the run_id is included here in the group id, does this not mean that each run will have a separate group id? and does that mean previous runs will not be cancelled?

actually, if the head_ref is part of this, how would cancellation even help anything? shouldn't we cancel jobs that are in the same branch? i.e. if you push a new commit we should cancel the previous job?

Copy link
Member Author

Choose a reason for hiding this comment

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

I now had a closer look at related docs about this (e.g. https://docs.github.com/en/actions/using-jobs/using-concurrency and https://docs.github.com/en/actions/learn-github-actions/contexts#github-context) and, as far as I understand it, believe this to be correct as-is, because:

  • those || are fallback values (not "concatenations") so my understanding is that e.g. the run_id would not be included as long as a head_ref or else ref was non-NIL
  • the head_ref is (quote) "the source branch of the pull request in a workflow run" - which will (should, based on doc) cancel jobs that are in the same branch - I think? But note that, quote: "This property is only available when the event that triggers a workflow run is either pull_request or pull_request_target." ...
  • ... so the ref is a fallback to (quote) "(...) For workflows triggered by push, this is the branch or tag ref that was pushed (...) " From the doc it seems like it may actually be sufficient to use only this, but given that http://go/github-actions#cancel-workflows suggests to use the combination, I went with that; I suspect it can't harm to be double extra safe
  • lastly, the run_id is a last fallback is something I thought I saw on some example yesterday. I'm not sure if this will be used, but given that ref docs says that it's "only set if a branch or tag is available for the event type" it seems like a sensible pre-caution as a last resort? I can also remove it, if you think it's confusing?

Copy link
Collaborator

@jingtang10 jingtang10 Oct 30, 2023

Choose a reason for hiding this comment

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

thanks michael for the explanation.

this is clear to me now.

up to you about the run_id. but either way can we add a single line of comment to explain what's happening here? doesn't have to go to the length of your comment above, but just noting that we're using the branch/pr ref etc so possible to cancel previous runs.

Copy link
Collaborator

Choose a reason for hiding this comment

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

once addressed please feel free to merge.

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed github.run_id and added inline documentation comments; I will self merge when build is green.

cancel-in-progress: true

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# Build will compile APK, test APK and run tests, lint, etc.
Expand All @@ -49,10 +53,6 @@ jobs:

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- name: Cancel previous
uses: styfle/cancel-workflow-action@0.12.0
with:
access_token: ${{ github.token }}

# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- name: Checkout Repo
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/codeql.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ on:
schedule:
- cron: '32 13 * * 2'

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref || || github.run_id }}
cancel-in-progress: true

jobs:
analyze:
name: Analyze
Expand Down
Loading