Skip to content

Commit 2535e4c

Browse files
Merge master into nightly-testing
2 parents 8889baa + 738faa5 commit 2535e4c

File tree

363 files changed

+4874
-1534
lines changed

Some content is hidden

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

363 files changed

+4874
-1534
lines changed

.github/workflows/build_template.yml

Lines changed: 99 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ jobs:
3737
build-outcome: ${{ steps.build.outcome }}
3838
archive-outcome: ${{ steps.archive.outcome }}
3939
counterexamples-outcome: ${{ steps.counterexamples.outcome }}
40+
cache-staging-has-files: ${{ steps.cache_staging_check.outputs.has_files }}
4041
get-cache-outcome: ${{ steps.get.outcome }}
4142
lint-outcome: ${{ steps.lint.outcome }}
4243
mk_all-outcome: ${{ steps.mk_all.outcome }}
@@ -367,31 +368,6 @@ jobs:
367368
cd pr-branch
368369
du .lake/build/lib/lean/Mathlib || echo "This code should be unreachable"
369370
370-
# The cache secrets are available here, so we must not run any untrusted code.
371-
- name: Upload cache to Azure
372-
# We only upload the cache if the build started (whether succeeding, failing, or cancelled)
373-
# but not if any earlier step failed or was cancelled.
374-
# See discussion at https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/Some.20files.20not.20found.20in.20the.20cache/near/407183836
375-
if: ${{ always() && steps.get.outcome == 'success' }}
376-
shell: bash
377-
run: |
378-
cd pr-branch
379-
380-
# Trim trailing whitespace from secrets to prevent issues with accidentally added spaces
381-
export MATHLIB_CACHE_SAS="${MATHLIB_CACHE_SAS_RAW%"${MATHLIB_CACHE_SAS_RAW##*[![:space:]]}"}"
382-
383-
# Use the trusted cache tool from tools-branch
384-
# TODO: this is not doing anything currently, and needs to be integrated with put-unpacked
385-
# ../tools-branch/.lake/build/bin/cache commit || true
386-
# run this in CI if it gets an incorrect lake hash for existing cache files somehow
387-
# ../tools-branch/.lake/build/bin/cache put!
388-
# do not try to upload files just downloaded
389-
390-
echo "Uploading cache to Azure..."
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
392-
env:
393-
MATHLIB_CACHE_SAS_RAW: ${{ secrets.MATHLIB_CACHE_SAS }}
394-
395371
# Note: we should not be including `Archive` and `Counterexamples` in the cache.
396372
# We do this for now for the sake of not rebuilding them in every CI run
397373
# even when they are not touched.
@@ -423,6 +399,52 @@ jobs:
423399
../tools-branch/scripts/lake-build-with-retry.sh Counterexamples
424400
# results of build at pr-branch/.lake/build_summary_Counterexamples.json
425401
402+
- name: prepare cache staging directory
403+
if: ${{ steps.build.outcome == 'success' }}
404+
shell: bash
405+
run: |
406+
rm -rf cache-staging
407+
mkdir -p cache-staging
408+
409+
- name: stage Mathlib cache files
410+
if: ${{ steps.build.outcome == 'success' }}
411+
shell: bash
412+
run: |
413+
cd pr-branch
414+
lake env ../tools-branch/.lake/build/bin/cache --staging-dir="../cache-staging" stage
415+
416+
- name: stage Archive cache files
417+
if: ${{ steps.archive.outcome == 'success' }}
418+
shell: bash
419+
run: |
420+
cd pr-branch
421+
lake env ../tools-branch/.lake/build/bin/cache --staging-dir="../cache-staging" stage Archive.lean
422+
423+
- name: stage Counterexamples cache files
424+
if: ${{ steps.counterexamples.outcome == 'success' }}
425+
shell: bash
426+
run: |
427+
cd pr-branch
428+
lake env ../tools-branch/.lake/build/bin/cache --staging-dir="../cache-staging" stage Counterexamples.lean
429+
430+
- name: check cache staging contents
431+
id: cache_staging_check
432+
if: ${{ steps.build.outcome == 'success' }}
433+
shell: bash
434+
run: |
435+
if find cache-staging -type f -name '*.ltar' -print -quit | grep -q .; then
436+
echo "has_files=true" >> "$GITHUB_OUTPUT"
437+
else
438+
echo "has_files=false" >> "$GITHUB_OUTPUT"
439+
fi
440+
441+
- name: upload cache staging artifact
442+
if: ${{ steps.cache_staging_check.outputs.has_files == 'true' }}
443+
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
444+
with:
445+
name: cache-staging
446+
path: cache-staging/
447+
426448
- name: Check if building Archive or Counterexamples failed
427449
if: steps.archive.outcome == 'failure' || steps.counterexamples.outcome == 'failure'
428450
run: |
@@ -434,21 +456,6 @@ jobs:
434456
fi
435457
exit 1
436458
437-
# The cache secrets are available here, so we must not run any untrusted code.
438-
- name: Upload Archive and Counterexamples cache to Azure
439-
shell: bash
440-
run: |
441-
cd pr-branch
442-
443-
# Trim trailing whitespace from secrets to prevent issues with accidentally added spaces
444-
export MATHLIB_CACHE_SAS="${MATHLIB_CACHE_SAS_RAW%"${MATHLIB_CACHE_SAS_RAW##*[![:space:]]}"}"
445-
446-
echo "Uploading Archive and Counterexamples cache to Azure..."
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
449-
env:
450-
MATHLIB_CACHE_SAS_RAW: ${{ secrets.MATHLIB_CACHE_SAS }}
451-
452459
- name: Check {Mathlib, Tactic, Counterexamples, Archive}.lean
453460
if: ${{ always() && steps.mk_all.outcome != 'skipped' }}
454461
run: |
@@ -595,9 +602,59 @@ jobs:
595602
tools-branch/scripts/lean-pr-testing-comments.sh lean
596603
tools-branch/scripts/lean-pr-testing-comments.sh batteries
597604
605+
upload_cache:
606+
name: Upload to cache
607+
needs: [build]
608+
runs-on: ubuntu-latest # These steps run on a GitHub runner; no landrun sandboxing is needed.
609+
# We only upload the cache if the build started (whether succeeding, failing, or cancelled)
610+
# but not if any earlier step failed or was cancelled.
611+
# See discussion at https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/Some.20files.20not.20found.20in.20the.20cache/near/407183836
612+
if: ${{ always() && needs.build.outputs.build-outcome == 'success' && needs.build.outputs.get-cache-outcome == 'success' && needs.build.outputs.cache-staging-has-files == 'true' }}
613+
steps:
614+
- name: Checkout tools branch
615+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
616+
with:
617+
ref: ${{ inputs.tools_branch_ref != '' && inputs.tools_branch_ref || (github.repository == 'leanprover-community/mathlib4-nightly-testing' && 'nightly-testing-green' || 'master') }}
618+
fetch-depth: 1
619+
620+
- name: Configure Lean
621+
uses: leanprover/lean-action@c544e89643240c6b398f14a431bcdc6309e36b3e # v1.4.0
622+
with:
623+
auto-config: false # Don't run `lake build`, `lake test`, or `lake lint` automatically.
624+
use-github-cache: false
625+
use-mathlib-cache: false # This can be re-enabled once we are confident in the cache again.
626+
reinstall-transient-toolchain: true
627+
628+
- name: build cache executable
629+
run: |
630+
lake build cache
631+
CACHE_BIN="$(pwd)/.lake/build/bin/cache"
632+
if [ ! -x "$CACHE_BIN" ]; then
633+
echo "cache binary not found: $CACHE_BIN"
634+
exit 1
635+
fi
636+
echo "CACHE_BIN=$CACHE_BIN" >> "$GITHUB_ENV"
637+
638+
- name: Download cache staging artifact
639+
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
640+
with:
641+
name: cache-staging
642+
path: cache-staging
643+
644+
- name: Upload staged cache to Azure
645+
shell: bash
646+
run: |
647+
# Trim trailing whitespace from secrets to prevent issues with accidentally added spaces
648+
export MATHLIB_CACHE_SAS="${MATHLIB_CACHE_SAS_RAW%"${MATHLIB_CACHE_SAS_RAW##*[![:space:]]}"}"
649+
650+
echo "Uploading cache to Azure..."
651+
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 }}
652+
env:
653+
MATHLIB_CACHE_SAS_RAW: ${{ secrets.MATHLIB_CACHE_SAS }}
654+
598655
post_steps:
599656
name: Post-Build Step
600-
needs: [build]
657+
needs: [build, upload_cache]
601658
runs-on: ubuntu-latest # Note these steps run on disposable GitHub runners, so no landrun sandboxing is needed.
602659
steps:
603660

@@ -674,6 +731,7 @@ jobs:
674731
675732
# We no longer run `lean4checker` in regular CI, as it is quite expensive for little benefit.
676733
# Instead we run it in a cron job on master: see `daily.yml`.
734+
677735
style_lint:
678736
name: Lint style
679737
runs-on: ubuntu-latest

.github/workflows/commit_verification.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ permissions:
2222

2323
env:
2424
TRANSIENT_PREFIX: "transient: "
25-
AUTO_PREFIX: "x: "
25+
# Support both "x " and "x: " (legacy) prefixes
26+
AUTO_PREFIX_COLON: "x: "
27+
AUTO_PREFIX_SPACE: "x "
2628

2729
jobs:
2830
verify:
@@ -46,8 +48,9 @@ jobs:
4648
HEAD_SHA="${{ github.event.pull_request.head.sha }}"
4749
4850
# Check if any commits have transient or auto prefix
51+
# Auto prefix can be "x " or "x: " (legacy)
4952
HAS_SPECIAL=$(git log --format="%s" "$BASE_SHA..$HEAD_SHA" | \
50-
grep -E "^(${TRANSIENT_PREFIX}|${AUTO_PREFIX})" || true)
53+
grep -E "^(${TRANSIENT_PREFIX}|${AUTO_PREFIX_COLON}|${AUTO_PREFIX_SPACE})" || true)
5154
5255
if [[ -n "$HAS_SPECIAL" ]]; then
5356
echo "has_special=true" >> "$GITHUB_OUTPUT"

