@@ -43,12 +43,16 @@ jobs:
4343 test-outcome : ${{ steps.test.outcome }}
4444 defaults : # On Hoskinson runners, landrun is already installed.
4545 run :
46- shell : landrun --rox /usr --rw /dev --rox /home/lean/.elan --rox /home/lean/actions-runner/_work --rox /home/lean/.cache/mathlib/ --rw pr-branch/.lake/ --env PATH --env HOME --env GITHUB_OUTPUT -- bash -euxo pipefail {0}
46+ shell : landrun --rox /usr --ro /etc/timezone -- rw /dev --rox /home/lean/.elan --rox /home/lean/actions-runner/_work --rox /home/lean/.cache/mathlib/ --rw pr-branch/.lake/ --env PATH --env HOME --env GITHUB_OUTPUT -- bash -euxo pipefail {0}
4747 steps :
4848 - name : cleanup
4949 shell : bash # This *just* deletes old files, so is safe to run outside landrun.
5050 run : |
51- find . -name . -o -prune -exec rm -rf -- {} +
51+ if ! find . -mindepth 1 -exec rm -rf -- {} +; then
52+ echo "ERROR: Initial cleanup failed, waiting 5 seconds and retrying..."
53+ sleep 5
54+ find . -mindepth 1 -exec rm -rf -- {} +
55+ fi
5256 # Delete all but the 5 most recent toolchains.
5357 # Make sure to delete both the `~/.elan/toolchains/X` directory and the `~/.elan/update-hashes/X` file.
5458 # Skip symbolic links (`-type d`), the current directory (`! -name .`), and `nightly` and `stable`.
6670 - name : Checkout master branch
6771 uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
6872 with :
69- ref : master
73+ # Recall that on the `leanprover-community/mathlib4-nightly-testing` repository,
74+ # we don't maintain a `master` branch at all.
75+ # For PRs and pushes to this repository, we will use `nightly-testing` instead.
76+ ref : ${{ github.repository == 'leanprover-community/mathlib4-nightly-testing' && 'nightly-testing' || 'master' }}
7077 path : master-branch
7178
7279 # Checkout the PR branch into a subdirectory
@@ -198,8 +205,8 @@ jobs:
198205 run : |
199206 cd pr-branch
200207
201- echo "Attempting: lake build --no-build Mathlib.Init (this runs under landrun)"
202- lake build --no-build Mathlib.Init
208+ echo "Attempting: lake build --no-build -v Mathlib.Init (this runs under landrun)"
209+ lake build --no-build -v Mathlib.Init
203210
204211 - name : get cache (3/3 - finalize cache operation)
205212 id : get
@@ -210,8 +217,11 @@ jobs:
210217 echo "Fetching all remaining cache..."
211218
212219 ../master-branch/.lake/build/bin/cache get
220+
221+ # Run again with --repo, to ensure we actually get the oleans.
222+ ../master-branch/.lake/build/bin/cache --repo=${{ github.event.pull_request.head.repo.full_name || github.repository }} get
213223 else
214- echo "WARNING: 'lake build --no-build Mathlib.Init' failed."
224+ echo "WARNING: 'lake build --no-build -v Mathlib.Init' failed."
215225 echo "No cache for 'Mathlib.Init' available or it could not be prepared."
216226 fi
217227
@@ -233,14 +243,17 @@ jobs:
233243 id : build
234244 run : |
235245 cd pr-branch
246+ echo "::group::{test curl}"
236247 # Test curl - should fail when landrun network isolation is working
237248 if curl --silent --head --fail https://www.example.com/ >/dev/null 2>&1; then
238249 echo "ERROR: curl to example.com succeeded, but it should fail when landrun is working correctly!"
239250 exit 1
240251 else
241252 echo "curl to example.com failed as expected - landrun network isolation is working"
242253 fi
243- bash -o pipefail -c "env LEAN_ABORT_ON_PANIC=1 lake build --wfail -KCI"
254+ echo "::endgroup::"
255+
256+ ../master-branch/scripts/lake-build-with-retry.sh Mathlib
244257 - name : end gh-problem-match-wrap for build step
245258 uses : leanprover-community/gh-problem-matcher-wrap@20007cb926a46aa324653a387363b52f07709845 # 2025-04-23
246259 with :
@@ -252,6 +265,17 @@ jobs:
252265 cd pr-branch
253266 du .lake/build/lib/lean/Mathlib || echo "This code should be unreachable"
254267
268+ - name : upload artifact containing contents of pr-branch
269+ # temporary measure for debugging no-build failures
270+ uses : actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
271+ with :
272+ name : mathlib4_artifact
273+ include-hidden-files : true
274+ # we exclude .git since there may be secrets in there
275+ path : |
276+ pr-branch/
277+ !pr-branch/.git/
278+
255279 # The cache secrets are available here, so we must not run any untrusted code.
256280 - name : upload cache
257281 # We only upload the cache if the build started (whether succeeding, failing, or cancelled)
@@ -262,36 +286,20 @@ jobs:
262286 run : |
263287 cd pr-branch
264288
289+ # Trim trailing whitespace from secrets to prevent issues with accidentally added spaces
290+ export MATHLIB_CACHE_SAS="${MATHLIB_CACHE_SAS_RAW%"${MATHLIB_CACHE_SAS_RAW##*[![:space:]]}"}"
291+ export MATHLIB_CACHE_S3_TOKEN="${MATHLIB_CACHE_S3_TOKEN_RAW%"${MATHLIB_CACHE_S3_TOKEN_RAW##*[![:space:]]}"}"
292+
265293 # Use the trusted cache tool from master-branch
266294 # TODO: this is not doing anything currently, and needs to be integrated with put-unpacked
267295 # ../master-branch/.lake/build/bin/cache commit || true
268296 # run this in CI if it gets an incorrect lake hash for existing cache files somehow
269297 # ../master-branch/.lake/build/bin/cache put!
270298 # do not try to upload files just downloaded
271- ../master-branch/.lake/build/bin/cache put-unpacked
299+ ../master-branch/.lake/build/bin/cache --repo=${{ github.event.pull_request.head.repo.full_name || github.repository }} put-unpacked
272300 env :
273- MATHLIB_CACHE_SAS : ${{ secrets.MATHLIB_CACHE_SAS }}
274- MATHLIB_CACHE_S3_TOKEN : ${{ secrets.MATHLIB_CACHE_S3_TOKEN }}
275-
276- - name : check the cache
277- # We need network access to download dependencies
278- # We run this inside landrun, but restrict disk access as usual.
279- shell : landrun --unrestricted-network --rox /usr --rw /dev --rox /etc --rox /home/lean/.elan --rox /home/lean/actions-runner/_work --rox /home/lean/.cache/mathlib -rw pr-branch/.lake/ --rw pr-branch/DownstreamTest/ --env PATH --env HOME --env GITHUB_OUTPUT -- bash -euxo pipefail {0}
280- run : |
281- cd pr-branch
282-
283- # Because the `lean-pr-testing-NNNN` branches use toolchains that are "updated in place"
284- # the cache mechanism is unreliable, so we don't test it if we are on such a branch.
285- if [[ ! $(cat lean-toolchain) =~ ^leanprover/lean4-pr-releases:pr-release-[0-9]+$ ]]; then
286- cd DownstreamTest
287- MATHLIB_NO_CACHE_ON_UPDATE=1 lake update
288-
289- lake env ../../master-branch/.lake/build/bin/cache get || (sleep 1; lake env ../../master-branch/.lake/build/bin/cache get)
290-
291- # We need to run `lake build ProofWidgets` here to retrieve ProofWidgets via Reservoir.
292- lake build ProofWidgets
293- lake build --no-build Mathlib
294- fi
301+ MATHLIB_CACHE_SAS_RAW : ${{ secrets.MATHLIB_CACHE_SAS }}
302+ MATHLIB_CACHE_S3_TOKEN_RAW : ${{ secrets.MATHLIB_CACHE_S3_TOKEN }}
295303
296304 # Note: we should not be including `Archive` and `Counterexamples` in the cache.
297305 # We do this for now for the sake of not rebuilding them in every CI run
@@ -310,26 +318,44 @@ jobs:
310318
311319 - name : build archive
312320 id : archive
321+ continue-on-error : true
313322 run : |
314323 cd pr-branch
315- bash -o pipefail -c "env LEAN_ABORT_ON_PANIC=1 lake build Archive"
324+ ../master-branch/scripts/ lake- build-with-retry.sh Archive
316325
317326 - name : build counterexamples
318327 id : counterexamples
328+ continue-on-error : true
319329 run : |
320330 cd pr-branch
321- bash -o pipefail -c "env LEAN_ABORT_ON_PANIC=1 lake build Counterexamples"
331+ ../master-branch/scripts/lake-build-with-retry.sh Counterexamples
332+
333+ - name : Check if building Archive or Counterexamples failed
334+ if : steps.archive.outcome == 'failure' || steps.counterexamples.outcome == 'failure'
335+ run : |
336+ if [ "${{ steps.archive.outcome }}" == "failure" ]; then
337+ echo "❌ The \"build archive\" step above failed; please check its logs."
338+ fi
339+ if [ "${{ steps.counterexamples.outcome }}" == "failure" ]; then
340+ echo "❌ The \"build counterexamples\" step above failed; please check its logs."
341+ fi
342+ exit 1
322343
323344 # The cache secrets are available here, so we must not run any untrusted code.
324345 - name : put archive and counterexamples cache
325346 shell : bash
326347 run : |
327348 cd pr-branch
328- ../master-branch/.lake/build/bin/cache put Archive.lean
329- ../master-branch/.lake/build/bin/cache put Counterexamples.lean
349+
350+ # Trim trailing whitespace from secrets to prevent issues with accidentally added spaces
351+ export MATHLIB_CACHE_SAS="${MATHLIB_CACHE_SAS_RAW%"${MATHLIB_CACHE_SAS_RAW##*[![:space:]]}"}"
352+ export MATHLIB_CACHE_S3_TOKEN="${MATHLIB_CACHE_S3_TOKEN_RAW%"${MATHLIB_CACHE_S3_TOKEN_RAW##*[![:space:]]}"}"
353+
354+ ../master-branch/.lake/build/bin/cache --repo=${{ github.event.pull_request.head.repo.full_name || github.repository }} put Archive.lean
355+ ../master-branch/.lake/build/bin/cache --repo=${{ github.event.pull_request.head.repo.full_name || github.repository }} put Counterexamples.lean
330356 env :
331- MATHLIB_CACHE_SAS : ${{ secrets.MATHLIB_CACHE_SAS }}
332- MATHLIB_CACHE_S3_TOKEN : ${{ secrets.MATHLIB_CACHE_S3_TOKEN }}
357+ MATHLIB_CACHE_SAS_RAW : ${{ secrets.MATHLIB_CACHE_SAS }}
358+ MATHLIB_CACHE_S3_TOKEN_RAW : ${{ secrets.MATHLIB_CACHE_S3_TOKEN }}
333359
334360 - name : Check {Mathlib, Tactic, Counterexamples, Archive}.lean
335361 if : always()
@@ -393,7 +419,7 @@ jobs:
393419 ## we filter out the output lines that begin with `✔ [xx/yy]`, where xx, yy
394420 ## are either numbers or ?, and the "Build completed successfully." message.
395421 ## We keep the rest, which are actual outputs of the files
396- awk '!($0 ~ "^\\s*✔ \\[[?0-9]*/[?0-9]*\\]" || $0 == " Build completed successfully. "){ print $0 }')"
422+ awk '!($0 ~ "^\\s*✔ \\[[?0-9]*/[?0-9]*\\]" || $0 ~ "^ Build completed successfully( \\([0-9]+ jobs\\))?\\.?$ "){ print $0 }')"
397423 if [ -n "${buildMsgs}" ]
398424 then
399425 printf $'%s\n' "${buildMsgs}"
@@ -413,6 +439,7 @@ jobs:
413439 COUNTEREXAMPLES_OUTCOME : ${{ steps.counterexamples.outcome }}
414440 LINT_OUTCOME : ${{ steps.lint.outcome }}
415441 TEST_OUTCOME : ${{ steps.test.outcome }}
442+ NIGHTLY_TESTING_REPO : leanprover-community/mathlib4-nightly-testing
416443 run : |
417444 master-branch/scripts/lean-pr-testing-comments.sh lean
418445 master-branch/scripts/lean-pr-testing-comments.sh batteries
@@ -425,6 +452,8 @@ jobs:
425452 steps :
426453
427454 - uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
455+ with :
456+ ref : " ${{ PR_BRANCH_REF }}"
428457
429458 - name : Configure Lean
430459 uses : leanprover/lean-action@f807b338d95de7813c5c50d018f1c23c9b93b4ec # 2025-04-24
@@ -434,15 +463,33 @@ jobs:
434463 use-mathlib-cache : true
435464 reinstall-transient-toolchain : true
436465
466+ # TODO: this step should not be necessary, "Configure Lean" above should already achieve this.
467+ - name : get cache for Mathlib
468+ run : |
469+ # Run once without --repo, so we can diagnose what `lake exe cache get` wants to do by itself.
470+ lake exe cache get
471+ # Run again with --repo, so ensure we actually get the oleans.
472+ lake exe cache --repo=${{ github.event.pull_request.head.repo.full_name || github.repository }} get
473+
474+
437475 - name : get cache for Archive and Counterexamples
438476 run : |
477+ # Run once without --repo, so we can diagnose what `lake exe cache get` wants to do by itself.
439478 lake exe cache get Archive Counterexamples
479+ # Run again with --repo, so ensure we actually get the oleans.
480+ lake exe cache --repo=${{ github.event.pull_request.head.repo.full_name || github.repository }} get Archive Counterexamples
440481
441482 - name : verify that everything was available in the cache
442483 run : |
443- lake build --no-build Mathlib
444- lake build --no-build Archive
445- lake build --no-build Counterexamples
484+ echo "::group::{verify Mathlib cache}"
485+ lake build --no-build -v Mathlib
486+ echo "::endgroup::"
487+ echo "::group::{verify Archive cache}"
488+ lake build --no-build -v Archive
489+ echo "::endgroup::"
490+ echo "::group::{verify Counterexamples cache}"
491+ lake build --no-build -v Counterexamples
492+ echo "::endgroup::"
446493
447494 - name : check declarations in db files
448495 run : |
@@ -504,10 +551,11 @@ jobs:
504551 if : FORK_CONDITION
505552 runs-on : ubuntu-latest
506553 steps :
507- - uses : leanprover-community/lint-style-action@f2e7272aad56233a642b08fe974cf09dd664b0c8 # 2025-05-22
554+ - uses : leanprover-community/lint-style-action@d29fb3b12c1c834450680b3c544f63fe0237a2e2 # 2025-06-20
508555 with :
509556 mode : check
510557 lint-bib-file : true
558+ ref : ${{ PR_BRANCH_REF }}
511559
512560 build_and_lint :
513561 name : CI Success
0 commit comments