Skip to content

Limit GHA to one active build per workflow/branch #305

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

Merged
merged 2 commits into from
Jan 11, 2023
Merged

Conversation

pirj
Copy link
Member

@pirj pirj commented Jan 10, 2023

This PR ensures that only the last execution per branch always works, even when pushed multiple times in a row, for example. The older one is canceled.

I find myself pushing often, and with many jobs the GHA limit them to a certain amount of concurrently running jobs.
This limit is applied per-org, so if there's a running rspec-rails build means the rspec-core build jobs will spin in a queued state until the first build jobs start to release job slots.

Refs:

Credit for this feature that went under my radar goes to @ydah

This PR ensures that only the last execution per branch always works,
even when pushed multiple times in a row, for example. The older one is
canceled.

Refs: https://docs.github.com/en/actions/using-jobs/using-concurrency
https://github.blog/changelog/2021-04-19-github-actions-limit-workflow-run-or-job-concurrency/
@pirj pirj self-assigned this Jan 10, 2023
@pirj pirj requested a review from JonRowe January 10, 2023 21:50
Copy link
Member

@JonRowe JonRowe left a comment

Choose a reason for hiding this comment

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

You'll also want to add this to the maintenance branch

@pirj
Copy link
Member Author

pirj commented Jan 11, 2023

Added one small change to only cancel PR builds, and allow for multiple simulataneousmain builds.

See rubocop/rubocop#11414 for more context.

@pirj pirj merged commit 74db8fd into main Jan 11, 2023
@pirj pirj deleted the ci-use-concurrency branch January 11, 2023 16:02
@pirj pirj restored the ci-use-concurrency branch January 11, 2023 17:15
@pirj pirj deleted the ci-use-concurrency branch January 11, 2023 17:16
@JonRowe
Copy link
Member

JonRowe commented Jan 12, 2023

Great 👍

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.

None yet

2 participants