Skip to content

Commit bde2579

Browse files
authored
Let the CI priority classifier read the PR checklist / 让 CI 优先级分类器读取 PR 检查清单 (#4749)
* Give the priority classifier the PR description for checklist-complete * Decide checklist-complete with a deterministic parser, keep the PR body away from the LLM
1 parent c044ca9 commit bde2579

6 files changed

Lines changed: 125 additions & 7 deletions

File tree

‎.github/actions/classify-priority/action.yml‎

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,15 @@ inputs:
1616
description: "full returns every criterion; patchwork returns only the patchwork verdict"
1717
required: false
1818
default: full
19+
pr-number:
20+
description: Pull request whose description decides checklist-complete; empty never returns it
21+
required: false
22+
default: ""
1923
anthropic-api-key:
2024
description: Anthropic API key for the classifier
2125
required: true
2226
github-token:
23-
description: GitHub token for claude-code-action
27+
description: GitHub token for claude-code-action and reading the PR description
2428
required: true
2529

2630
outputs:
@@ -74,9 +78,24 @@ runs:
7478
uv run --no-project --exclude-newer PT12H --python 3.12 --with pyyaml \
7579
python -P -m infx.workflows.ci_priority \
7680
--policy "$E2E_ROOT/configs/ci-priority.yaml" --list-criteria)
77-
schema=$(jq -c '{type:"object",properties:{criteria:{type:"array",items:{type:"string",enum:.},uniqueItems:true},reason:{type:"string"}},required:["criteria","reason"]}' <<<"$criteria")
81+
schema=$(jq -c 'map(select(. != "checklist-complete")) | {type:"object",properties:{criteria:{type:"array",items:{type:"string",enum:.},uniqueItems:true},reason:{type:"string"}},required:["criteria","reason"]}' <<<"$criteria")
7882
echo "json=$schema" >> "$GITHUB_OUTPUT"
7983
84+
- name: Check PR checklist
85+
id: checklist
86+
if: steps.range.outputs.head != '' && inputs.pr-number != ''
87+
continue-on-error: true
88+
shell: bash
89+
env:
90+
GH_TOKEN: ${{ inputs.github-token }}
91+
PR_NUMBER: ${{ inputs.pr-number }}
92+
E2E_ROOT: ${{ github.action_path }}/../../../inferencex-e2e
93+
run: |
94+
complete=$(gh api "repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}" --jq '.body // ""' |
95+
env PYTHONPATH="$E2E_ROOT" uv run --no-project --exclude-newer PT12H --python 3.12 \
96+
python -P -m infx.workflows.pr_checklist)
97+
echo "complete=$complete" >> "$GITHUB_OUTPUT"
98+
8099
- name: Install Claude Code 2.1.282
81100
id: claude_cli
82101
if: steps.range.outputs.head != ''
@@ -117,7 +136,6 @@ runs:
117136
- mtp, draft_model: speculative decoding method
118137
- sglang, vllm, dynamo-sglang, dynamo-vllm: runtime framework
119138
- model criterion: the config model-prefix itself (minimaxm31flash, not minimaxm3)
120-
- checklist-complete: PR checklist is satisfied
121139
- patchwork: modified upstream engine or runtime source
122140
123141
Patchwork includes patch files, git apply, source mutation,
@@ -133,13 +151,18 @@ runs:
133151
env:
134152
OUTPUT: ${{ steps.classify.outputs.structured_output || '{}' }}
135153
SCOPE: ${{ inputs.scope }}
154+
CHECKLIST_COMPLETE: ${{ steps.checklist.outputs.complete }}
136155
run: |
137156
if jq -e 'type == "object" and (.criteria | type == "array")' \
138157
>/dev/null <<<"$OUTPUT"; then
139158
criteria=$(jq -c '.criteria' <<<"$OUTPUT")
140159
else
141160
criteria='["patchwork"]'
142161
fi
162+
criteria=$(jq -c 'map(select(. != "checklist-complete"))' <<<"$criteria")
163+
if [ "$CHECKLIST_COMPLETE" = "true" ]; then
164+
criteria=$(jq -c '. + ["checklist-complete"]' <<<"$criteria")
165+
fi
143166
if [ "$SCOPE" = "patchwork" ]; then
144167
if jq -e 'index("patchwork")' >/dev/null <<<"$criteria"; then
145168
criteria='["patchwork"]'

‎.github/workflows/README.md‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,14 @@ Labels authorize same-repository sweeps on draft or ready PRs. Marking ready
186186
does not dispatch a sweep. Changing a recognized primary or modifier label
187187
cancels the active sweep; another starts only if a primary label remains.
188188
To retrigger an already-labeled PR, remove and reapply its primary label.
189-
Merge conflicts block sweeps. Queue priority comes from the PR diff and
190-
review state, not priority labels. Trusted external sweeps classify the
191-
approved PR diff the same way. Manual `e2e-tests.yml` and `profile.yml`
192-
dispatches of a revision not yet on `main` classify its diff from the merge
189+
Merge conflicts block sweeps. Queue priority comes from the PR diff and the
190+
PR description's checklist, not priority labels. A PR gets a small bonus when
191+
every item under its `Checklist` heading is checked, except conditional items
192+
("If ...", "Before merging ...") that do not apply yet. The checklist is read
193+
when the sweep starts, so later edits count from the next sweep. Trusted
194+
external sweeps classify the approved PR diff the same way. Manual
195+
`e2e-tests.yml` and `profile.yml` dispatches of a revision not yet on `main`
196+
classify its diff from the merge
193197
base only for patchwork, so engine-patching branches still run last. Klaud runs
194198
and revisions already on `main` keep unclassified scoring.
195199

‎.github/workflows/e2e-tests.yml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,9 @@ jobs:
198198
get-jobs:
199199
name: get-jobs
200200
runs-on: ubuntu-latest
201+
permissions:
202+
contents: read
203+
pull-requests: read # Read the external PR description for checklist-complete.
201204
outputs:
202205
benchmark-ref: ${{ steps.checkout-ref.outputs.commit || steps.checkout-default.outputs.commit }}
203206
tooling-ref: ${{ steps.tooling.outputs.result }}
@@ -260,6 +263,7 @@ jobs:
260263
base-ref: ${{ inputs.changelog-base-ref }}
261264
head-ref: ${{ inputs.changelog-head-ref || 'HEAD' }}
262265
scope: ${{ inputs.changelog-head-ref != '' && 'full' || 'patchwork' }}
266+
pr-number: ${{ inputs.source-pr-number }}
263267
anthropic-api-key: ${{ secrets.ANTHROPIC_API_KEY }} # zizmor: ignore[secrets-outside-env]
264268
github-token: ${{ github.token }}
265269
- id: get-jobs

‎.github/workflows/run-sweep.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ jobs:
225225
with:
226226
base-ref: origin/${{ github.base_ref }}
227227
head-ref: ${{ github.event.pull_request.head.sha }}
228+
pr-number: ${{ github.event.pull_request.number }}
228229
anthropic-api-key: ${{ secrets.ANTHROPIC_API_KEY }} # zizmor: ignore[secrets-outside-env]
229230
github-token: ${{ github.token }}
230231

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import pytest
2+
3+
from infx.workflows.pr_checklist import checklist_complete
4+
5+
TEMPLATE = """## Summary
6+
7+
- [ ] Unrelated task outside the checklist
8+
9+
<details>
10+
<summary>PR checklist and change type</summary>
11+
12+
## Type of Change
13+
14+
- [ ] Bug fix
15+
16+
## Checklist
17+
18+
- [{tested}] I have tested my changes locally
19+
- [{changelog}] **If `python -m infx.matrix.changed` lists affected config keys, I have appended one entry**
20+
- [ ] **Before merging via reuse, an authorized maintainer has commented `/use <run_id>`**
21+
22+
</details>
23+
24+
- [ ] Trailing task after the section
25+
"""
26+
27+
28+
@pytest.mark.parametrize(
29+
("tested", "changelog", "expected"),
30+
[
31+
("x", "x", True),
32+
("X", " ", True),
33+
(" ", "x", False),
34+
],
35+
)
36+
def test_only_conditional_items_may_stay_unchecked(tested, changelog, expected):
37+
body = TEMPLATE.format(tested=tested, changelog=changelog)
38+
39+
assert checklist_complete(body) is expected
40+
41+
42+
def test_missing_or_empty_checklist_is_incomplete():
43+
assert checklist_complete("## Summary\n\n- [x] Done\n") is False
44+
assert checklist_complete("## Checklist\n\nNothing here.\n\n## Notes\n- [x] Done\n") is False
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"""Decide whether a PR description's author checklist is complete.
2+
3+
The checklist is the task list under the ``## Checklist`` heading of the PR template.
4+
Every item must be checked except conditional ones ("If ...", "Before merging ..."),
5+
which may stay unchecked until they apply.
6+
"""
7+
8+
from __future__ import annotations
9+
10+
import re
11+
import sys
12+
13+
CHECKLIST_HEADING = re.compile(r"^#{1,6}\s+Checklist\s*$")
14+
ANY_HEADING = re.compile(r"^#{1,6}\s")
15+
SECTION_END = re.compile(r"^\s*</details>")
16+
TASK_ITEM = re.compile(r"^- \[([ xX])\]\s+(.*)$")
17+
CONDITIONAL = re.compile(r"^(If|Before merging)\b")
18+
19+
20+
def checklist_complete(body: str) -> bool:
21+
"""Return True when the Checklist section exists and every unconditional item is checked."""
22+
items: list[tuple[bool, str]] = []
23+
in_section = False
24+
for line in body.splitlines():
25+
if CHECKLIST_HEADING.match(line):
26+
in_section = True
27+
continue
28+
if in_section and (ANY_HEADING.match(line) or SECTION_END.match(line)):
29+
break
30+
if in_section and (match := TASK_ITEM.match(line)):
31+
items.append((match.group(1) != " ", match.group(2).lstrip("*").strip()))
32+
return bool(items) and all(checked or CONDITIONAL.match(text) for checked, text in items)
33+
34+
35+
def main() -> int:
36+
"""Read a PR description from stdin and print true or false."""
37+
print("true" if checklist_complete(sys.stdin.read()) else "false")
38+
return 0
39+
40+
41+
if __name__ == "__main__":
42+
raise SystemExit(main())

0 commit comments

Comments
 (0)