Skip to content

Commit c210307

Browse files
kim-emclaude
andcommitted
perf(ci): cache ~/.elan + external-tags build across crossref_review runs
The orchestrator used to clone external-tags and lake-build crossref-render on every PR comment. That's elan install (~10s of curl/extract) + Lean toolchain download (~30s) + source compile (~10s) per PR, paid on the workflow_run job side of every fork PR. This restructure makes the workflow_run job: 1. Read the pinned EXTERNAL_TAGS_SHA out of mathlib-ci's post-comment.sh (single source of truth — bumping the pin remains a one-line PR to mathlib-ci, and this YAML picks the new value up automatically). 2. Restore a single actions/cache covering ~/.elan and external-tags/, keyed by that SHA + runner OS. Cache scope means same paths across runs, so lake-built rpaths into ~/.elan/toolchains/ stay valid. 3. On cache miss, install elan + clone + lake build once and the cache captures the result for subsequent runs. 4. Always run the orchestrator with CROSSREF_RENDER_BIN pointing at the prebuilt binary. The orchestrator (mathlib-ci 051c44c) honours that env var; if unset it falls back to clone+build, keeping the script standalone-runnable. Expected steady-state: ~5s of cache restore + the orchestrator's actual work (filter TSV, fetch snippets, post comment). First run after a pin bump: the usual ~1 min, then cached again. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 5bc5ddc commit c210307

1 file changed

Lines changed: 52 additions & 1 deletion

File tree

.github/workflows/crossref_review.yml

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,62 @@ jobs:
6060
if: steps.bridge.outputs.pr_number != ''
6161
uses: ./workflow-actions/.github/actions/get-mathlib-ci
6262

63+
# mathlib-ci's post-comment.sh hardcodes the pinned external-tags
64+
# SHA. We grep it out so the cache key tracks the same source of
65+
# truth. Bumping the pin is a one-line PR to mathlib-ci.
66+
- name: Resolve pinned external-tags SHA
67+
if: steps.bridge.outputs.pr_number != ''
68+
id: pin
69+
run: |
70+
sha=$(grep -E '^EXTERNAL_TAGS_SHA=' "${CI_SCRIPTS_DIR}/crossref_review/post-comment.sh" | head -1 | cut -d'"' -f2)
71+
if [[ ! "$sha" =~ ^[0-9a-f]{40}$ ]]; then
72+
echo "Could not parse EXTERNAL_TAGS_SHA from post-comment.sh; got: '$sha'" >&2
73+
exit 1
74+
fi
75+
echo "sha=$sha" >> "$GITHUB_OUTPUT"
76+
echo "external-tags pinned at $sha"
77+
78+
# Restore (and on miss, eventually populate) a single cache that
79+
# covers both the Lean toolchain (~/.elan) and the built
80+
# external-tags lake project. The key changes whenever the pinned
81+
# external-tags ref changes; a stale toolchain across pin bumps
82+
# costs us one rebuild and that's acceptable.
83+
- name: Restore external-tags build cache
84+
if: steps.bridge.outputs.pr_number != ''
85+
id: cache
86+
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
87+
with:
88+
path: |
89+
~/.elan
90+
external-tags
91+
key: crossref-render-${{ steps.pin.outputs.sha }}-${{ runner.os }}
92+
93+
- name: Install elan
94+
if: steps.bridge.outputs.pr_number != '' && steps.cache.outputs.cache-hit != 'true'
95+
shell: bash
96+
run: |
97+
curl -sSfL https://elan.lean-lang.org/elan-init.sh \
98+
| bash -s -- -y --default-toolchain none
99+
echo "$HOME/.elan/bin" >> "$GITHUB_PATH"
100+
101+
- name: Clone and build external-tags
102+
if: steps.bridge.outputs.pr_number != '' && steps.cache.outputs.cache-hit != 'true'
103+
shell: bash
104+
run: |
105+
git clone --quiet https://github.com/leanprover-community/external-tags external-tags
106+
( cd external-tags && git checkout --quiet "${{ steps.pin.outputs.sha }}" )
107+
( cd external-tags && lake build crossref-render )
108+
63109
- name: Run cross-reference review
64110
if: steps.bridge.outputs.pr_number != ''
65111
env:
66112
GH_TOKEN: ${{ github.token }}
67113
PR_NUMBER: ${{ steps.bridge.outputs.pr_number }}
68114
HEAD_SHA: ${{ steps.bridge.outputs.head_sha }}
69115
TSV_PATH: ${{ github.workspace }}/.bridge/crossref-tags.tsv
70-
run: bash "${CI_SCRIPTS_DIR}/crossref_review/post-comment.sh"
116+
CROSSREF_RENDER_BIN: ${{ github.workspace }}/external-tags/.lake/build/bin/crossref-render
117+
run: |
118+
# elan is needed on PATH so the lake-built binary can find its
119+
# toolchain shared libs (rpath points into ~/.elan/toolchains/).
120+
[[ -d "$HOME/.elan/bin" ]] && export PATH="$HOME/.elan/bin:$PATH"
121+
bash "${CI_SCRIPTS_DIR}/crossref_review/post-comment.sh"

0 commit comments

Comments
 (0)