@@ -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 : |
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 : |
0 commit comments