ci: the needs-rebase labeler no longer runs per pull request push (PR-CONFLICT-LABEL-LOAD)

conflict-label.yml (#155) started a run on every push to every pull
request through pull_request_target. On this repository that queued 265
runs within a day, some waiting five hours, in the same runner queue as
CI, No Game Data and Runtime, whose oldest queued run waited six hours.

Drop the pull_request_target trigger and put every run in one
concurrency group. Each run already checks every open pull request, so
a push to main and the hourly schedule cover what the per-PR runs did;
a rebased pull request loses the label within the hour instead of at
once. At most one run waits at a time. The workflow also no longer has a
trigger that hands a fork's pull request a write token.

tests/test_pr_conflict_label.py fails on the old workflow and checks
that no pull request trigger, per-PR group or --pr comes back; the tool's
docstring and CONTRIBUTING.md say what runs it now.
This commit is contained in:
Mouad-Scriptz-0
2026-11-24 20:51:58 +00:00
parent 66d4f5aa36
commit 364754de5c
4 changed files with 19 additions and 17 deletions

View File

@ -1,16 +1,15 @@
name: Needs rebase label
# Labels the open pull requests that conflict with main `needs rebase` and unlabels them once they merge again
# (tools/pr_conflict_label.py). A push to main can make any open pull request conflict, so it checks all of them; a
# push to a pull request checks that one; the hourly run catches merges GitHub had not computed yet.
# (tools/pr_conflict_label.py). A push to main can make any open pull request conflict, so it checks all of them;
# the hourly run catches a rebase and any merge GitHub had not computed yet.
#
# pull_request_target gives a fork's pull request a token that can write labels. That is safe only because this job
# checks out main, never the pull request, and the tool reads nothing but the GitHub API: no pull request code runs.
# There is no pull request trigger. One run per push to every pull request queued hundreds of runs here, ahead of
# the builds and tests that share the repository's runners; checking all of them per push to main and per hour keeps
# at most one run waiting. The job checks out main and reads only the GitHub API: no pull request code runs.
on:
push:
branches: [main]
pull_request_target:
types: [opened, reopened, synchronize]
schedule:
- cron: '17 * * * *'
workflow_dispatch:
@ -18,7 +17,8 @@ on:
permissions: {}
concurrency:
group: conflict-label-${{ github.event.pull_request.number || 'all' }}
# One run at a time and one waiting; a newer push replaces the waiting one, since each run checks every pull request.
group: conflict-label
cancel-in-progress: false
jobs:
@ -37,5 +37,4 @@ jobs:
- name: Label conflicting pull requests
env:
GITHUB_TOKEN: ${{ github.token }}
PR: ${{ github.event.pull_request.number }}
run: python3 -I tools/pr_conflict_label.py --repo "$GITHUB_REPOSITORY" ${PR:+--pr "$PR"}
run: python3 -I tools/pr_conflict_label.py --repo "$GITHUB_REPOSITORY"

View File

@ -81,5 +81,4 @@ number and links nowhere now, including the two this page used to send you to: #
- Fill in the [template](.github/pull_request_template.md): the claim, `Depends on:`, `Fixes: #N` for an issue it
closes, what you tested, `GPUs tested:` (vendor, model, driver and OS) and whether it was AI-assisted.
- A pull request that conflicts with `main` is labeled `needs rebase` (`tools/pr_conflict_label.py`, run on every
push to `main` and to the pull request, and hourly). Rebase it on `main` yourself; the label goes once it merges
cleanly. Reviews start with the pull requests that do.
push to `main` and hourly). Rebase it on `main` yourself; the label goes within the hour once it merges cleanly. Reviews start with the pull requests that do.

View File

@ -140,9 +140,14 @@ class WorkflowTest(unittest.TestCase):
def test_runs_this_tool(self):
self.assertIn("python3 -I tools/pr_conflict_label.py", self.text)
def test_no_run_per_pull_request(self):
# A run per push to every pull request queued hundreds of runs ahead of the repository's builds and tests.
# Every run checks all pull requests, so one concurrency group keeps at most one waiting.
self.assertNotRegex(self.text, r"(?m)^\s+pull_request(_target)?\s*:")
self.assertRegex(self.text, r"(?m)^\s+group:\s*conflict-label\s*$")
self.assertNotIn("--pr", self.text)
def test_never_checks_out_pull_request_code(self):
# pull_request_target runs with a write token; checking out the head would run untrusted code with it.
self.assertIn("pull_request_target", self.text)
self.assertNotRegex(self.text, r"github\.event\.pull_request\.head|github\.head_ref|refs/pull/")
self.assertRegex(self.text, r"ref:\s*\$\{\{\s*github\.event\.repository\.default_branch\s*\}\}")
self.assertIn("persist-credentials: false", self.text)

View File

@ -3,14 +3,13 @@
python -I tools/pr_conflict_label.py --repo OWNER/NAME [--pr N] [--dry-run]
`.github/workflows/conflict-label.yml` runs this on every push to `main` (a merge can make other pull requests
conflict), on a pull request being opened, reopened or pushed to (a rebase can clear a conflict), and hourly in case
GitHub had not finished computing a merge. Every pull request gets reviewed by hand; the label lets a reviewer skip
conflict) and hourly (a rebase can clear a conflict, and GitHub may not have finished computing a merge). It has no
per-pull-request trigger: one run per push to every pull request flooded the repository's runners. Every pull request gets reviewed by hand; the label lets a reviewer skip
the ones that cannot be merged as they stand and tells their authors to rebase.
GitHub computes `mergeable` in the background and answers `null` until it has, so a pull request whose answer is
still unknown is asked again a few times and otherwise left as it is for the next run. Only the GitHub REST API is
read and written: no pull request code is checked out or run, which is what makes the `pull_request_target` trigger
safe here. The token comes from `GITHUB_TOKEN` (or `GH_TOKEN`); `--dry-run` prints the changes and writes nothing.
read and written: no pull request code is checked out or run. The token comes from `GITHUB_TOKEN` (or `GH_TOKEN`); `--dry-run` prints the changes and writes nothing.
Standard library only; no game files.
"""
import argparse