2424 type : string
2525 required : false
2626 default : ' '
27+ cache_application_id :
28+ type : string
29+ required : true
2730
2831env :
2932 # Disable Lake's automatic fetching of cloud builds.
@@ -244,76 +247,6 @@ jobs:
244247 echo "✅ All inputRevs in lake-manifest.json are valid"
245248 fi
246249
247- - name : validate ProofWidgets source repository
248- # Only enforce this on the main mathlib4 repository, not on nightly-testing
249- if : github.repository == 'leanprover-community/mathlib4'
250- shell : bash
251- run : |
252- cd pr-branch
253-
254- expected_url='https://github.com/leanprover-community/ProofWidgets4'
255- proofwidgets_count=$(jq '[.packages[] | select(.name == "proofwidgets")] | length' lake-manifest.json)
256- if [ "$proofwidgets_count" -ne 1 ]; then
257- echo "❌ Error: expected exactly one proofwidgets entry in lake-manifest.json, found $proofwidgets_count"
258- exit 1
259- fi
260-
261- proofwidgets_url=$(jq -r '.packages[] | select(.name == "proofwidgets") | .url' lake-manifest.json)
262- normalized_url="${proofwidgets_url%.git}"
263- if [ "$normalized_url" != "$expected_url" ]; then
264- echo "❌ Error: invalid ProofWidgets source URL in lake-manifest.json"
265- echo " expected: $expected_url"
266- echo " found: $proofwidgets_url"
267- exit 1
268- fi
269-
270- echo "✅ ProofWidgets source URL is allowed: $proofwidgets_url"
271-
272- - name : verify ProofWidgets lean-toolchain matches on versioned releases
273- # Only enforce this on the main mathlib4 repository, not on nightly-testing
274- if : github.repository == 'leanprover-community/mathlib4'
275- shell : bash
276- run : |
277- cd pr-branch
278-
279- # Read the lean-toolchain file
280- TOOLCHAIN=$(cat lean-toolchain | tr -d '[:space:]')
281- echo "Lean toolchain: $TOOLCHAIN"
282-
283- # Check if toolchain matches the versioned release pattern: leanprover/lean4:vX.Y.Z (with optional suffix like -rc1)
284- if [[ "$TOOLCHAIN" =~ ^leanprover/lean4:v[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.-]+)?$ ]]; then
285- echo "✓ Detected versioned Lean release: $TOOLCHAIN"
286- echo "Verifying ProofWidgets lean-toolchain matches..."
287-
288- # Check if ProofWidgets lean-toolchain exists
289- if [ ! -f .lake/packages/proofwidgets/lean-toolchain ]; then
290- echo "❌ Error: .lake/packages/proofwidgets/lean-toolchain does not exist"
291- echo "This file should be created by 'lake env' during dependency download."
292- exit 1
293- fi
294-
295- # Read ProofWidgets lean-toolchain
296- PROOFWIDGETS_TOOLCHAIN=$(cat .lake/packages/proofwidgets/lean-toolchain | tr -d '[:space:]')
297- echo "ProofWidgets toolchain: $PROOFWIDGETS_TOOLCHAIN"
298-
299- # Compare the two
300- if [ "$TOOLCHAIN" != "$PROOFWIDGETS_TOOLCHAIN" ]; then
301- echo "❌ Error: Lean toolchain mismatch!"
302- echo " Main lean-toolchain: $TOOLCHAIN"
303- echo " ProofWidgets lean-toolchain: $PROOFWIDGETS_TOOLCHAIN"
304- echo ""
305- echo "When using a versioned Lean release (leanprover/lean4:vX.Y.Z),"
306- echo "the ProofWidgets dependency must use the same toolchain."
307- echo "Please update the ProofWidgets dependency to use $TOOLCHAIN"
308- exit 1
309- else
310- echo "✅ ProofWidgets lean-toolchain matches: $TOOLCHAIN"
311- fi
312- else
313- echo "ℹ Lean toolchain is not a versioned release (pattern: leanprover/lean4:vX.Y.Z)"
314- echo "Skipping ProofWidgets toolchain verification."
315- fi
316-
317250 - name : get cache (1/3 - setup and initial fetch)
318251 id : get_cache_part1_setup
319252 shell : bash # only runs `cache get` from `tools-branch`, so doesn't need to be inside landrun
@@ -324,7 +257,7 @@ jobs:
324257
325258 # Fail quickly if the cache is completely cold, by checking for Mathlib.Init
326259 echo "Attempting to fetch olean for Mathlib/Init.lean from cache..."
327- ../tools-branch/.lake/build/bin/cache --skip-proofwidgets get Mathlib/Init.lean
260+ ../tools-branch/.lake/build/bin/cache get Mathlib/Init.lean
328261
329262 - name : get cache (2/3 - test Mathlib.Init cache)
330263 id : get_cache_part2_test
@@ -377,13 +310,19 @@ jobs:
377310 # cf. https://leanprover.zulipchat.com/#narrow/channel/287929-mathlib4/topic/Mathlib.20has.20moved.20to.20the.20new.20module.20system/near/563452000
378311 echo "Warming up cache using previous commit: $PREV_SHA (source: $PREV_SHA_SOURCE)"
379312 if git cat-file -e "$PREV_SHA^{commit}" 2>/dev/null || git fetch --no-tags --depth=1 origin "$PREV_SHA"; then
380- git checkout "$PREV_SHA"
381- ../tools-branch/.lake/build/bin/cache --skip-proofwidgets get
382- # Run again with --repo, to ensure we actually get the oleans.
383- ../tools-branch/.lake/build/bin/cache --repo="$CACHE_REPO" --skip-proofwidgets get
384-
385- echo "Switching back to branch head"
386- git checkout "$ORIG_SHA"
313+ # Skip warmup if the previous commit uses a different toolchain
314+ PREV_TOOLCHAIN=$(git show "$PREV_SHA:lean-toolchain" 2>/dev/null || true)
315+ if [[ "$PREV_TOOLCHAIN" != "$(cat lean-toolchain)" ]]; then
316+ echo "Previous commit $PREV_SHA uses a different toolchain ($PREV_TOOLCHAIN); skipping warmup."
317+ else
318+ git checkout "$PREV_SHA"
319+ ../tools-branch/.lake/build/bin/cache get
320+ # Run again with --repo, to ensure we actually get the oleans.
321+ ../tools-branch/.lake/build/bin/cache --repo="$CACHE_REPO" get
322+
323+ echo "Switching back to branch head"
324+ git checkout "$ORIG_SHA"
325+ fi
387326 else
388327 echo "Could not fetch $PREV_SHA; skipping parent warmup cache fetch."
389328 fi
@@ -393,18 +332,10 @@ jobs:
393332
394333 echo "Fetching all remaining cache..."
395334
396- ../tools-branch/.lake/build/bin/cache --skip-proofwidgets get
335+ ../tools-branch/.lake/build/bin/cache get
397336
398337 # Run again with --repo, to ensure we actually get the oleans.
399- ../tools-branch/.lake/build/bin/cache --repo="$CACHE_REPO" --skip-proofwidgets get
400-
401- - name : fetch ProofWidgets release
402- # We need network access for ProofWidgets frontend assets.
403- # Run inside landrun so PR-controlled code remains sandboxed.
404- shell : landrun --unrestricted-network --rox /etc --rox /usr --rw /dev --rox /home/lean/.elan --rox /home/lean/actions-runner/_work --rw pr-branch/.lake/ --env PATH --env HOME --env GITHUB_OUTPUT --env CI -- bash -euxo pipefail {0}
405- run : |
406- cd pr-branch
407- lake build proofwidgets:release
338+ ../tools-branch/.lake/build/bin/cache --repo="$CACHE_REPO" get
408339
409340 - name : update {Mathlib, Tactic, Counterexamples, Archive}.lean
410341 id : mk_all
@@ -459,8 +390,8 @@ jobs:
459390 shell : bash
460391 run : |
461392 cd pr-branch
462- ../tools-branch/.lake/build/bin/cache --skip-proofwidgets get Archive.lean
463- ../tools-branch/.lake/build/bin/cache --skip-proofwidgets get Counterexamples.lean
393+ ../tools-branch/.lake/build/bin/cache get Archive.lean
394+ ../tools-branch/.lake/build/bin/cache get Counterexamples.lean
464395
465396 - name : build archive
466397 id : archive
@@ -643,7 +574,7 @@ jobs:
643574 - name : Generate lean-pr-testing app token
644575 if : ${{ always() && github.repository == 'leanprover-community/mathlib4-nightly-testing' && (startsWith(github.ref_name, 'lean-pr-testing-') || startsWith(github.ref_name, 'batteries-pr-testing-')) }}
645576 id : lean-pr-testing-token
646- uses : actions/create-github-app-token@29824e69f54612133e76f7eaac726eef6c875baf # v2.2.1
577+ uses : actions/create-github-app-token@f8d387b68d61c58ab83c6c016672934102569859 # v3.0.0
647578 with :
648579 app-id : ${{ secrets.MATHLIB_LEAN_PR_TESTING_APP_ID }}
649580 private-key : ${{ secrets.MATHLIB_LEAN_PR_TESTING_PRIVATE_KEY }}
@@ -672,6 +603,9 @@ jobs:
672603 name : Upload to cache
673604 needs : [build]
674605 runs-on : ubuntu-latest # These steps run on a GitHub runner; no landrun sandboxing is needed.
606+ permissions :
607+ contents : read
608+ id-token : write
675609 # We only upload the cache if the build started (whether succeeding, failing, or cancelled)
676610 # but not if any earlier step failed or was cancelled.
677611 # See discussion at https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/Some.20files.20not.20found.20in.20the.20cache/near/407183836
@@ -702,21 +636,46 @@ jobs:
702636 echo "CACHE_BIN=$CACHE_BIN" >> "$GITHUB_ENV"
703637
704638 - name : Download cache staging artifact
705- uses : actions/download-artifact@70fc10c6e5e1ce46ad2ea6f2b72d43f7d47b13c3 # v8.0.0
639+ uses : actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
706640 with :
707641 name : cache-staging
708642 path : cache-staging
709643
710- - name : Upload staged cache to Azure
644+ - name : Azure CLI OIDC login and mint storage bearer token
645+ id : mint_cache_bearer
646+ continue-on-error : true
647+ uses : leanprover-community/mathlib-ci/.github/actions/azure-create-cache-token@17db5ff55a65df98d55cbddcc67938f70d10dab2
648+ with :
649+ azure-client-id : ${{ inputs.cache_application_id }}
650+ azure-tenant-id : ${{ secrets.LPC_AZ_TENANT_ID }}
651+
652+ - name : Fallback to SAS token if bearer mint fails (for ease of migration)
653+ if : ${{ steps.mint_cache_bearer.outcome != 'success' }}
711654 shell : bash
655+ env :
656+ MATHLIB_CACHE_SAS_RAW : ${{ secrets.MATHLIB_CACHE_SAS }}
712657 run : |
713- # Trim trailing whitespace from secrets to prevent issues with accidentally added spaces
714- export MATHLIB_CACHE_SAS="${MATHLIB_CACHE_SAS_RAW%"${MATHLIB_CACHE_SAS_RAW##*[![:space:]]}"}"
658+ if [ -z "$MATHLIB_CACHE_SAS_RAW" ]; then
659+ echo "Azure bearer mint failed and secrets.MATHLIB_CACHE_SAS is not set"
660+ exit 1
661+ fi
662+
663+ MATHLIB_CACHE_SAS="${MATHLIB_CACHE_SAS_RAW%"${MATHLIB_CACHE_SAS_RAW##*[![:space:]]}"}"
664+ if [ -z "$MATHLIB_CACHE_SAS" ]; then
665+ echo "Azure bearer mint failed and secrets.MATHLIB_CACHE_SAS is empty after trimming"
666+ exit 1
667+ fi
668+
669+ echo "::add-mask::$MATHLIB_CACHE_SAS"
670+ echo "MATHLIB_CACHE_AZURE_BEARER_TOKEN=" >> "$GITHUB_ENV"
671+ echo "MATHLIB_CACHE_SAS=$MATHLIB_CACHE_SAS" >> "$GITHUB_ENV"
672+ echo "Using SAS fallback because bearer mint step failed."
715673
674+ - name : Upload staged cache to Azure
675+ shell : bash
676+ run : |
716677 echo "Uploading cache to Azure..."
717678 MATHLIB_CACHE_USE_CLOUDFLARE=0 lake env "$CACHE_BIN" put-staged --staging-dir="cache-staging" --repo=${{ github.event.pull_request.head.repo.full_name || github.repository }}
718- env :
719- MATHLIB_CACHE_SAS_RAW : ${{ secrets.MATHLIB_CACHE_SAS }}
720679
721680 post_steps :
722681 name : Post-Build Step
@@ -784,6 +743,12 @@ jobs:
784743 - name : clean up the import graph file
785744 run : rm import_graph.dot
786745
746+ - name : check all scripts build successfully
747+ run : |
748+ lake env lean scripts/create_deprecated_modules.lean
749+ lake env lean scripts/autolabel.lean
750+ lake exe check_title_labels --labels "t-algebra" "feat: dummy PR for testing"
751+
787752 - name : build everything
788753 # make sure everything is available for test/import_all.lean
789754 # and that miscellaneous executables still work
@@ -906,7 +871,8 @@ jobs:
906871 - if : >- # bot usernames will cause this step to error with "Could not resolve to a User..."
907872 contains(steps.PR.outputs.pr_labels, 'auto-merge-after-CI') &&
908873 steps.get-label-actor.outputs.username != 'mathlib-nolints' &&
909- steps.get-label-actor.outputs.username != 'mathlib-update-dependencies'
874+ steps.get-label-actor.outputs.username != 'mathlib-update-dependencies' &&
875+ steps.get-label-actor.outputs.username != 'mathlib-splicebot'
910876 name: check team membership
911877 uses: tspascoal/get-user-teams-membership@57e9f42acd78f4d0f496b3be4368fc5f62696662 # v3.0.0
912878 id: actorTeams
@@ -921,7 +887,9 @@ jobs:
921887 (
922888 steps.get-label-actor.outputs.username == 'mathlib-nolints' ||
923889 steps.get-label-actor.outputs.username == 'mathlib-update-dependencies' ||
890+ steps.get-label-actor.outputs.username == 'mathlib-splicebot' ||
924891 contains(steps.actorTeams.outputs.teams, 'mathlib-maintainers') ||
892+ contains(steps.actorTeams.outputs.teams, 'lean-release-managers') ||
925893 contains(steps.actorTeams.outputs.teams, 'bot-users')
926894 )
927895 name: If `auto-merge-after-CI` is present, add a `bors merge` comment.
0 commit comments