.github/workflows/nightly_bump_and_merge.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ jobs:
230230
}
231231
232232
# Find tags that are ancestors of this branch with the right format
233-
LATEST_TAG=$(git tag --merged HEAD | grep "nightly-testing-[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}" | sort -r | head -n 1)
233+
LATEST_TAG=$(git tag --merged HEAD | grep "nightly-testing-[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}\(-rev[0-9]\+\)\?" | sort -rV | head -n 1)
234234
echo "Latest tag found for $BRANCH: ${LATEST_TAG:-none}"
235235
236236
# Return to nightly-testing branch

.github/workflows/nightly_detect_failure.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ jobs:
274274
core.setOutput('toolchain_content', content);
275275
core.setOutput('branch_name', branchName);
276276
277-
const match = content.match(/leanprover\/lean4:nightly-(\d{4}-\d{2}-\d{2})/);
277+
const match = content.match(/leanprover\/lean4:nightly-(\d{4}-\d{2}-\d{2}(?:-rev\d+)?)/);
278278
if (!match) {
279279
core.setFailed('Toolchain pattern did not match');
280280
return null;
@@ -292,7 +292,7 @@ jobs:
292292
type: 'stream'
293293
topic: 'Mathlib status updates'
294294
content: |
295-
⚠️ Warning: The lean-toolchain file in bump branch `${{ steps.bump_version.outputs.branch_name }}` does not match the expected pattern 'leanprover/lean4:nightly-YYYY-MM-DD'.
295+
⚠️ Warning: The lean-toolchain file in bump branch `${{ steps.bump_version.outputs.branch_name }}` does not match the expected pattern 'leanprover/lean4:nightly-YYYY-MM-DD(-revK)'.
296296
297297
**Branch:** `${{ steps.bump_version.outputs.branch_name }}`
298298
**File URL:** https://github.com/${{ github.repository }}/blob/${{ steps.bump_version.outputs.branch_sha }}/lean-toolchain
@@ -418,7 +418,7 @@ jobs:
418418
if last_bot_message:
419419
last_content = last_bot_message['content']
420420
# Extract nightly date and bump branch from last bot message
421-
date_match = re.search(r'bump/nightly-(\d{4}-\d{2}-\d{2})', last_content)
421+
date_match = re.search(r'bump/nightly-(\d{4}-\d{2}-\d{2}(?:-rev\d+)?)', last_content)
422422
branch_match = re.search(r'PR that to (bump/v[\d.]+)', last_content)
423423
if date_match and branch_match:
424424
last_date = date_match.group(1)

.github/workflows/nolints.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ jobs:
3636
- name: Create Pull Request
3737
uses: peter-evans/create-pull-request@c0f553fe549906ede9cf27b5156039d195d2ece0 # v8.1.0
3838
with:
39+
# this needs to be set, otherwise the last person who edited the `cron` line may get tagged
40+
author: "mathlib-nolints[bot] <258989889+mathlib-nolints[bot]@users.noreply.github.com>"
3941
token: ${{ steps.app-token.outputs.token }}
4042
commit-message: "chore(scripts): update nolints.json"
4143
branch: "nolints"
@@ -44,5 +46,7 @@ jobs:
4446
body: |
4547
I am happy to remove some nolints for you!
4648
49+
---
50+
4751
[workflow run for this PR](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})
4852
labels: "auto-merge-after-CI"

