Skip to content

Commit 324d792

Browse files
authored
Merge branch 'leanprover-community:master' into freeprob
2 parents 11704fe + c61602c commit 324d792

7,362 files changed

Lines changed: 290873 additions & 131881 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.
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# get-mathlib-ci
2+
3+
This action is the source of truth for how workflows in this repository check out
4+
`leanprover-community/mathlib-ci`.
5+
6+
## Policy
7+
8+
Any workflow that needs `mathlib-ci` should use this action instead of writing its
9+
own `actions/checkout` block for `leanprover-community/mathlib-ci`.
10+
11+
The default `ref` in [`action.yml`](./action.yml) is the single canonical pinned
12+
`mathlib-ci` commit for this repository. This is auto-updated regularly by the
13+
[`update_dependencies.yml` workflow](../../workflows/update_dependencies.yml).
14+
15+
## Why
16+
17+
- Keep the pinned `mathlib-ci` ref in one place.
18+
- Avoid drift and copy/paste mistakes across many workflows.
19+
- Make ref bumps a one-file update.
20+
21+
## Usage
22+
23+
In workflows, check out this repository's actions from the running workflow commit,
24+
then use the local action:
25+
26+
```yaml
27+
- name: Checkout local actions
28+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
29+
with:
30+
ref: ${{ github.workflow_sha }}
31+
fetch-depth: 1
32+
sparse-checkout: .github/actions
33+
path: workflow-actions
34+
35+
- name: Get mathlib-ci
36+
uses: ./workflow-actions/.github/actions/get-mathlib-ci
37+
```
38+
39+
Override the ref only when needed:
40+
41+
```yaml
42+
- name: Get mathlib-ci
43+
uses: ./workflow-actions/.github/actions/get-mathlib-ci
44+
with:
45+
ref: master
46+
```
47+
48+
## Outputs
49+
50+
This action also exposes values that later workflow steps can reuse:
51+
52+
- `ref`: the effective `mathlib-ci` ref that was checked out. If the workflow did
53+
not pass `with.ref`, this is the action's default pinned commit.
54+
- `path`: the checkout path used for `mathlib-ci`.
55+
- `scripts_dir`: the absolute path to the checked out `scripts` directory.
56+
57+
The action also exports these environment variables for subsequent steps:
58+
59+
- `CI_CHECKOUT_PATH`: the absolute path to the checked out `mathlib-ci` repository.
60+
- `CI_SCRIPTS_DIR`: the absolute path to the checked out `mathlib-ci/scripts` directory.
61+
62+
If a workflow needs to refer to the exact resolved `mathlib-ci` ref later, use the
63+
action output instead of duplicating the pinned SHA in the workflow:
64+
65+
```yaml
66+
- name: Get mathlib-ci
67+
id: get_mathlib_ci
68+
uses: ./workflow-actions/.github/actions/get-mathlib-ci
69+
70+
- name: Use resolved ref
71+
run: |
72+
echo "Resolved ref: ${{ steps.get_mathlib_ci.outputs.ref }}"
73+
echo "Scripts dir: ${{ steps.get_mathlib_ci.outputs.scripts_dir }}"
74+
echo "Raw URL: https://raw.githubusercontent.com/leanprover-community/mathlib-ci/${{ steps.get_mathlib_ci.outputs.ref }}/scripts/nightly/create-adaptation-pr.sh"
75+
```
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Source of truth for `mathlib-ci` checkout settings in this repository.
2+
# Workflows should use this action instead of duplicating the checkout block
3+
# and hardcoded ref in multiple places.
4+
name: Get mathlib-ci
5+
description: Checkout leanprover-community/mathlib-ci at a shared ref.
6+
inputs:
7+
ref:
8+
description: Git ref (branch, tag, or SHA) for mathlib-ci.
9+
required: false
10+
# Default pinned commit used by workflows unless they explicitly override.
11+
# Update this ref as needed to pick up changes to mathlib-ci scripts
12+
# This is also updated automatically by .github/workflows/update_dependencies.yml
13+
default: e7a159e9a129f92fd07e6852a742485798678473
14+
path:
15+
description: Checkout destination path.
16+
required: false
17+
default: ci-tools
18+
fetch-depth:
19+
description: Number of commits to fetch.
20+
required: false
21+
default: '1'
22+
outputs:
23+
ref:
24+
description: Effective ref used for the checkout.
25+
value: ${{ inputs.ref }}
26+
path:
27+
description: Checkout path used.
28+
value: ${{ inputs.path }}
29+
scripts_dir:
30+
description: Absolute path to the scripts directory.
31+
value: ${{ steps.paths.outputs.scripts_dir }}
32+
runs:
33+
using: composite
34+
steps:
35+
- name: Get mathlib-ci
36+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
37+
with:
38+
repository: leanprover-community/mathlib-ci
39+
ref: ${{ inputs.ref }}
40+
fetch-depth: ${{ inputs.fetch-depth }}
41+
path: ${{ inputs.path }}
42+
43+
- name: Setup CI Scripts Paths
44+
id: paths
45+
shell: bash
46+
run: |
47+
checkout_path="${GITHUB_WORKSPACE}/${{ inputs.path }}"
48+
scripts_dir="${checkout_path}/scripts"
49+
echo "checkout_path=${checkout_path}" >> "$GITHUB_OUTPUT"
50+
echo "scripts_dir=${scripts_dir}" >> "$GITHUB_OUTPUT"
51+
echo "CI_CHECKOUT_PATH=${checkout_path}" >> "$GITHUB_ENV"
52+
echo "CI_SCRIPTS_DIR=${scripts_dir}" >> "$GITHUB_ENV"

