workflows/labels: fix race condition with throttling

When we switched to a scheduled workflow, we also changed these lines to
take the labels directly from the pull request list we iterate over. At
the time it saved us an API request. Meanwhile, we have introduced
throttling to the workflow and this causes a potential race condition:

When the scheduled or manually triggered workflow is kicked off and
empties its reservoir of API requests it might be blocked to wait up
to.. an hour! If this happens, the labels taken from the pull request
list might already be outdated at the time the workflow continues. This
would cause some labels to be reset to their original state, which could
be wrong if, for example, another push has happened in the meantime.

This will have a much bigger impact after the next commit, where *all*
labels are set every time, thus the `before` part must be accurate.

Fetching the current labels right before managing them reduces this risk
significantly.

(cherry picked from commit 9581b0c55b)
This commit is contained in:
Wolfgang Walther
2025-06-18 18:19:49 +02:00
committed by github-actions[bot]
parent 42fdf6c64d
commit 21584659f5

View File

@@ -186,7 +186,11 @@ jobs:
// Get all currently set labels that we manage
const before =
pull_request.labels.map(({ name }) => name)
(await github.paginate(github.rest.issues.listLabelsOnIssue, {
...context.repo,
issue_number: pull_request.number
}))
.map(({ name }) => name)
.filter(name =>
name.startsWith('10.rebuild') ||
name == '11.by: package-maintainer' ||