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

ci: Limit concurrent workflow jobs to one per workflow per branch #1632

Merged
merged 9 commits into from
Jan 5, 2022

Conversation

matthewfeickert
Copy link
Member

@matthewfeickert matthewfeickert commented Oct 13, 2021

Description

Resolves #1631

Use GitHub Actions concurrency key with cancel-in-progress option to limit the number of concurrent workflow jobs to one per workflow per github.head_ref github.ref (so per branch which results in per PR). This should speed up CI by keeping the queue clear by canceling CI jobs when another commit has been pushed that would kick off the same workflow.

Example:

  • On a PR a commit is pushed that doesn't pass the pre-commit checks.
  • pre-commit.ci pushes back the changes that allows for pre-commit to pass.
  • There would now be two jobs running for all the GHA workflows that run per PR, which is wasteful and slows things down.
  • With
concurrency:
  group: some-identifying-string-${{ github.ref }}
  cancel-in-progress: true

the offending first workflow job is canceled and the second workflow job from pre-commit.ci's push can start.

Checklist Before Requesting Reviewer

  • Tests are passing
  • "WIP" removed from the title of the pull request
  • Selected an Assignee for the PR to be responsible for the log summary

Before Merging

For the PR Assignees:

  • Summarize commit messages into a comprehensive review of the PR
* Add concurrency groups to all workflows that run on PRs
   - Use 'cancel-in-progress' option to cancel already running workflow jobs
   - This should speed up CI by keeping the queue clear by canceling CI jobs
      when another commit has been pushed that would kick off the same
      workflow
   - https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#concurrency

@matthewfeickert matthewfeickert added the CI CI systems, GitHub Actions label Oct 13, 2021
@matthewfeickert matthewfeickert self-assigned this Oct 13, 2021
@matthewfeickert matthewfeickert force-pushed the ci/limit-with-concurency branch from acd32f3 to 3e1bcaa Compare October 13, 2021 03:22
@matthewfeickert
Copy link
Member Author

I rebased off of master for this PR and the already running jobs got canceled as expected. 👍

@matthewfeickert matthewfeickert changed the title ci: Limit number of concurrent workflow jobs to one per workflow per branch ci: Limit concurrent workflow jobs to one per workflow per branch Oct 13, 2021
@codecov
Copy link

codecov bot commented Oct 13, 2021

Codecov Report

Merging #1632 (a074d8a) into master (f94e72f) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1632   +/-   ##
=======================================
  Coverage   98.12%   98.12%           
=======================================
  Files          64       64           
  Lines        4270     4270           
  Branches      683      683           
=======================================
  Hits         4190     4190           
  Misses         46       46           
  Partials       34       34           
Flag Coverage Δ
contrib 26.25% <ø> (ø)
doctest 60.58% <ø> (ø)
unittests 96.18% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.


Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f94e72f...a074d8a. Read the comment docs.

@matthewfeickert
Copy link
Member Author

matthewfeickert commented Oct 13, 2021

Oh. I just realized this might be problematic for our release workflow as the tag workflow executes and pushes to master very quickly after we merge a release triggering PR.

Example:

commit 248e40072ca933813214ada3fd79b10633ffef1d (tag: v0.6.3)
Author: GitHub Action <[email protected]>
Date:   Fri Sep 3 18:53:29 2021 +0000

    Bump version: 0.6.2 → 0.6.3
    
    Triggered by #1583 via GitHub Actions.

commit 5a56b28f59ec0518b42116c422583c48267a6745
Author: Matthew Feickert <[email protected]>
Date:   Fri Sep 3 13:53:09 2021 -0500

    docs: Add v0.6.3 release notes (#1583)
    
    * Add release notes for pyhf v0.6.3
       - c.f. https://github.com/scikit-hep/pyhf/releases/tag/v0.6.3
    * Update link to uproot in README to point to uproot4 GitHub repo
    * Add Sviatoslav Sydorenko as a contributor

for v0.6.3 the tag workflow push with tag v0.6.3 happened just 20 seconds (note +0000 vs. -0500) after we merged the release triggering PR.

As

github.head_ref: The head_ref or source branch of the pull request in a workflow run. This property is only available when the event that triggers a workflow run is either pull_request or pull_request_target.

does that mean that on push_events to master

concurrency:
  group: ci-${{ github.head_ref }}
  cancel-in-progress: true

will evaluate the group to ci? Or does concurrency not exist for push_events?

@kratsg
Copy link
Contributor

kratsg commented Oct 13, 2021

does that mean that on push_events to master

concurrency:
  group: ci-${{ github.head_ref }}
  cancel-in-progress: true

will evaluate the group to ci? Or does concurrency not exist for push_events?

isn't the head_ref for a tag the tag name, rather than the branch?

@matthewfeickert
Copy link
Member Author

isn't the head_ref for a tag the tag name, rather than the branch?

Apparently not, as the github context docs say that

github.head_ref: The head_ref or source branch of the pull request in a workflow run. This property is only available when the event that triggers a workflow run is either pull_request or pull_request_target.

github.ref: The branch or tag ref that triggered the workflow run. For branches this is the format refs/heads/<branch_name>, and for tags it is refs/tags/<tag_name>.

@matthewfeickert matthewfeickert force-pushed the ci/limit-with-concurency branch from 2045d29 to ee74132 Compare December 10, 2021 20:48
@kratsg kratsg merged commit 9018a3a into master Jan 5, 2022
@kratsg kratsg deleted the ci/limit-with-concurency branch January 5, 2022 20:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI CI systems, GitHub Actions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use GitHub Actions 'concurrency' option to cancel all but latest workflow on PRs
2 participants