diff --git a/.github/scripts/fork-head-gate-workflow.test.py b/.github/scripts/fork-head-gate-workflow.test.py index 57c993c288a28..65c269c47609f 100644 --- a/.github/scripts/fork-head-gate-workflow.test.py +++ b/.github/scripts/fork-head-gate-workflow.test.py @@ -424,6 +424,27 @@ def caller_group(event, run_id, sha="", workflow_ref="o/p/.github/workflows/gate "caller's run (the gate job's own group is per head: a newer job there reads the newest state)", lost == [("review", 2)], str(lost)) +# #379: the review trigger's live check is a written setup step, and the release notes tell a pin move what to copy. +# The fields the lookup relies on are tested above only against fakes, so whoever sets the trigger up checks them once. +readme = (root / "fork-ci/actions/head-check/README.md").read_text() +setup = readme[readme.find("\nSetup ("):] +setup = setup[:setup.find("\n\n", setup.find("\n8. "))] if "\n8. " in setup else "" +check("README setup: step 8 is the live check (post a review, the gate runs; the warning that says the fields differ)", + "post a review on one" in setup and "review run: #N has the head" in setup + and "does not name a head" in setup and "head=owner:branch" in setup and "fallback" in setup, setup[-300:]) +gate_src = GATE_PY.read_text() +check("README setup: the warning it names is head_gate's own text", + "the review trigger's run does not name a head" in setup.replace("\n ", " ") + and "the review trigger's run does not name a head" in gate_src) +notes = (root / "fork-ci/RELEASE-NOTES.md").read_text() +entry = next((e for e in notes.split("\n### ")[1:] if "review-trigger.example.yml" in e and "#375" in e.split("\n")[0]), + "") +upgrade = entry[entry.find("**Upgrade:**"):] if "**Upgrade:**" in entry else "" +check("release notes: the review trigger has an entry whose Upgrade copies the trigger and the caller's workflow_run, " + "if and concurrency, pin first, then the live check (setup step 8)", + all(w in upgrade for w in ("review-trigger.example.yml", "gate-caller.example.yml", "`workflow_run`", "`if`", + "`concurrency`", "pinned to an older release", "setup step 8")), upgrade[:300]) + if failures: print(f"\n{len(failures)} failed") sys.exit(1) diff --git a/fork-ci/RELEASE-NOTES.md b/fork-ci/RELEASE-NOTES.md index 1ba07d38a3759..76d23445c9c99 100644 --- a/fork-ci/RELEASE-NOTES.md +++ b/fork-ci/RELEASE-NOTES.md @@ -242,6 +242,25 @@ then behind, and the update that brings it up to date is a new head, judged on t refuses the fix too ("not JSON"), and an owner has to push the fix by hand, as for any base config that does not parse. +### head-check gate: reviews and inline review comments run the gate again (#375, #392, #379) + +A new example workflow, `review-trigger.example.yml` ("Head gate review trigger"), runs on reviews and inline review +comments and does nothing but finish. The gate caller runs on `workflow_run` of it and judges the head of the open pull +request whose head branch, head repository and head sha are the run's (the number comes from the API, never from the +run). Two open pull requests on one head (one branch into two bases) are judged once, in the job for the lowest number. +Before this, a review left the check showing the older answer until the next push or issue comment. First in `ci/v15`. +After `ci/v19` (#379), a review run whose head fields are missing or odd judges nothing with a warning (before: a plain +log line). + +**Upgrade:** nothing breaks if you only move the pin: a caller without the new trigger never runs on `workflow_run`. +To use it, in one pull request on the default branch, after the pin is at a release that has this entry: copy +`review-trigger.example.yml` to `.github/workflows/` unchanged, and add the caller's `workflow_run` trigger, its `if` +(with the event clause) and its `concurrency` from `gate-caller.example.yml`. The pin moves first or in that pull +request: a caller with `workflow_run` pinned to an older release is refused on that event (its guard job fails, nothing +is posted). Then do the +live check once ([head-check README](actions/head-check/README.md), setup step 8): post a review on one open pull +request and check that the gate ran for it. The GitHub fields the lookup uses are tested only against fakes. + ### pr-queue and head-check: stricter rule order in `review` (#378) A rule of the same weight above another rule that lacks one of its lenses is now a rule-order problem, and only the diff --git a/fork-ci/actions/head-check/README.md b/fork-ci/actions/head-check/README.md index 9db61e3bf65c8..356ada460850b 100644 --- a/fork-ci/actions/head-check/README.md +++ b/fork-ci/actions/head-check/README.md @@ -320,6 +320,17 @@ Setup (the repository owner's steps; nothing here creates them): ([pr-queue](../pr-queue/README.md)), so the queue counts only that App's check runs. Release the code first, then bump the pins, then add the key: an older queue refuses a key it does not know. +8. The live check, once, after the review trigger is in: post a review on one + open pull request and check that the gate ran for it. The caller's run on + `workflow_run` logs `review run: #N has the head …`, and the check run on + that head is new. The GitHub fields the lookup uses (the review run's head + branch, head repository and head sha, and the list filter + `head=owner:branch`) are tested only against fakes. If the run warns + "the review trigger's run does not name a head", or logs "no open pull + request has the head" for a review on an open pull request whose head did + not move, they differ: reviews then never run the gate again. Report it + on the fork and use the fallback (an issue comment or a dispatch, see + "Run again after a review") until it is fixed. After a change to the caller, a new pin, or a change to the queue config or the lens rules on the default branch, dispatch the backfill again: it judges @@ -431,7 +442,10 @@ head "not passed" unless it judged the head and the head passed. pull request read and git's `refs/pull/N/head` both fail every try. - A review trigger's run whose pull request cannot be found: the list of open pull requests with its head fails every try (the guard job fails), or - no open pull request has its head (nothing to judge, the log says why). + no open pull request has its head (nothing to judge, the log says why). A + run that names no head (its head fields missing or odd) judges nothing + with a warning: GitHub's fields are not what the lookup expects (setup + step 8). More than one is no such case: the head is judged once, in the job for the lowest number. - The backfill cannot list the open pull requests after its tries, or finds diff --git a/fork-ci/actions/head-check/head_gate.py b/fork-ci/actions/head-check/head_gate.py index 2c45db08dac60..4c8308ace15c6 100644 --- a/fork-ci/actions/head-check/head_gate.py +++ b/fork-ci/actions/head-check/head_gate.py @@ -326,8 +326,11 @@ def review_run_pr(repo, run, gh, out): return [], None if not (pr_queue.SHA.fullmatch(sha) and pr_queue.REPO_RE.fullmatch(head_repo) and 0 < len(branch) <= BRANCH_MAX and branch.isprintable()): - out("nothing to judge: the run does not name a head (head sha, head repository, head branch); dispatch the " - 'gate with the pull request number') + # A warning, not a log line: a review run always has these fields (GitHub's, of a pull request event), so a + # run without them means GitHub's fields are not what this lookup expects, and no review would ever re-run the + # gate while every run stays green. The annotation makes that seen (the live check after setup looks for it). + out("::warning::head gate: nothing to judge: the review trigger's run does not name a head (head sha, head " + 'repository, head branch); dispatch the gate with the pull request number') return [], None owner = urllib.parse.quote(head_repo.split('/')[0], safe='') query = (f'repos/{repo}/pulls?state=open&per_page=100&head={owner}:' diff --git a/fork-ci/actions/head-check/head_gate.test.py b/fork-ci/actions/head-check/head_gate.test.py index 5b0f48b4637bd..e6cf5185199ea 100644 --- a/fork-ci/actions/head-check/head_gate.test.py +++ b/fork-ci/actions/head-check/head_gate.test.py @@ -556,6 +556,13 @@ def test_a_run_of_another_event_or_with_odd_fields_judges_nothing_and_reads_noth code, out, gh = self.review(run=run) self.assertEqual((code, self.found(), gh.calls), (0, [], []), out) self.assertIn('nothing to judge', out) + # #379: a review run always has its head fields, so odd ones mean GitHub's fields are not what the + # lookup expects (no review would ever re-run the gate): a warning the live check can see, one line. + # Another event is normal (an older caller without the event clause): a plain log line. + odd = 'event' not in run + self.assertEqual(out.startswith('::warning::head gate: nothing to judge: '), odd, out) + self.assertEqual(out.count('::'), 2 if odd else 0, out) + self.assertNotIn('::error::', out) def test_the_listing_reads_only_the_fields_it_uses(self): # #379: no draft (preflight fails a draft's head) self.assertEqual(G.HEAD_JQ, '.[] | [.number, .head.sha, .head.repo.full_name] | @json')