Skip to content

Commit 0f3829e

Browse files
committed
merge upstream
2 parents 61fbfc1 + 032b054 commit 0f3829e

4,359 files changed

Lines changed: 44794 additions & 19724 deletions

File tree

Some content is hidden

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

.github/actions/get-mathlib-ci/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ inputs:
1010
# Default pinned commit used by workflows unless they explicitly override.
1111
# Update this ref as needed to pick up changes to mathlib-ci scripts
1212
# This is also updated automatically by .github/workflows/update_dependencies.yml
13-
default: 78f34ded6a5f5aa11ea5b7c3120fe5d8422db1da
13+
default: e7a159e9a129f92fd07e6852a742485798678473
1414
path:
1515
description: Checkout destination path.
1616
required: false

.github/workflows/PR_summary.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ jobs:
2222
ref: ${{ github.event.pull_request.head.sha }}
2323
fetch-depth: 0
2424
path: pr-branch
25+
# Untrusted (potentially fork) checkout: don't persist the GITHUB_TOKEN into its .git/config.
26+
persist-credentials: false
2527

2628
- name: Checkout local actions
2729
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2

.github/workflows/add_label_from_diff.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ jobs:
4343
ref: ${{ github.event.pull_request.head.sha || github.sha }}
4444
fetch-depth: 0
4545
path: pr-branch
46+
# Untrusted (potentially fork) checkout: don't persist the GITHUB_TOKEN into its .git/config.
47+
persist-credentials: false
4648
- name: Run autolabel
4749
working-directory: pr-branch
4850
run: |

.github/workflows/bot_fix_style.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ on:
1212
# triggers on a review comment
1313
types: [created, edited]
1414

15+
# `lint-style-action` in `fix` mode pushes a style-fix commit and reacts/comments
16+
# on the PR. Grant exactly those scopes rather than inheriting the default token
17+
# permissions; all other scopes are implicitly 'none'.
18+
permissions:
19+
contents: write # push the style-fix commit to the PR branch
20+
pull-requests: write # add the bot's reaction/comment
21+
issues: write # PR comment reactions go through the issues API
22+
1523
jobs:
1624
fix_style:
1725
# we set some variables. The ones of the form `${{ X }}${{ Y }}` are typically not

.github/workflows/build_template.yml

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ jobs:
127127
ref: ${{ inputs.pr_branch_ref }}
128128
fetch-depth: 2 # we may fetch cache from the commit before this one (or earlier)
129129
path: pr-branch
130+
# This is an untrusted (potentially fork) checkout whose code we build.
131+
# Don't leave the GITHUB_TOKEN in pr-branch/.git/config, where that code could read it.
132+
persist-credentials: false
130133

131134
- name: Prepare DownstreamTest directory
132135
shell: bash
@@ -222,7 +225,7 @@ jobs:
222225
223226
- name: validate lake-manifest.json inputRevs
224227
# Only enforce this on the main mathlib4 repository, not on nightly-testing
225-
if: github.repository == 'leanprover-community/mathlib4'
228+
if: github.repository == 'leanprover-community/mathlib4' && github.ref_name != 'nightly-testing'
226229
shell: bash
227230
run: |
228231
cd pr-branch
@@ -513,19 +516,19 @@ jobs:
513516
run: |
514517
cd pr-branch
515518
set -o pipefail
516-
# Try running with --trace; if it fails due to argument parsing, the PR needs to merge master
519+
# If lint fails because the PR predates lake-lint configuration or the
520+
# old --trace argument-parsing behavior, ask the author to merge master.
517521
# We use .lake/ for the output file because landrun restricts /tmp access
518522
for attempt in 1 2; do
519-
if timeout 10m env LEAN_ABORT_ON_PANIC=1 stdbuf -oL lake exe runLinter --trace Mathlib 2>&1 | tee ".lake/lint_output_attempt_${attempt}.txt"; then
523+
if timeout 10m env LEAN_ABORT_ON_PANIC=1 stdbuf -oL lake lint -- --trace 2>&1 | tee ".lake/lint_output_attempt_${attempt}.txt"; then
520524
break
521525
fi
522526
status=${PIPESTATUS[0]}
523-
if grep -q "cannot parse arguments" ".lake/lint_output_attempt_${attempt}.txt"; then
527+
if grep -qE "cannot parse arguments|no lint driver configured" ".lake/lint_output_attempt_${attempt}.txt"; then
524528
echo ""
525529
echo "=============================================================================="
526-
echo "ERROR: Your branch uses an older version of runLinter that doesn't support"
527-
echo "the --trace flag. Please merge 'master' into your PR branch to get the"
528-
echo "updated linter, then push again."
530+
echo "ERROR: Your branch predates the current 'lake lint' configuration."
531+
echo "Please merge 'master' into your PR branch and push again."
529532
echo ""
530533
echo "You can do this with:"
531534
echo " git fetch upstream"
@@ -689,6 +692,8 @@ jobs:
689692
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
690693
with:
691694
ref: ${{ inputs.pr_branch_ref }}
695+
# Untrusted (potentially fork) checkout: don't persist the GITHUB_TOKEN into its .git/config.
696+
persist-credentials: false
692697