.github/workflows/PR_summary.yml

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

26-
# Checkout the master branch into a subdirectory
27-
- name: Checkout master branch
28+
- name: Checkout local actions
2829
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
2930
with:
30-
# When testing the scripts, comment out the "ref: master"
31-
ref: master
32-
path: master-branch
31+
ref: ${{ github.workflow_sha }}
32+
fetch-depth: 1
33+
sparse-checkout: .github/actions
34+
path: workflow-actions
35+
- name: Get mathlib-ci
36+
uses: ./workflow-actions/.github/actions/get-mathlib-ci
3337

3438
- name: Update the merge-conflict label
3539
run: |
@@ -79,6 +83,10 @@ jobs:
7983
echo "Saving the changed files to 'changed_files.txt'..."
8084
git diff --name-only origin/${{ github.base_ref }}... | tee changed_files.txt
8185
86+
# Get all newly added files.
87+
echo "Checking for added files..."
88+
git diff --name-only --diff-filter A origin/${{ github.base_ref }}... | tee added_files.txt
89+
8290
# Get all files which were removed or renamed.
8391
echo "Checking for removed files..."
8492
@@ -152,13 +160,13 @@ jobs:
152160
printf 'currentHash=%s\n' "${currentHash}"
153161
154162
echo "Compute the counts for the HEAD of the PR"
155-
python ../master-branch/scripts/count-trans-deps.py "Mathlib/" > head.json
163+
python "${CI_SCRIPTS_DIR}/pr_summary/count-trans-deps.py" "Mathlib/" > head.json
156164
157165
# Checkout the merge base
158166
git checkout "$(git merge-base master ${{ github.event.pull_request.head.sha }})"
159167
160168
echo "Compute the counts for the merge base"
161-
python ../master-branch/scripts/count-trans-deps.py "Mathlib/" > base.json
169+
python "${CI_SCRIPTS_DIR}/pr_summary/count-trans-deps.py" "Mathlib/" > base.json
162170
163171
# switch back to the current branch: the `declarations_diff` script should be here
164172
git checkout "${currentHash}" --
@@ -173,12 +181,12 @@ jobs:
173181
PR="${{ github.event.pull_request.number }}"
174182
title="### PR summary"
175183
176-
graphAndHighPercentReports=$(python ../master-branch/scripts/import-graph-report.py base.json head.json changed_files.txt)
184+
graphAndHighPercentReports=$(python "${CI_SCRIPTS_DIR}/pr_summary/import-graph-report.py" base.json head.json changed_files.txt)
177185
178186
echo "Produce import count comment"
179187
importCount=$(
180188
printf '%s\n' "${graphAndHighPercentReports}" | sed '/^Import changes exceeding/Q'
181-
../master-branch/scripts/import_trans_difference.sh
189+
"${CI_SCRIPTS_DIR}/pr_summary/import_trans_difference.sh"
182190
)
183191
184192
echo "Produce high percentage imports"
@@ -202,7 +210,7 @@ jobs:
202210
fi
203211
204212
echo "Compute Declarations' diff comment"
205-
declDiff=$(../master-branch/scripts/declarations_diff.sh)
213+
declDiff=$("${CI_SCRIPTS_DIR}/pr_summary/declarations_diff.sh")
206214
if [ "$(printf '%s' "${declDiff}" | wc -l)" -gt 15 ]
207215
then
208216
declDiff="$(printf '<details><summary>\n\n%s\n\n</summary>\n\n%s\n\n</details>\n' "#### Declarations diff" "${declDiff}")"
@@ -214,10 +222,40 @@ jobs:
214222
printf 'hashURL: %s' "${hashURL}"
215223
216224
echo "Compute technical debt changes"
217-
techDebtVar="$(../master-branch/scripts/technical-debt-metrics.sh pr_summary)"
225+
techDebtVar="$("${CI_SCRIPTS_DIR}/reporting/technical-debt-metrics.sh" pr_summary)"
226+
227+
echo "Compute documentation reminder"
228+
workflowFilesChanged="$(grep '^\.github/workflows/' changed_files.txt || true)"
229+
if [ -n "${workflowFilesChanged}" ]
230+
then
231+
# Format each changed workflow path as a Markdown bullet: "- `path`"
232+
workflowFilesChangedMarkdown="$(sed "s|^|- \`|; s|\$|\`|" <<< "${workflowFilesChanged}")"
233+
workflowDocsReminder="$(printf "### ⚠️ Workflow documentation reminder\nThis PR modifies files under \`.github/workflows/\`.\nPlease update \`docs/workflows.md\` if the workflow inventory, triggers, or behavior changed.\n\nModified workflow files:\n%s\n" "${workflowFilesChangedMarkdown}")"
234+
else
235+
workflowDocsReminder=""
236+
fi
237+
238+
echo "Compute scripts-location reminder"
239+
scriptsFilesAdded="$(grep '^scripts/' added_files.txt || true)"
240+
if [ -n "${scriptsFilesAdded}" ]
241+
then
242+
# Format each added scripts path as a Markdown bullet: "- `path`"
243+
scriptsFilesAddedMarkdown="$(sed "s|^|- \`|; s|\$|\`|" <<< "${scriptsFilesAdded}")"
244+
scriptsLocationReminder="$(printf "### ⚠️ Scripts folder reminder\nThis PR adds files under \`scripts/\`.\nPlease consider whether each added script belongs in this repository or in [\`leanprover-community/mathlib-ci\`](https://github.com/leanprover-community/mathlib-ci).\n\nA script belongs in **\`mathlib-ci\`** if it is a CI automation script that interacts with GitHub (e.g. managing labels, posting comments, triggering bots), runs from a trusted external checkout in CI, or requires access to secrets.\n\nA script belongs in **this repository** (\`scripts/\`) if it is a developer or maintainer tool to be run locally, a code maintenance or analysis utility, a style linting tool, or a data file used by the library's own linters.\n\nSee the [\`mathlib-ci\` README](https://github.com/leanprover-community/mathlib-ci) for more details.\n\nAdded scripts files:\n%s\n" "${scriptsFilesAddedMarkdown}")"
245+
else
246+
scriptsLocationReminder=""
247+
fi
218248
219249
# store in a file, to avoid "long arguments" error.
220250
printf '%s [%s](%s)%s\n\n%s\n\n---\n\n%s\n\n---\n\n%s\n' "${title}" "$(git rev-parse --short HEAD)" "${hashURL}" "${high_percentages}" "${importCount}" "${declDiff}" "${techDebtVar}" > please_merge_master.md
251+
if [ -n "${workflowDocsReminder}" ]
252+
then
253+
printf '\n\n---\n\n%s\n' "${workflowDocsReminder}" >> please_merge_master.md
254+
fi
255+
if [ -n "${scriptsLocationReminder}" ]
256+
then
257+
printf '\n\n---\n\n%s\n' "${scriptsLocationReminder}" >> please_merge_master.md
258+
fi
221259
222260
echo "Include any errors about removed or renamed files without deprecation,"
223261
echo "as well as errors about extraneous deprecated_module additions."
@@ -233,7 +271,7 @@ jobs:
233271
fi
234272
235273
cat please_merge_master.md
236-
../master-branch/scripts/update_PR_comment.sh please_merge_master.md "${title}" "${PR}"
274+
"${CI_SCRIPTS_DIR}/pr_summary/update_PR_comment.sh" please_merge_master.md "${title}" "${PR}"
237275
238276
- name: Update the file-removed label
239277
run: |

.github/workflows/actionlint.yml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ on:
33
pull_request:
44
paths:
55
- '.github/**'
6-
merge_group:
76

87
jobs:
98
actionlint:
@@ -13,7 +12,19 @@ jobs:
1312
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
1413

1514
- name: suggester / actionlint
16-
uses: reviewdog/action-actionlint@e58ee9d111489c31395fbe4857b0be6e7635dbda # v1.70.0
15+
uses: reviewdog/action-actionlint@6fb7acc99f4a1008869fa8a0f09cfca740837d9d # v1.72.0
1716
with:
1817
tool_name: actionlint
19-
fail_level: error
18+
fail_level: any
19+
20+
ensure-sha-pinned-actions:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
25+
26+
# Using our fork's PR branch until upstream merges the improved error reporting:
27+
# https://github.com/zgosalvez/github-actions-ensure-sha-pinned-actions/pull/288
28+
# TODO: Update to upstream release once merged.
29+
- name: Ensure all actions are pinned to SHA
30+
uses: kim-em/github-actions-ensure-sha-pinned-actions@00f51cdb5bbc21f5bc873ef3a2dceef45df213af # improve-error-reporting

.github/workflows/add_label_from_diff.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
ref: master
2828
path: tools
2929
- name: Configure Lean
30-
uses: leanprover/lean-action@c544e89643240c6b398f14a431bcdc6309e36b3e # v1.4.0
30+
uses: leanprover/lean-action@38fbc41a8c28c4cbaec22d7f7de508ec2e7c0dd9 # v1.5.0
3131
with:
3232
auto-config: false
3333
use-github-cache: false
@@ -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/bors.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ concurrency:
1515
# Limit permissions for GITHUB_TOKEN for the entire workflow
1616
permissions:
1717
contents: read
18+
id-token: write
1819
pull-requests: write # Only allow PR comments/labels
1920
# All other permissions are implicitly 'none'
2021

@@ -26,9 +27,12 @@ jobs:
2627
with:
2728
concurrency_group: ${{ github.workflow }}-${{ github.ref }}-${{ github.run_id }}
2829
pr_branch_ref: ${{ github.sha }}
30+
# Use the MASTER cache key only when merging into mathlib4 (staging branch);
31+
# 'bors try' runs (trying branch) and nightly-testing use NON_MASTER
32+
cache_application_id: ${{ github.ref_name == 'staging' && github.repository == 'leanprover-community/mathlib4' && vars.CACHE_MASTER_WRITER_AZURE_APP_ID || vars.CACHE_NON_MASTER_WRITER_AZURE_APP_ID }}
2933
# bors runs should build the tools from their commit-under-test: after all, we are trying to
3034
# test 'what would happen if this was merged', so we need to use the 'would-be-post-merge' tools
3135
tools_branch_ref: ${{ github.sha }}
32-
# We don't wan't 'bors try' runs to compete with merge-candidates, so we pool trying with PR runs
36+
# We don't want 'bors try' runs to compete with merge-candidates, so we pool trying with PR runs
3337
runs_on: ${{ github.ref_name == 'trying' && 'pr' || 'bors' }}
3438
secrets: inherit

.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.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ on:
1212
- 'trying'
1313
# ignore branches meant for experiments
1414
- 'ci-dev/**'
15-
merge_group:
1615

1716
concurrency:
1817
# label each workflow run; only the latest with each label will run
@@ -24,6 +23,7 @@ concurrency:
2423
# Limit permissions for GITHUB_TOKEN for the entire workflow
2524
permissions:
2625
contents: read
26+
id-token: write
2727
pull-requests: write # Only allow PR comments/labels
2828
# All other permissions are implicitly 'none'
2929

@@ -35,5 +35,7 @@ jobs:
3535
with:
3636
concurrency_group: ${{ github.workflow }}-${{ github.ref }}-${{ (github.event_name == 'push' && github.ref == 'refs/heads/master' && github.run_id) || '' }}
3737
pr_branch_ref: ${{ github.sha }}
38+
# Use the MASTER cache key only on mathlib4/master; nightly-testing and other branches use NON_MASTER
39+
cache_application_id: ${{ github.repository == 'leanprover-community/mathlib4' && github.ref == 'refs/heads/master' && vars.CACHE_MASTER_WRITER_AZURE_APP_ID || vars.CACHE_NON_MASTER_WRITER_AZURE_APP_ID }}
3840
runs_on: pr
3941
secrets: inherit

.github/workflows/build_fork.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ concurrency:
2424
# Limit permissions for GITHUB_TOKEN for the entire workflow
2525
permissions:
2626
contents: read
27+
id-token: write
2728
pull-requests: write # Only allow PR comments/labels
2829
# All other permissions are implicitly 'none'
2930

@@ -35,5 +36,6 @@ jobs:
3536
with:
3637
concurrency_group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
3738
pr_branch_ref: ${{ github.event.pull_request.head.sha }}
39+
cache_application_id: ${{ vars.CACHE_NON_MASTER_WRITER_AZURE_APP_ID }}
3840
runs_on: pr
3941
secrets: inherit

0 commit comments

Comments
 (0)