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
10 changes: 8 additions & 2 deletions .github/scripts/fork-head-gate-workflow.test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
against every fork workflow, in fork-contracts.test.py (head-gate).
"""

import ast
import json
import os
import pathlib
Expand Down Expand Up @@ -332,8 +333,13 @@ def args(*a):
and "Needed:" in EXAMPLE.read_text())
check("example: no pass-drafts anywhere (a draft's check run would count for a ready pull request at its head)",
"pass-drafts" not in EXAMPLE.read_text() and "pass-drafts" not in text)
REVIEW_EVENTS = re.search(r"^REVIEW_EVENTS = \(([^)]*)\)", GATE_PY.read_text(), re.M)
REVIEW_EVENTS = re.findall(r"'([a-z_]+)'", REVIEW_EVENTS.group(1)) if REVIEW_EVENTS else []
# The tuple as Python reads it (any quoting), from head_gate.py's top-level assignment; [] if it is not a literal.
REVIEW_EVENTS = next((n.value for n in ast.parse(GATE_PY.read_text()).body if isinstance(n, ast.Assign)
and [getattr(t, "id", None) for t in n.targets] == ["REVIEW_EVENTS"]), None)
try:
REVIEW_EVENTS = list(ast.literal_eval(REVIEW_EVENTS)) if REVIEW_EVENTS is not None else []
except (ValueError, TypeError, SyntaxError):
REVIEW_EVENTS = []
check("example: an issue comment that is not on a pull request starts nothing, nor a review trigger run that did "
"not succeed (a newer one replaced it) or that another event started (#379: skipped before a guard job "
"starts; the events are head_gate's REVIEW_EVENTS)",
Expand Down
16 changes: 10 additions & 6 deletions fork-ci/actions/head-check/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,9 @@ gate again, through two workflows
are GitHub's fields of the run, never its outputs, artifacts or names). A
match is judged like an issue comment on it. More than one (one branch into
two bases, so every match has the same head): the gate judges a head, not a
pull request, so the lowest number judges it once for all of them, and the
log names the others. None (closed or merged since, or the head moved on:
pull request, so it judges the head once, in the job for the lowest number.
The log lists them all; the target step names the ones it judges (ready,
into the default branch). None (closed or merged since, or the head moved on:
the push ran the gate already): nothing is judged and the log says why.
- Review trigger runs on one head wait in one group per caller: one judges,
the newest waits, the ones in between are dropped while they wait. A run is
Expand All @@ -342,8 +343,9 @@ name, but the caller only learns "look at this head again", which any issue
comment on the pull request can already say. A run from a fork carries the
fork as its head repository, so a fork that copies another pull request's
head sha finds only its own pull request, and the head is judged as a whole
anyway. A pull request that removes or breaks its copy only stops runs on
itself.
anyway. A pull request that removes or breaks its own copy of the trigger
stops only its own review runs; whether another pull request can cancel them
is the next paragraph.

The trigger is a convenience, not a guard. Withdrawing a lens read (deleting
an inline lens comment, editing a review) runs the gate again only through
Expand All @@ -358,7 +360,8 @@ run.
Fallback: when the trigger does not run (a fork's run waiting for approval,
a review posted with a workflow's `GITHUB_TOKEN`, which starts no workflow,
a pull request with a merge conflict, on which GitHub runs no
`pull_request*` workflow, or a project that has not copied it yet), post an
`pull_request`, `pull_request_review` or `pull_request_review_comment`
workflow, or a project that has not copied it yet), post an
issue comment on the pull request or dispatch the gate with its number. A new
push, ready or draft, a base change and any issue comment start the gate
anyway. Copy the new caller
Expand Down Expand Up @@ -401,7 +404,8 @@ head "not passed" unless it judged the head and the head passed.
- 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).
More than one is no such case: the lowest number judges the head once.
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
more than 256 heads. Dispatch again (or once per pull request).
- A step before start fails for a reason of GitHub or the runner, never
Expand Down
20 changes: 13 additions & 7 deletions fork-ci/actions/head-check/head_gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@
not its rate limit). On a workflow_run (the review trigger's run finished, README.md "Run again after a
review"): no number is taken; the open pull requests whose head is the run's head sha from the run's
head repository and branch (--run-*, GitHub's fields of the run), read from the API. More than one (one
branch into two bases): the lowest number judges the head once, the log names the others. None, or a run
of another event: nothing to judge (a log line says why).
branch into two bases): the head is judged once, in the job for the lowest number; target names the ones
it judges (ready, into the default branch). None, or a run of another event: nothing to judge (a log
line says why).
target before any token: post=false only for bad arguments. Else post=true: the head gets a failure (judge writes
it) when the guard did not pass, on a re-run (run attempt 2 or later), for a caller that is not the default
branch's current one or does not pin this gate release, for a lens list with a name that names no lens, for
Expand Down Expand Up @@ -349,11 +350,16 @@ def review_run_pr(repo, run, gh, out):
'or the head moved on: its push ran the gate)')
return [], None
# One branch into two bases: every match has this head, and the gate judges a head, not a pull request (preflight
# lists every open pull request with it again; the number only names the job). So it is judged once.
first, others = min(matches), sorted(set(matches) - {min(matches)})
also = f'; #{first} judges it for {", ".join(f"#{n}" for n in others)} too' if others else ''
out(f'review run: #{first} has the head {head_check.escape(where)}{also}')
return [{'pr': first, 'sha': sha}], None
# lists every open pull request with it again; the number only names the job). So it is judged once. The listing
# has no draft or base, so this line cannot say which of them are judged: target's "judging" line does.
numbers = sorted(set(matches)) # numbers, so 9 < 10; a number GitHub listed twice is named once
if len(numbers) == 1:
out(f'review run: #{numbers[0]} has the head {head_check.escape(where)}')
else:
out(f'review run: open pull requests {", ".join(f"#{n}" for n in numbers)} have the head '
f'{head_check.escape(where)}; judged once, in the job for #{numbers[0]} (the lowest number); the target '
'step names the ones it judges (ready, into the default branch)')
return [{'pr': numbers[0], 'sha': sha}], None


def prs(repo, event, pr_text, gh, out, env, event_sha='', git_head=None, run=None):
Expand Down
41 changes: 38 additions & 3 deletions fork-ci/actions/head-check/head_gate.test.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ def test_no_open_pull_request_with_the_head_judges_nothing(self):

def test_two_open_pull_requests_with_the_head_judge_it_once(self): # #379: same branch into two bases
# The gate judges a head, not a pull request (preflight lists every open pull request with it again), so the
# lowest number judges it once for all of them; the others are named in the log. Nothing is skipped: a lens
# head is judged once, in the job for the lowest number; the log lists them all. Nothing is skipped: a lens
# read withdrawn on one of them leaves no stale pass. Order of the listing, a third one: the same answer.
for rows in ([(12, self.H, REPO), (14, self.H, REPO)], [(14, self.H, REPO), (12, self.H.upper(), REPO)],
[(15, self.H, REPO), (14, self.H, REPO), (12, self.H, REPO), (13, self.OTHER, REPO)]):
Expand All @@ -485,8 +485,41 @@ def test_two_open_pull_requests_with_the_head_judge_it_once(self): # #379: sam
self.assertEqual((code, self.found()), (0, [{'pr': 12, 'sha': self.H}]), out)
self.assertNotIn('nothing to judge', out)
self.assertNotIn('each number', out)
others = ', '.join(f'#{n}' for n, h, _ in sorted(rows) if h.lower() == self.H and n != 12)
self.assertIn(f'#12 judges it for {others} too', out)
listed = ', '.join(f'#{n}' for n, h, _ in sorted(rows) if h.lower() == self.H)
self.assertIn(f'review run: open pull requests {listed} have the head ', out)
self.assertIn('judged once, in the job for #12 (the lowest number)', out)

def test_the_lowest_is_the_lowest_number_not_the_first_text(self): # #400: 9 < 10 < 100, though '10' < '9'
for rows in ([(10, self.H, REPO), (9, self.H, REPO)],
[(100, self.H, REPO), (9, self.H, REPO), (10, self.H, REPO)]):
with self.subTest(rows=rows):
code, out, _ = self.review(rows)
self.assertEqual((code, self.found()), (0, [{'pr': 9, 'sha': self.H}]), out)
self.assertIn('open pull requests #9, #10' + (', #100' if len(rows) == 3 else '') + ' have', out)

def test_the_log_names_no_pull_request_as_judged(self): # #400: the lowest may be a draft or into another base
# The listing has no draft or base (HEAD_JQ), so this line cannot know which of them are judged: it names
# them as the open ones with the head, and target's "judging" line names the ones judged.
code, out, _ = self.review([(12, self.H, REPO), (14, self.H, REPO)])
self.assertEqual((code, self.found()), (0, [{'pr': 12, 'sha': self.H}]), out)
self.assertNotRegex(out, r'#\d+ judges')
self.assertIn('the target step names the ones it judges (ready, into the default branch)', out)
code, out, _ = self.review([(12, self.H, REPO)]) # one: unchanged
self.assertEqual((code, self.found()), (0, [{'pr': 12, 'sha': self.H}]), out)
self.assertIn('review run: #12 has the head ', out)
self.assertNotIn('judged once', out)

def test_a_number_listed_twice_is_named_once(self): # #400: pages that overlap while the list changes
for rows in ([(12, self.H, REPO), (14, self.H, REPO), (14, self.H, REPO)],
[(14, self.H, REPO), (12, self.H, REPO), (12, self.H, REPO), (14, self.H, REPO)],
[(12, self.H, REPO), (12, self.H, REPO)]):
with self.subTest(rows=rows):
code, out, _ = self.review(rows)
self.assertEqual((code, self.found()), (0, [{'pr': 12, 'sha': self.H}]), out)
line = next(l for l in out.splitlines() if l.startswith('review run:'))
want = 'open pull requests #12, #14 have' if 14 in (r[0] for r in rows) else '#12 has'
self.assertTrue(line.startswith(f'review run: {want} the head '), line)
self.assertEqual(line.count('#14'), int(14 in (r[0] for r in rows)), line)

def test_one_of_two_closed_half_way_judges_the_one_left(self): # stops half-way: the listing has the one left
for rows in ([(14, self.H, REPO)], [(12, self.H, REPO)]):
Expand Down Expand Up @@ -533,6 +566,8 @@ def test_a_number_on_a_workflow_run_is_refused(self): # the number comes only
def test_an_unreadable_or_odd_listing_is_refused_and_posts_nothing(self): # stops half-way: an older check stays
for rows in (answer(1, '', 'gh: Server Error (HTTP 502)'), answer(0, 'x\n'), answer(0, '[12, "x", null]\n'),
answer(0, '[true, "' + self.H + '", null]\n'), answer(0, '[12, "' + self.H + '", 5]\n'),
answer(0, '["12", "' + self.H + '", "' + REPO + '"]\n'), # #400: a number as a string
answer(0, '[12.0, "' + self.H + '", "' + REPO + '"]\n'),
answer(0, '[12, false, "' + self.H + '", null]\n'), # the old four-field row
answer(0, '[12, "' + self.H + '", "' + REPO + '", false]\n')):
with self.subTest(rows=rows.stdout[:20]):
Expand Down
Loading