693698
- name: Configure Lean
694699
uses: leanprover/lean-action@38fbc41a8c28c4cbaec22d7f7de508ec2e7c0dd9 # v1.5.0
@@ -733,17 +738,36 @@ jobs:
733738
run: |
734739
lake exe graph
735740
741+
- name: Checkout local actions
742+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
743+
with:
744+
ref: ${{ github.workflow_sha }}
745+
fetch-depth: 1
746+
sparse-checkout: .github/actions
747+
path: workflow-actions
748+
749+
- name: Get mathlib-ci
750+
uses: ./workflow-actions/.github/actions/get-mathlib-ci
751+
752+
- name: dump declarations and transitive-import counts
753+
run: |
754+
lake env lean --run "${CI_SCRIPTS_DIR}/pr_summary/dumpReasonableDecls.lean" \
755+
--out decls.txt --imports-out imports.json Mathlib
756+
736757
- name: upload the import graph
737758
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
738759
with:
739760
name: import-graph
740-
path: import_graph.dot
741-
## the default is 90, but we build often, so unless there's a reason
742-
## to care about old copies in the future, just say 7 days for now
743-
retention-days: 7
761+
path: |
762+
import_graph.dot
763+
decls.txt
764+
imports.json
765+
## Master pushes: 90 days, so later PRs forked from these commits
766+
## can consume the dumps from the artifact. Other branches: 7 days.
767+
retention-days: ${{ github.ref == 'refs/heads/master' && '90' || '7' }}
744768

745769
- name: clean up the import graph file
746-
run: rm import_graph.dot
770+
run: rm -f import_graph.dot decls.txt imports.json
747771

748772
- name: check all scripts build successfully
749773
run: |

