Skip to content

Commit 87b84ac

Browse files
Merge branch 'master' into mitchell-horner/between
2 parents 907f2d1 + 3117eec commit 87b84ac

2,925 files changed

Lines changed: 60611 additions & 27904 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.

.devcontainer/devcontainer.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
{
22
"name": "Mathlib4 dev container",
33

4-
"build": {
5-
"dockerfile": "Dockerfile"
6-
},
4+
"image": "ghcr.io/leanprover-community/mathlib4/gitpod",
75

86
"onCreateCommand": "lake exe cache get!",
97

.github/build.in.yml

Lines changed: 344 additions & 153 deletions
Large diffs are not rendered by default.

.github/workflows/PR_summary.yml

Lines changed: 58 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
name: Post PR summary comment
22

33
on:
4-
pull_request:
4+
pull_request_target:
5+
6+
# Limit permissions for GITHUB_TOKEN for the entire workflow
7+
permissions:
8+
contents: read
9+
pull-requests: write # Only allow PR comments/labels
10+
# All other permissions are implicitly 'none'
511

612
jobs:
713
build:
@@ -12,11 +18,25 @@ jobs:
1218
- name: Checkout code
1319
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
1420
with:
21+
ref: ${{ github.event.pull_request.head.sha }}
1522
fetch-depth: 0
23+
path: pr-branch
24+
25+
# Checkout the master branch into a subdirectory
26+
- name: Checkout master branch
27+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
28+
with:
29+
# When testing the scripts, comment out the "ref: master"
30+
ref: master
31+
path: master-branch
1632

1733
- name: Update the merge-conflict label
1834
run: |
35+
cd pr-branch
1936
printf 'PR number: "%s"\n' "${{ github.event.pull_request.number }}"
37+
git config user.name "leanprover-community-mathlib4-bot"
38+
git config user.email "leanprover-community-mathlib4-bot@users.noreply.github.com"
39+
2040
if git merge origin/master --no-ff --no-commit
2141
then
2242
git merge --abort || true
@@ -27,7 +47,7 @@ jobs:
2747
--url https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels/merge-conflict \
2848
--header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}'
2949
else
30-
echo "This PR has merge conflicts with main."
50+
echo "This PR has merge conflicts with master."
3151
# we use curl rather than octokit/request-action so that the job won't fail
3252
# (and send an annoying email) if the labels don't exist
3353
curl --request POST \
@@ -36,7 +56,6 @@ jobs:
3656
--header 'X-GitHub-Api-Version: 2022-11-28' \
3757
--url https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels \
3858
--data '{"labels":["merge-conflict"]}'
39-
4059
fi
4160
4261
- name: Set up Python
@@ -52,10 +71,12 @@ jobs:
5271
5372
- name: Get changed and removed/renamed files
5473
run: |
74+
cd pr-branch
5575
git fetch origin ${{ github.base_ref }} # fetch the base branch
5676
5777
# Get the list of all changed files.
58-
git diff --name-only origin/${{ github.base_ref }}... > changed_files.txt
78+
echo "Saving the changed files to 'changed_files.txt'..."
79+
git diff --name-only origin/${{ github.base_ref }}... | tee changed_files.txt
5980
6081
# Get all files which were removed or renamed.
6182
echo "Checking for removed files..."
@@ -87,61 +108,70 @@ jobs:
87108
88109
- name: Compute (re)moved files without deprecation
89110
run: |
111+
cd pr-branch
90112
touch moved_without_deprecation.txt
91113
git checkout ${{ github.base_ref }}
92-
for file in $(cat removed_files.txt) ; do
114+
while IFS= read -r file
115+
do
93116
if grep ^deprecated_module "${file}" ; then
94117
printf 'info: removed file %s contains a deprecation\n' "${file}"
95118
else
119+
# shellcheck disable=SC2016
96120
printf '\n⚠️ **warning**: file `%s` was removed without a module deprecation\n' "${file}" |
97121
tee -a moved_without_deprecation.txt
98122
fi
99-
done
123+
done < removed_files.txt
100124
IFS=$'\n'
101-
for file in $(cat renamed_files.txt) ; do
125+
while IFS= read -r file
126+
do
127+
# shellcheck disable=SC2016
102128
printf '\n⚠️ **warning**: file %s without a module deprecation\n' "${file}" |
103129
tee -a moved_without_deprecation.txt
104-
done
130+
done < renamed_files.txt
105131
106132
# we return to the PR branch, since the next step wants it!
107133
git checkout -
108134
109135
- name: Compute transitive imports
110136
run: |
137+
cd pr-branch
111138
# the checkout dance, to avoid a detached head
112139
git checkout master
113140
git checkout -
114141
currentHash="$(git rev-parse HEAD)"
142+
printf 'currentHash=%s\n' "${currentHash}"
115143
116-
# Compute the counts for the HEAD of the PR
117-
python ./scripts/count-trans-deps.py "Mathlib/" > head.json
144+
echo "Compute the counts for the HEAD of the PR"
145+
python ../master-branch/scripts/count-trans-deps.py "Mathlib/" > head.json
118146
119147
# Checkout the merge base
120-
git checkout "$(git merge-base master ${{ github.sha }})"
148+
git checkout "$(git merge-base master ${{ github.event.pull_request.head.sha }})"
121149
122-
# Compute the counts for the merge base
123-
python ./scripts/count-trans-deps.py "Mathlib/" > base.json
150+
echo "Compute the counts for the merge base"
151+
python ../master-branch/scripts/count-trans-deps.py "Mathlib/" > base.json
124152
125153
# switch back to the current branch: the `declarations_diff` script should be here
126-
git checkout "${currentHash}"
154+
git checkout "${currentHash}" --
127155
128156
- name: Post or update the summary comment
129157
env:
130-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
158+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
131159
BRANCH_NAME: ${{ github.head_ref }}
132160
run: |
161+
cd pr-branch
162+
currentHash="$(git rev-parse HEAD)"
133163
PR="${{ github.event.pull_request.number }}"
134164
title="### PR summary"
135165
136-
graphAndHighPercentReports=$(python ./scripts/import-graph-report.py base.json head.json changed_files.txt)
166+
graphAndHighPercentReports=$(python ../master-branch/scripts/import-graph-report.py base.json head.json changed_files.txt)
137167
138-
## Import count comment
168+
echo "Produce import count comment"
139169
importCount=$(
140170
printf '%s\n' "${graphAndHighPercentReports}" | sed '/^Import changes exceeding/Q'
141-
./scripts/import_trans_difference.sh
171+
../master-branch/scripts/import_trans_difference.sh
142172
)
143173
144-
## High percentage imports
174+
echo "Produce high percentage imports"
145175
high_percentages=$(
146176
printf '%s\n' "${graphAndHighPercentReports}" | sed -n '/^Import changes exceeding/,$p'
147177
)
@@ -161,36 +191,37 @@ jobs:
161191
importCount="$(printf '#### Import changes for modified files\n\n%s\n' "${importCount}")"
162192
fi
163193
164-
## Declarations' diff comment
165-
declDiff=$(./scripts/declarations_diff.sh)
194+
echo "Compute Declarations' diff comment"
195+
declDiff=$(../master-branch/scripts/declarations_diff.sh)
166196
if [ "$(printf '%s' "${declDiff}" | wc -l)" -gt 15 ]
167197
then
168198
declDiff="$(printf '<details><summary>\n\n%s\n\n</summary>\n\n%s\n\n</details>\n' "#### Declarations diff" "${declDiff}")"
169199
else
170200
declDiff="$(printf '#### Declarations diff\n\n%s\n' "${declDiff}")"
171201
fi
172-
git checkout "${BRANCH_NAME}"
173-
currentHash="$(git rev-parse HEAD)"
202+
git checkout "${currentHash}" --
174203
hashURL="https://github.com/${{ github.repository }}/pull/${{ github.event.pull_request.number }}/commits/${currentHash}"
204+
printf 'hashURL: %s' "${hashURL}"
175205
176-
## Technical debt changes
177-
techDebtVar="$(./scripts/technical-debt-metrics.sh pr_summary)"
206+
echo "Compute technical debt changes"
207+
techDebtVar="$(../master-branch/scripts/technical-debt-metrics.sh pr_summary)"
178208
179209
# store in a file, to avoid "long arguments" error.
180210
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
181211
182-
# At the end, include any errors about removed or renamed files without deprecation.
212+
echo "Include any errors about removed or renamed files without deprecation."
183213
if [ -s moved_without_deprecation.txt ]
184214
then
185215
printf '\n\n---\n\n' >> please_merge_master.md
186216
cat moved_without_deprecation.txt >> please_merge_master.md
187217
fi
188218
189219
cat please_merge_master.md
190-
./scripts/update_PR_comment.sh please_merge_master.md "${title}" "${PR}"
220+
../master-branch/scripts/update_PR_comment.sh please_merge_master.md "${title}" "${PR}"
191221
192222
- name: Update the file-removed label
193223
run: |
224+
cd pr-branch
194225
undeprecatedMoves="$(cat moved_without_deprecation.txt)"
195226
if [ -n "$undeprecatedMoves" ]; then
196227
echo "This PR has undeprecated module (re)movals."
Lines changed: 48 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,64 @@
11
name: Autolabel PRs
22

