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

GitHub Actions CI template: do not skip intermediate builds on the main, master, or release-* branches #341

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all 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
6 changes: 3 additions & 3 deletions templates/github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ on:
pull_request:
workflow_dispatch:
concurrency:
# Skip intermediate builds: always.
# Cancel intermediate builds: only if it is a pull request build.
group: ${{ github.workflow }}-${{ github.ref }}
# Skip intermediate builds: all builds except for builds on the `main`, `master`, or `release-*` branches
# Cancel intermediate builds: only pull request builds
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.ref != 'refs/heads/main' || github.ref != 'refs/heads/master' || startsWith(github.ref, 'refs/heads/release-') || github.run_number }}
Copy link
Collaborator

Choose a reason for hiding this comment

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

can you explain a little more what this does? I read https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#concurrency but I'm still a bit confused

Copy link
Member Author

Choose a reason for hiding this comment

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

So, roughly speaking, if two separate builds have the same concurrency group value, then the second build will have to wait until the first build has completed. Additionally, if three builds all have the same concurrency group value, then while the first build is happening, the second and third build will have to wait, but once the first build has completed, the second build will be completely skipped, and the third build will start.

This is good for PRs, but usually it is undesirable to not run CI on every commit pushed to main or master. Therefore, for commits on main, master, and release-*, we create a unique concurrency group value. This ensures that two different commits on main never have the same concurrency group value, and thus builds on main are never skipped.

For commits on PRs, two separate commits on the same PR will have the same concurrency group value. Therefore, if multiple commits are pushed to a PR, we can skip CI on the intermediate commits, and only run CI on the latest commit of the PR, since that is the code that we actually care about.

cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}
jobs:
test:
Expand Down
Loading