Skip to content
Merged
Show file tree
Hide file tree
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
17 changes: 8 additions & 9 deletions .github/workflows/conflict-label.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
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:

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:
Expand All @@ -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"
3 changes: 1 addition & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
9 changes: 7 additions & 2 deletions tests/test_pr_conflict_label.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,14 @@ def setUp(self):
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)
Expand Down
7 changes: 3 additions & 4 deletions tools/pr_conflict_label.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading