Skip to content

Commit 391e717

Browse files
kim-emclaude
andcommitted
feat(ci): cross-reference tag review via post-build dump + workflow_run shim
Stack on top of the dump_crossref_tags.lean PR. Adds two pieces: * .github/workflows/build_template.yml: three new steps in `post_steps`, after the import-graph upload. Run scripts/dump_crossref_tags.lean to produce crossref-tags.tsv. For pull_request_target builds, build a bridge payload (pr_number, head_sha) and emit it via leanprover-community/privilege-escalation-bridge/emit using artifact name `crossref-tags-bridge`. Non-PR builds skip the emit. * .github/workflows/crossref_review.yml: workflow_run listener on the two `continuous integration` workflows. Consumes the bridge artifact via privilege-escalation-bridge/consume, checks out leanprover-community/mathlib-ci, and invokes its scripts/crossref_review/post-comment.sh orchestrator. The orchestrator clones leanprover-community/external-tags at a pinned SHA and uses it to fetch snippets and render the PR comment. Replaces #39666. The original PR rolled its own artifact upload + PR number resolution fallback chain (~158 LOC) and included the snippet fetcher in scripts/crossref.lean (~760 LOC). This version delegates to the existing privilege-escalation-bridge infrastructure (same pattern as olean_report.yaml + olean_report_wf_run.yaml) and to external-tags, cutting the mathlib4 surface to ~97 LOC. Trust model: the privileged workflow_run job runs only code from mathlib-ci@<pinned SHA> (which runs only code from external-tags at a pinned SHA). Nothing from the build artifact is interpreted as code; the TSV is parsed as untrusted data with user-controllable fields escaped before interpolation into the comment. Depends on #39876. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent e265200 commit 391e717

2 files changed

Lines changed: 97 additions & 0 deletions

File tree

.github/workflows/build_template.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,41 @@ jobs:
745745
- name: clean up the import graph file
746746
run: rm import_graph.dot
747747

748+
- name: dump cross-reference tags to TSV
749+
# Walks Mathlib.CrossRef.tagExt and writes one TSV row per @[stacks ...] /
750+
# @[kerodon ...] / @[wikidata ...] tag for the privileged workflow_run
751+
# job (crossref_review.yml) to consume. The script has no network access
752+
# and enforces a 2 MB output cap.
753+
run: lake env lean --run scripts/dump_crossref_tags.lean crossref-tags.tsv
754+
755+
- name: prepare crossref bridge outputs
756+
# We only emit the crossref bridge artifact when this build is for a PR
757+
# (the `crossref_review.yml` workflow_run job has nothing to post otherwise).
758+
id: crossref_outputs
759+
env:
760+
EVENT_NAME: ${{ github.event_name }}
761+
HEAD_SHA: ${{ inputs.pr_branch_ref }}
762+
PR_NUMBER: ${{ github.event.pull_request.number }}
763+
run: |
764+
if [ "$EVENT_NAME" = "pull_request_target" ] && [ -n "$PR_NUMBER" ]; then
765+
jq -n --arg n "$PR_NUMBER" --arg s "$HEAD_SHA" \
766+
'{ pr_number: $n, head_sha: $s }' > crossref-bridge-outputs.json
767+
echo "emit=true" >> "$GITHUB_OUTPUT"
768+
else
769+
echo "emit=false" >> "$GITHUB_OUTPUT"
770+
fi
771+
772+
- name: emit crossref bridge artifact
773+
if: steps.crossref_outputs.outputs.emit == 'true'
774+
uses: leanprover-community/privilege-escalation-bridge/emit@f5dfe313a79647c07315b451b2dc2a81a161a50d # v1.2.0
775+
with:
776+
artifact: crossref-tags-bridge
777+
outputs_file: crossref-bridge-outputs.json
778+
include_event: minimal
779+
files: |
780+
crossref-tags.tsv
781+
retention_days: 5
782+
748783
- name: check all scripts build successfully
749784
run: |
750785
lake env lean scripts/create_deprecated_modules.lean
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Cross-reference tag review (workflow_run)
2+
#
3+
# Privileged companion to the `dump cross-reference tags to TSV` step in
4+
# `build_template.yml`. Downloads the bridge artifact emitted by the build,
5+
# hands off to mathlib-ci's orchestrator, which in turn invokes the
6+
# pinned `leanprover-community/external-tags` tool to fetch snippets and
7+
# produce the PR comment body, then posts/updates the comment.
8+
#
9+
# The privileged job runs with `pull-requests: write`, but it executes only
10+
# code from mathlib-ci (which executes only code from external-tags at a
11+
# pinned SHA). Nothing from the build artifact is interpreted as code; the
12+
# TSV is parsed as untrusted data.
13+
name: cross-reference review (workflow_run)
14+
15+
on:
16+
workflow_run:
17+
workflows:
18+
- continuous integration
19+
- continuous integration (mathlib forks)
20+
types:
21+
- completed
22+
23+
permissions:
24+
actions: read
25+
contents: read
26+
pull-requests: write
27+
28+
jobs:
29+
review:
30+
name: Post cross-reference review comment
31+
runs-on: ubuntu-latest
32+
if: ${{ github.repository == 'leanprover-community/mathlib4' && github.event.workflow_run.conclusion == 'success' }}
33+
steps:
34+
- name: Consume bridge artifact
35+
id: bridge
36+
uses: leanprover-community/privilege-escalation-bridge/consume@f5dfe313a79647c07315b451b2dc2a81a161a50d # v1.2.0
37+
with:
38+
token: ${{ github.token }}
39+
artifact: crossref-tags-bridge
40+
# Pushes (non-PR builds) intentionally skip the emit step, so a
41+
# missing artifact is the common case for non-PR runs.
42+
fail_on_missing: false
43+
extract: |
44+
pr_number=outputs.pr_number
45+
head_sha=outputs.head_sha
46+
47+
- name: Checkout mathlib-ci
48+
if: steps.bridge.outputs.pr_number != ''
49+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
50+
with:
51+
repository: leanprover-community/mathlib-ci
52+
ref: master
53+
path: mathlib-ci
54+
55+
- name: Run cross-reference review
56+
if: steps.bridge.outputs.pr_number != ''
57+
env:
58+
GH_TOKEN: ${{ github.token }}
59+
PR_NUMBER: ${{ steps.bridge.outputs.pr_number }}
60+
HEAD_SHA: ${{ steps.bridge.outputs.head_sha }}
61+
TSV_PATH: ${{ github.workspace }}/.bridge/crossref-tags.tsv
62+
run: bash mathlib-ci/scripts/crossref_review/post-comment.sh

0 commit comments

Comments
 (0)