33
on:
4-
pull_request:
4+
pull_request_target:
55
types: [opened]
66
push:
77
paths:
88
- scripts/autolabel.lean
99
- .github/workflows/add_label_from_diff.yaml
1010

11+
# Limit permissions for GITHUB_TOKEN for the entire workflow
12+
permissions:
13+
contents: read
14+
pull-requests: write # Only allow PR comments/labels
15+
# All other permissions are implicitly 'none'
16+
1117
jobs:
1218
add_topic_label:
1319
name: Add topic label
1420
runs-on: ubuntu-latest
1521
# Don't run on forks, where we wouldn't have permissions to add the label anyway.
1622
if: github.repository == 'leanprover-community/mathlib4'
17-
permissions:
18-
issues: write
19-
checks: write
20-
pull-requests: write
21-
contents: read
2223
steps:
23-
- name: Checkout code
24-
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
25-
with:
26-
fetch-depth: 0
27-
- name: Configure Lean
28-
uses: leanprover/lean-action@f807b338d95de7813c5c50d018f1c23c9b93b4ec # 2025-04-24
29-
with:
30-
auto-config: false
31-
use-github-cache: false
32-
use-mathlib-cache: false
33-
- name: lake exe autolabel
34-
run: |
35-
# the checkout dance, to avoid a detached head
36-
git checkout master
37-
git checkout -
38-
lake exe autolabel "$NUMBER"
39-
env:
40-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
41-
GH_REPO: ${{ github.repository }}
42-
NUMBER: ${{ github.event.number }}
24+
- name: Checkout code
25+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
26+
with:
27+
ref: ${{ github.event.pull_request.head.sha }}
28+
fetch-depth: 0
29+
- name: Configure Lean
30+
uses: leanprover/lean-action@f807b338d95de7813c5c50d018f1c23c9b93b4ec # 2025-04-24
31+
with:
32+
auto-config: false
33+
use-github-cache: false
34+
use-mathlib-cache: false
35+
- name: lake exe autolabel
36+
run: |
37+
# the checkout dance, to avoid a detached head
38+
git checkout master
39+
git checkout -
40+
labels="$(lake exe autolabel)"
41+
printf '%s\n' "${labels}"
42+
# extract
43+
label="$(printf '%s' "${labels}" | sed -n 's=.*#\[\([^,]*\)\].*=\1=p')"
44+
printf 'label: "%s"\n' "${label}"
45+
if [ -n "${label}" ]
46+
then
47+
printf 'Applying label %s\n' "${label}"
48+
# we use curl rather than octokit/request-action so that the job won't fail
49+
# (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"
51+
printf 'url: %s\n' "${url}"
52+
jsonLabel="$(printf '{"labels":["%s"]}' "${label}")"
53+
printf 'jsonLabel: %s\n' "${jsonLabel}"
54+
curl --request POST \
55+
--header 'Accept: application/vnd.github+json' \
56+
--header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
57+
--header 'X-GitHub-Api-Version: 2022-11-28' \
58+
--url "${url}" \
59+
--data "${jsonLabel}"
60+
else
61+
echo "There is no single label that we could apply, so we are not applying any label."
62+
fi
63+
env:
64+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)