Skip to content

Commit 35cd860

Browse files
authored
Merge branch 'master' into nontriviality
2 parents abb53c1 + a2306ec commit 35cd860

File tree

509 files changed

+13325
-5396
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

509 files changed

+13325
-5396
lines changed

.github/workflows/add_label_from_diff.yaml

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,33 +21,42 @@ jobs:
2121
# Don't run on forks, where we wouldn't have permissions to add the label anyway.
2222
if: github.repository == 'leanprover-community/mathlib4'
2323
steps:
24-
- name: Checkout code
24+
- name: Checkout master branch to build autolabel from
2525
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
2626
with:
27-
ref: ${{ github.event.pull_request.head.sha }}
28-
fetch-depth: 0
27+
ref: master
28+
path: tools
2929
- name: Configure Lean
3030
uses: leanprover/lean-action@c544e89643240c6b398f14a431bcdc6309e36b3e # v1.4.0
3131
with:
3232
auto-config: false
3333
use-github-cache: false
3434
use-mathlib-cache: false
35-
- name: lake exe autolabel
35+
lake-package-directory: tools # Building here
36+
- name: Build autolabel from master
37+
working-directory: tools
38+
run: |
39+
lake build autolabel
40+
- name: Checkout branch to label
41+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
42+
with:
43+
ref: ${{ github.event.pull_request.head.sha || github.sha }}
44+
fetch-depth: 0
45+
path: pr-branch
46+
- name: Run autolabel
47+
working-directory: pr-branch
3648
run: |
37-
# the checkout dance, to avoid a detached head
38-
git checkout master
39-
git checkout -
40-
labels="$(lake exe autolabel)"
49+
labels="$("${GITHUB_WORKSPACE}/tools/.lake/build/bin/autolabel")"
4150
printf '%s\n' "${labels}"
4251
# extract
4352
label="$(printf '%s' "${labels}" | sed -n 's=^::notice::.*#\[\([^,]*\)\].*=\1=p')"
4453
printf 'label: "%s"\n' "${label}"
45-
if [ -n "${label}" ]
54+
if [ -n "${label}" ] && [ -n "${PR_NUMBER}" ]
4655
then
4756
printf 'Applying label %s\n' "${label}"
4857
# we use curl rather than octokit/request-action so that the job won't fail
4958
# (and send an annoying email) if the labels don't exist
50-
url="https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels"
59+
url="https://api.github.com/repos/${{ github.repository }}/issues/${PR_NUMBER}/labels"
5160
printf 'url: %s\n' "${url}"
5261
jsonLabel="$(printf '{"labels":["%s"]}' "${label}")"
5362
printf 'jsonLabel: %s\n' "${jsonLabel}"
@@ -62,3 +71,6 @@ jobs:
6271
fi
6372
env:
6473
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
74+
# the PR number could be undefined in workflows triggered by 'push',
75+
# in which case we only log the applicable label and exit
76+
PR_NUMBER: ${{ github.event.pull_request.number }}

.github/workflows/bors.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ jobs:
2626
with:
2727
concurrency_group: ${{ github.workflow }}-${{ github.ref }}-${{ github.run_id }}
2828
pr_branch_ref: ${{ github.sha }}
29+
# bors runs should build the tools from their commit-under-test: after all, we are trying to
30+
# test 'what would happen if this was merged', so we need to use the 'would-be-post-merge' tools
31+
tools_branch_ref: ${{ github.sha }}
2932
# We don't wan't 'bors try' runs to compete with merge-candidates, so we pool trying with PR runs
3033
runs_on: ${{ github.ref_name == 'trying' && 'pr' || 'bors' }}
3134
secrets: inherit

.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: 52 additions & 33 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:
@@ -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: |

.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

0 commit comments

Comments
 (0)