chore: rerun CI only when full-ci label is added or removed #4136
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Previously, the CI would run upon every label addition, including things like
builds-mathlib
or
will-merge-soon
, possibly triggering a new PR release, new mathlib builds etc. Very wasteful!Unfortunately (but not surprisingly) Github does not offer a nice way of saying
“this workflow depends on that label, please re-run if changed”. Not enough
functional programmer or nix enthusiasts there, I guess…
So here is the next iteration trying to work with what we have from Github:
A new workflow watches for (only)
full-ci
label addition or deletion, and then re-runsthe CI job for the current PR.
Sounds simple? But remember, this is github!
github.event.pull_request.labels.*.name
is not updated when a job is re-run.(This is actually a reasonable step towards determinism, but doesn't help us
constructing this work-around.)
Ok, so let’s use the API to fetch the current state of the label.
There is no good way to say “find the latest run of workflow
"CI"
on PR$n
”.The best approximation seems to search by branch and triggering event. This can
probably go wrong if there are multiple PRs from different repos with the same
head ref name (
patch-1
anyone?). Let’s hope that it doesn’t happen too often.You cannot just rerun a workflow. You can only rerun a finished workflow. So cancel
it first. And
sleep
a bit…So let’s see how well this will work. It’s plausibly an improvement.