Skip to content

Commit 5c6d055

Browse files
committed
ci: Add workflow to support CI experiments (#35145)
This PR introduces a `ci_dev.yml` workflow as a "safe playground" for manually experimenting with CI changes without touching the main `build.yml`/`bors.yml` paths. It is manually dispatched and constrained to `ci-dev/*` branches, so iteration on workflow logic can happen in isolation. To make those experiments useful, the workflow now exposes manual inputs for `tools_branch_ref` and `pr_branch_ref`, both defaulting to the triggering commit when left empty. This lets us test template changes against arbitrary refs when needed, while preserving the “build this commit” default for quick runs.
1 parent d6c9e7a commit 5c6d055

File tree

4 files changed

+84
-30
lines changed

4 files changed

+84
-30
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ on:
1010
# ignore staging and trying branches used by bors, these are handled by bors.yml
1111
- 'staging'
1212
- 'trying'
13+
# ignore branches meant for experiments
14+
- 'ci-dev/**'
1315
merge_group:
1416

1517
concurrency:

.github/workflows/build_template.yml

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
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

33
on:
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:

.github/workflows/ci_dev.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: ci dev
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
tools_branch_ref:
7+
description: ref for tools checkout (defaults to 'this commit')
8+
required: false
9+
type: string
10+
default: ''
11+
pr_branch_ref:
12+
description: ref for building-branch checkout (defaults to 'this commit')
13+
required: false
14+
type: string
15+
default: ''
16+
run_post_ci:
17+
description: Run the post-CI job?
18+
required: false
19+
type: boolean
20+
default: false # We shouldn't need this job in typical experiments
21+
22+
# Limit permissions for GITHUB_TOKEN for the entire workflow
23+
permissions:
24+
contents: read
25+
# By default let's remove this permission (which is present in the other build pipelines)
26+
# from the CI experimentation runs to avoid unwitting side effects
27+
# pull-requests: write
28+
29+
jobs:
30+
build:
31+
name: ci (dev branch)
32+
# For sanity and intentionality, let's only trigger this from branches ci-dev/*
33+
if: ${{ github.repository == 'leanprover-community/mathlib4' && github.ref_type == 'branch' && startsWith(github.ref_name, 'ci-dev/') }}
34+
uses: ./.github/workflows/build_template.yml
35+
with:
36+
concurrency_group: ${{ github.workflow }}-${{ github.ref }}
37+
# Use the tools from 'this branch', as our changes in the tools might be relevant for experiments
38+
tools_branch_ref: ${{ inputs.tools_branch_ref != '' && inputs.tools_branch_ref || github.sha }}
39+
pr_branch_ref: ${{ inputs.pr_branch_ref != '' && inputs.pr_branch_ref || github.sha }}
40+
run_post_ci: ${{ inputs.run_post_ci }}
41+
runs_on: pr
42+
secrets: inherit

.github/workflows/pre-commit.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ on:
1111
# ignore staging and trying branches used by bors, these are handled by bors.yml
1212
- 'staging'
1313
- 'trying'
14+
- 'ci-dev/**' # ignore branches meant for experiments
1415
- 'master'
1516
pull_request:
1617

0 commit comments

Comments
 (0)