.github/workflows/remove_deprecated_decls.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,8 @@ jobs:
218218
if: ${{ steps.process_dates.outputs.from_date && toJson(inputs.dry_run) != 'true' && steps.find-pr.outputs.pr_found != 'true' }}
219219
uses: peter-evans/create-pull-request@c0f553fe549906ede9cf27b5156039d195d2ece0 # v8.1.0
220220
with:
221+
# this needs to be set, otherwise the last person who edited the `cron` line may get tagged
222+
author: "mathlib-nolints[bot] <258989889+mathlib-nolints[bot]@users.noreply.github.com>"
221223
token: ${{ steps.app-token.outputs.token }}
222224
commit-message: "chore: remove declarations deprecated between ${{ steps.process_dates.outputs.from_date }} and ${{ steps.process_dates.outputs.to_date }}"
223225
branch: ${{ env.BRANCH_NAME }}

.github/workflows/update_dependencies.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ jobs:
124124
if: ${{ steps.pr-title.outcome == 'success' }}
125125
uses: peter-evans/create-pull-request@c0f553fe549906ede9cf27b5156039d195d2ece0 # v8.1.0
126126
with:
127+
# this needs to be set, otherwise the last person who edited the `cron` line may get tagged
128+
author: "mathlib-update-dependencies[bot] <258990618+mathlib-update-dependencies[bot]@users.noreply.github.com>"
127129
token: ${{ steps.app-token.outputs.token }}
128130
commit-message: "chore: update Mathlib dependencies ${{ env.timestamp }}"
129131
# this branch is referenced in update_dependencies_zulip.yml
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
name: Zulip emoji CI status
2+
3+
on:
4+
workflow_run:
5+
workflows: ["continuous integration", "continuous integration (mathlib forks)"]
6+
types: [requested, completed]
7+
8+
# Limit permissions for GITHUB_TOKEN for the entire workflow
9+
permissions:
10+
contents: read
11+
pull-requests: read
12+
# All other permissions are implicitly 'none'
13+
14+
jobs:
15+
update_ci_emoji:
16+
runs-on: ubuntu-latest
17+
if: github.repository == 'leanprover-community/mathlib4'
18+
steps:
19+
- name: Determine PR number
20+
id: pr
21+
env:
22+
GH_TOKEN: ${{ github.token }}
23+
HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }}
24+
HEAD_REPO_OWNER: ${{ github.event.workflow_run.head_repository.owner.login }}
25+
HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
26+
run: |
27+
# Try to get PR number from the workflow_run event
28+
PR_NUMBER=$(echo '${{ toJSON(github.event.workflow_run.pull_requests) }}' | jq -r '.[0].number // empty')
29+
# For push-triggered CI (non-fork PRs), pull_requests may be empty;
30+
# fall back to looking up the PR by branch name.
31+
# Use owner:branch format to avoid matching the wrong PR when
32+
# multiple forks use the same branch name.
33+
if [ -z "$PR_NUMBER" ]; then
34+
PR_NUMBER=$(gh pr list --repo "${{ github.repository }}" --head "$HEAD_REPO_OWNER:$HEAD_BRANCH" --state open --json number,headRefOid --jq ".[] | select(.headRefOid == \"$HEAD_SHA\") | .number" 2>/dev/null || true)
35+
fi
36+
# If owner-qualified lookup failed, try without owner (for same-repo branches)
37+
if [ -z "$PR_NUMBER" ]; then
38+
PR_NUMBER=$(gh pr list --repo "${{ github.repository }}" --head "$HEAD_BRANCH" --state open --json number,headRefOid --jq ".[] | select(.headRefOid == \"$HEAD_SHA\") | .number" 2>/dev/null || true)
39+
fi
40+
if [ -z "$PR_NUMBER" ]; then
41+
echo "No PR found for branch $HEAD_REPO_OWNER:$HEAD_BRANCH at $HEAD_SHA, skipping"
42+
echo "skip=true" >> "$GITHUB_OUTPUT"
43+
else
44+
echo "Found PR #$PR_NUMBER"
45+
echo "pr_number=$PR_NUMBER" >> "$GITHUB_OUTPUT"
46+
echo "skip=false" >> "$GITHUB_OUTPUT"
47+
fi
48+
49+
- name: Determine CI action
50+
id: action
51+
if: steps.pr.outputs.skip != 'true'
52+
run: |
53+
EVENT_ACTION="${{ github.event.action }}"
54+
CONCLUSION="${{ github.event.workflow_run.conclusion }}"
55+
echo "Event action: $EVENT_ACTION, conclusion: $CONCLUSION"
56+
if [ "$EVENT_ACTION" = "requested" ]; then
57+
echo "ci_action=ci-running" >> "$GITHUB_OUTPUT"
58+
elif [ "$EVENT_ACTION" = "completed" ]; then
59+
case "$CONCLUSION" in
60+
success)
61+
echo "ci_action=ci-success" >> "$GITHUB_OUTPUT"
62+
;;
63+
cancelled)
64+
# Clear the running emoji. A new run may or may not follow
65+
# (manual cancel, branch deleted, etc.), so don't leave stale 🟡.
66+
echo "ci_action=ci-cancelled" >> "$GITHUB_OUTPUT"
67+
;;
68+
*)
69+
echo "ci_action=ci-failure" >> "$GITHUB_OUTPUT"
70+
;;
71+
esac
72+
fi
73+
74+
- name: Checkout mathlib repository
75+
if: steps.pr.outputs.skip != 'true' && steps.action.outputs.ci_action != 'skip'
76+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
77+
with:
78+
ref: master
79+
sparse-checkout: |
80+
scripts/zulip_emoji_reactions.py
81+
82+
- name: Set up Python
83+
if: steps.pr.outputs.skip != 'true' && steps.action.outputs.ci_action != 'skip'
84+
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
85+
with:
86+
python-version: '3.x'
87+
88+
- name: Install dependencies
89+
if: steps.pr.outputs.skip != 'true' && steps.action.outputs.ci_action != 'skip'
90+
run: |
91+
python -m pip install --upgrade pip
92+
pip install zulip
93+
94+
- name: Update CI emoji
95+
if: steps.pr.outputs.skip != 'true' && steps.action.outputs.ci_action != 'skip'
96+
env:
97+
ZULIP_API_KEY: ${{ secrets.ZULIP_API_KEY }}
98+
ZULIP_EMAIL: github-mathlib4-bot@leanprover.zulipchat.com
99+
ZULIP_SITE: https://leanprover.zulipchat.com
100+
run: |
101+
python scripts/zulip_emoji_reactions.py "$ZULIP_API_KEY" "$ZULIP_EMAIL" "$ZULIP_SITE" "${{ steps.action.outputs.ci_action }}" "none" "${{ steps.pr.outputs.pr_number }}"

0 commit comments

Comments
 (0)