.github/workflows/decls-diff.yml

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
# Post-build workflow that emits a Lean-aware declarations-diff in the Actions
2+
# step summary for each successful PR build. Consumes the `import-graph`
3+
# artifact uploaded by `build_template.yml` on both sides (PR head + master
4+
# merge-base) and computes the diff via mathlib-ci's `decls-diff` action.
5+
#
6+
# Stage-2 scope: visibility only. No `### PR summary` comment patching; that
7+
# behaviour ships in a follow-up PR.
8+
9+
name: Declarations diff (post-build)
10+
11+
on:
12+
workflow_run:
13+
# Match the build workflows by their `name:` — `build.yml` (non-fork PRs,
14+
# push-triggered) and `build_fork.yml` (fork PRs, pull_request_target).
15+
workflows: ["continuous integration", "continuous integration (mathlib forks)"]
16+
types: [completed]
17+
18+
permissions:
19+
contents: read
20+
actions: read # for cross-workflow artifact downloads
21+
22+
jobs:
23+
diff:
24+
# The build never runs on a `pull_request` event: non-fork PRs build via
25+
# `build.yml` on `push` (head_branch = the PR branch), fork PRs via
26+
# `build_fork.yml` on `pull_request_target`. Accept both, and for `push`
27+
# exclude master and the non-PR maintenance branches.
28+
if: >-
29+
github.repository == 'leanprover-community/mathlib4'
30+
&& github.event.workflow_run.conclusion == 'success'
31+
&& (
32+
github.event.workflow_run.event == 'pull_request_target'
33+
|| (
34+
github.event.workflow_run.event == 'push'
35+
&& github.event.workflow_run.head_branch != 'master'
36+
&& github.event.workflow_run.head_branch != 'nightly-testing'
37+
&& !startsWith(github.event.workflow_run.head_branch, 'lean-pr-testing-')
38+
)
39+
)
40+
runs-on: ubuntu-latest
41+
steps:
42+
- name: Resolve Build run + SHA
43+
id: meta
44+
run: |
45+
set -euo pipefail
46+
RUN_ID="${{ github.event.workflow_run.id }}"
47+
NEW_SHA="${{ github.event.workflow_run.head_sha }}"
48+
{
49+
echo "run-id=$RUN_ID"
50+
echo "new-sha=$NEW_SHA"
51+
} | tee -a "$GITHUB_OUTPUT"
52+
53+
- name: Checkout new commit
54+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
55+
with:
56+
ref: ${{ steps.meta.outputs.new-sha }}
57+
fetch-depth: 0
58+
59+
- name: Resolve merge-base against master
60+
id: resolve
61+
env:
62+
NEW_SHA: ${{ steps.meta.outputs.new-sha }}
63+
run: |
64+
set -euo pipefail
65+
git fetch --quiet origin master
66+
MB="$(git merge-base "$NEW_SHA" origin/master)"
67+
echo "merge-base=$MB" | tee -a "$GITHUB_OUTPUT"
68+
69+
- name: Download new-side artifact
70+
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
71+
with:
72+
name: import-graph
73+
path: ./new-artifact
74+
run-id: ${{ steps.meta.outputs.run-id }}
75+
github-token: ${{ secrets.GITHUB_TOKEN }}
76+
77+
- name: Find master Build for the merge-base
78+
id: master-run
79+
env:
80+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
81+
REPO: ${{ github.repository }}
82+
MB: ${{ steps.resolve.outputs.merge-base }}
83+
run: |
84+
set -euo pipefail
85+
RUN="$(gh api "repos/$REPO/actions/runs?head_sha=$MB&event=push&status=success&branch=master" \
86+
--jq '[.workflow_runs[] | select(.name=="continuous integration")] | .[0].id // ""')"
87+
# A successful run is not enough: it must also carry the `import-graph` artifact.
88+
HAS_ARTIFACT=""
89+
if [ -n "$RUN" ]; then
90+
HAS_ARTIFACT="$(gh api "repos/$REPO/actions/runs/$RUN/artifacts" \
91+
--jq '[.artifacts[] | select(.name=="import-graph")] | length')"
92+
fi
93+
if [ -n "$RUN" ] && [ "${HAS_ARTIFACT:-0}" -gt 0 ]; then
94+
{
95+
echo "found=true"
96+
echo "run-id=$RUN"
97+
} | tee -a "$GITHUB_OUTPUT"
98+
else
99+
echo "found=false" | tee -a "$GITHUB_OUTPUT"
100+
echo "No usable master Build for merge-base $MB (no run, or run lacks the import-graph artifact)."
101+
fi
102+
103+
- name: Download master-side artifact
104+
if: steps.master-run.outputs.found == 'true'
105+
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
106+
with:
107+
name: import-graph
108+
path: ./ref-artifact
109+
run-id: ${{ steps.master-run.outputs.run-id }}
110+
github-token: ${{ secrets.GITHUB_TOKEN }}
111+
112+
- name: Checkout local actions
113+
if: steps.master-run.outputs.found == 'true'
114+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
115+
with:
116+
ref: ${{ github.workflow_sha }}
117+
fetch-depth: 1
118+
sparse-checkout: .github/actions
119+
path: workflow-actions
120+
121+
- name: Get mathlib-ci
122+
if: steps.master-run.outputs.found == 'true'
123+
uses: ./workflow-actions/.github/actions/get-mathlib-ci
124+
125+
- name: Compute Lean-aware declarations diff
126+
if: steps.master-run.outputs.found == 'true'
127+
uses: ./ci-tools/.github/actions/decls-diff
128+
with:
129+
reference-decls-file: ${{ github.workspace }}/ref-artifact/decls.txt
130+
reference-imports-file: ${{ github.workspace }}/ref-artifact/imports.json
131+
new-decls-file: ${{ github.workspace }}/new-artifact/decls.txt
132+
new-imports-file: ${{ github.workspace }}/new-artifact/imports.json
133+
new-sha: ${{ steps.meta.outputs.new-sha }}
134+
135+
- name: Note cache miss
136+
if: steps.master-run.outputs.found != 'true'
137+
run: |
138+
{
139+
echo "## Declarations diff"
140+
echo
141+
echo "⚠️ The Mathlib cache for this PR's merge-base \`${{ steps.resolve.outputs.merge-base }}\` isn't on the server (typically because the merge-base is a bors-batch intermediate that CI never built). Merge \`master\` into this PR and push to retrigger the build."
142+
} >> "$GITHUB_STEP_SUMMARY"

0 commit comments

Comments
 (0)