1- # Reusable workflow invoked by build.yml, bors.yml, and build_fork .yml.
1+ # Reusable workflow invoked by build.yml, bors.yml, build_fork.yml, and ci_dev .yml.
22
33on :
44 workflow_call :
55 inputs :
66 concurrency_group :
77 type : string
88 required : true
9+ tools_branch_ref :
10+ type : string
11+ required : false
12+ default : ' '
913 pr_branch_ref :
1014 type : string
1115 required : true
16+ run_post_ci :
17+ type : boolean
18+ required : false
19+ default : true
1220 runs_on :
1321 type : string
1422 required : true
@@ -71,16 +79,16 @@ jobs:
7179 - name : ' Setup jq'
7280 uses : dcarbone/install-jq-action@b7ef57d46ece78760b4019dbc4080a1ba2a40b45 # v3.2.0
7381
74- # Checkout the master branch into a subdirectory
75- - name : Checkout master branch
82+ # Checkout a trusted branch to build the tooling from
83+ - name : Checkout tools branch
7684 uses : actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
7785 with :
7886 # Recall that on the `leanprover-community/mathlib4-nightly-testing` repository,
7987 # we don't maintain a `master` branch at all.
8088 # For PRs and pushes to this repository, we will use `nightly-testing-green` instead,
8189 # so that even when `nightly-testing` is broken, we can still build tools from a known good state.
82- ref : ${{ github.repository == 'leanprover-community/mathlib4-nightly-testing' && 'nightly-testing-green' || 'master' }}
83- path : master -branch
90+ ref : ${{ inputs.tools_branch_ref != '' && inputs.tools_branch_ref || ( github.repository == 'leanprover-community/mathlib4-nightly-testing' && 'nightly-testing-green' || 'master') }}
91+ path : tools -branch
8492
8593 # Checkout the PR branch into a subdirectory
8694 - name : Checkout PR branch
@@ -160,18 +168,18 @@ jobs:
160168 # Set it as an environment variable for subsequent steps
161169 echo "LEAN_SRC_PATH=$LEAN_SRC_PATH" >> "$GITHUB_ENV"
162170
163- - name : build master -branch tools
164- shell : bash # We're only building the `master` branch version of the tools, so don't need to run inside landrun.
171+ - name : build tools -branch tools
172+ shell : bash # We're only building a trusted branch with the tools, so no need to run inside landrun.
165173 run : |
166- cd master -branch
174+ cd tools -branch
167175 lake build cache check-yaml graph
168176 ls .lake/build/bin/cache
169177 ls .lake/build/bin/check-yaml
170178 ls .lake/packages/importGraph/.lake/build/bin/graph
171179
172180 - name : cleanup .cache/mathlib
173181 # This needs write access to .cache/mathlib, so can't be run inside landrun.
174- # However it is only using the `master ` version of `cache`, so is safe to run outside landrun.
182+ # However it is only using the `tools ` version of `cache`, so is safe to run outside landrun.
175183 shell : bash
176184 run : |
177185 # Define the cache directory path
@@ -190,8 +198,8 @@ jobs:
190198 # Check if size exceeds 10GB
191199 if [ "$DIR_SIZE" -gt "10737418240" ]; then
192200 echo "Cache size exceeds threshold, running lake exe cache clean"
193- # We use the master -branch version of `cache`.
194- cd master -branch
201+ # We use the tools -branch version of `cache`.
202+ cd tools -branch
195203 lake exe cache clean
196204 fi
197205
@@ -281,15 +289,15 @@ jobs:
281289
282290 - name : get cache (1/3 - setup and initial fetch)
283291 id : get_cache_part1_setup
284- shell : bash # only runs `cache get` from `master -branch`, so doesn't need to be inside landrun
292+ shell : bash # only runs `cache get` from `tools -branch`, so doesn't need to be inside landrun
285293 run : |
286294 cd pr-branch
287295 echo "Removing old Mathlib build directories prior to cache fetch..."
288296 rm -rf .lake/build/lib/lean/Mathlib
289297
290298 # Fail quickly if the cache is completely cold, by checking for Mathlib.Init
291299 echo "Attempting to fetch olean for Mathlib/Init.lean from cache..."
292- ../master -branch/.lake/build/bin/cache get Mathlib/Init.lean
300+ ../tools -branch/.lake/build/bin/cache get Mathlib/Init.lean
293301
294302 - name : get cache (2/3 - test Mathlib.Init cache)
295303 id : get_cache_part2_test
@@ -303,16 +311,16 @@ jobs:
303311
304312 - name : get cache (3/3 - finalize cache operation)
305313 id : get
306- shell : bash # only runs `cache get` from `master -branch`, so doesn't need to be inside landrun
314+ shell : bash # only runs `cache get` from `tools -branch`, so doesn't need to be inside landrun
307315 run : |
308316 cd pr-branch
309317 if [[ "${{ steps.get_cache_part2_test.outcome }}" == "success" ]]; then
310318 echo "Fetching all remaining cache..."
311319
312- ../master -branch/.lake/build/bin/cache get
320+ ../tools -branch/.lake/build/bin/cache get
313321
314322 # Run again with --repo, to ensure we actually get the oleans.
315- ../master -branch/.lake/build/bin/cache --repo=${{ github.event.pull_request.head.repo.full_name || github.repository }} get
323+ ../tools -branch/.lake/build/bin/cache --repo=${{ github.event.pull_request.head.repo.full_name || github.repository }} get
316324 else
317325 echo "WARNING: 'lake build --no-build -v Mathlib.Init' failed."
318326 echo "No cache for 'Mathlib.Init' available or it could not be prepared."
@@ -346,7 +354,7 @@ jobs:
346354 fi
347355 echo "::endgroup::"
348356
349- ../master -branch/scripts/lake-build-with-retry.sh Mathlib
357+ ../tools -branch/scripts/lake-build-with-retry.sh Mathlib
350358 # results of build at pr-branch/.lake/build_summary_Mathlib.json
351359 - name : end gh-problem-match-wrap for build step
352360 uses : leanprover-community/gh-problem-matcher-wrap@20007cb926a46aa324653a387363b52f07709845 # 2025-04-23
@@ -372,15 +380,15 @@ jobs:
372380 # Trim trailing whitespace from secrets to prevent issues with accidentally added spaces
373381 export MATHLIB_CACHE_SAS="${MATHLIB_CACHE_SAS_RAW%"${MATHLIB_CACHE_SAS_RAW##*[![:space:]]}"}"
374382
375- # Use the trusted cache tool from master -branch
383+ # Use the trusted cache tool from tools -branch
376384 # TODO: this is not doing anything currently, and needs to be integrated with put-unpacked
377- # ../master -branch/.lake/build/bin/cache commit || true
385+ # ../tools -branch/.lake/build/bin/cache commit || true
378386 # run this in CI if it gets an incorrect lake hash for existing cache files somehow
379- # ../master -branch/.lake/build/bin/cache put!
387+ # ../tools -branch/.lake/build/bin/cache put!
380388 # do not try to upload files just downloaded
381389
382390 echo "Uploading cache to Azure..."
383- MATHLIB_CACHE_USE_CLOUDFLARE=0 ../master -branch/.lake/build/bin/cache --repo=${{ github.event.pull_request.head.repo.full_name || github.repository }} put-unpacked
391+ MATHLIB_CACHE_USE_CLOUDFLARE=0 ../tools -branch/.lake/build/bin/cache --repo=${{ github.event.pull_request.head.repo.full_name || github.repository }} put-unpacked
384392 env :
385393 MATHLIB_CACHE_SAS_RAW : ${{ secrets.MATHLIB_CACHE_SAS }}
386394
@@ -396,23 +404,23 @@ jobs:
396404 shell : bash
397405 run : |
398406 cd pr-branch
399- ../master -branch/.lake/build/bin/cache get Archive.lean
400- ../master -branch/.lake/build/bin/cache get Counterexamples.lean
407+ ../tools -branch/.lake/build/bin/cache get Archive.lean
408+ ../tools -branch/.lake/build/bin/cache get Counterexamples.lean
401409
402410 - name : build archive
403411 id : archive
404412 continue-on-error : true
405413 run : |
406414 cd pr-branch
407- ../master -branch/scripts/lake-build-with-retry.sh Archive
415+ ../tools -branch/scripts/lake-build-with-retry.sh Archive
408416 # results of build at pr-branch/.lake/build_summary_Archive.json
409417
410418 - name : build counterexamples
411419 id : counterexamples
412420 continue-on-error : true
413421 run : |
414422 cd pr-branch
415- ../master -branch/scripts/lake-build-with-retry.sh Counterexamples
423+ ../tools -branch/scripts/lake-build-with-retry.sh Counterexamples
416424 # results of build at pr-branch/.lake/build_summary_Counterexamples.json
417425
418426 - name : Check if building Archive or Counterexamples failed
@@ -436,8 +444,8 @@ jobs:
436444 export MATHLIB_CACHE_SAS="${MATHLIB_CACHE_SAS_RAW%"${MATHLIB_CACHE_SAS_RAW##*[![:space:]]}"}"
437445
438446 echo "Uploading Archive and Counterexamples cache to Azure..."
439- MATHLIB_CACHE_USE_CLOUDFLARE=0 ../master -branch/.lake/build/bin/cache --repo=${{ github.event.pull_request.head.repo.full_name || github.repository }} put-unpacked Archive.lean
440- MATHLIB_CACHE_USE_CLOUDFLARE=0 ../master -branch/.lake/build/bin/cache --repo=${{ github.event.pull_request.head.repo.full_name || github.repository }} put-unpacked Counterexamples.lean
447+ MATHLIB_CACHE_USE_CLOUDFLARE=0 ../tools -branch/.lake/build/bin/cache --repo=${{ github.event.pull_request.head.repo.full_name || github.repository }} put-unpacked Archive.lean
448+ MATHLIB_CACHE_USE_CLOUDFLARE=0 ../tools -branch/.lake/build/bin/cache --repo=${{ github.event.pull_request.head.repo.full_name || github.repository }} put-unpacked Counterexamples.lean
441449 env :
442450 MATHLIB_CACHE_SAS_RAW : ${{ secrets.MATHLIB_CACHE_SAS }}
443451
@@ -460,7 +468,7 @@ jobs:
460468 id : test
461469 run : |
462470 cd pr-branch
463- ../master -branch/scripts/lake-build-wrapper.py .lake/build_summary_MathlibTest.json lake --iofail test
471+ ../tools -branch/scripts/lake-build-wrapper.py .lake/build_summary_MathlibTest.json lake --iofail test
464472 - name : end gh-problem-match-wrap for test step
465473 uses : leanprover-community/gh-problem-matcher-wrap@20007cb926a46aa324653a387363b52f07709845 # 2025-04-23
466474 with :
@@ -584,8 +592,8 @@ jobs:
584592 TEST_OUTCOME : ${{ steps.test.outcome }}
585593 NIGHTLY_TESTING_REPO : leanprover-community/mathlib4-nightly-testing
586594 run : |
587- master -branch/scripts/lean-pr-testing-comments.sh lean
588- master -branch/scripts/lean-pr-testing-comments.sh batteries
595+ tools -branch/scripts/lean-pr-testing-comments.sh lean
596+ tools -branch/scripts/lean-pr-testing-comments.sh batteries
589597
590598 post_steps :
591599 name : Post-Build Step
@@ -678,6 +686,7 @@ jobs:
678686
679687 final :
680688 name : Post-CI job
689+ if : ${{ inputs.run_post_ci }}
681690 needs : [style_lint, build, post_steps]
682691 runs-on : ubuntu-latest
683692 steps :
@@ -774,7 +783,10 @@ jobs:
774783 echo "username=$USERNAME" >> "$GITHUB_OUTPUT"
775784 echo "Found label actor: $USERNAME"
776785
777- - if : contains(steps.PR.outputs.pr_labels, 'auto-merge-after-CI')
786+ - if : >- # bot usernames will cause this step to error with "Could not resolve to a User..."
787+ contains(steps.PR.outputs.pr_labels, 'auto-merge-after-CI') &&
788+ steps.get-label-actor.outputs.username != 'mathlib-nolints' &&
789+ steps.get-label-actor.outputs.username != 'mathlib-update-dependencies'
778790 name: check team membership
779791 uses: tspascoal/get-user-teams-membership@57e9f42acd78f4d0f496b3be4368fc5f62696662 # v3.0.0
780792 id: actorTeams
@@ -784,11 +796,18 @@ jobs:
784796 username: ${{ steps.get-label-actor.outputs.username }}
785797 GITHUB_TOKEN: ${{ secrets.MATHLIB_REVIEWERS_TEAM_KEY }} # (Requires scope: `read:org`)
786798
787- # The create-github-app-token README states that this token is masked and will not be logged accidentally.
788- - if : ${{ contains(steps.PR.outputs.pr_labels, 'auto-merge-after-CI') && (contains(steps.actorTeams.outputs.teams, 'mathlib-maintainers') || contains(steps.actorTeams.outputs.teams, 'bot-users')) }}
799+ - if : >-
800+ contains(steps.PR.outputs.pr_labels, 'auto-merge-after-CI') &&
801+ (
802+ steps.get-label-actor.outputs.username == 'mathlib-nolints' ||
803+ steps.get-label-actor.outputs.username == 'mathlib-update-dependencies' ||
804+ contains(steps.actorTeams.outputs.teams, 'mathlib-maintainers') ||
805+ contains(steps.actorTeams.outputs.teams, 'bot-users')
806+ )
789807 name: If `auto-merge-after-CI` is present, add a `bors merge` comment.
790808 uses: GrantBirki/comment@608e41b19bc973020ec0e189ebfdae935d7fe0cc # v2.1.1
791809 with:
810+ # The create-github-app-token README states that this token is masked and will not be logged accidentally.
792811 token: ${{ steps.auto-merge-app-token.outputs.token }}
793812 issue-number: ${{ steps.PR.outputs.number }}
794813 body: |
0 commit comments