11name : Post PR summary comment
22
33on :
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
612jobs :
713 build :
814 name : " post-or-update-summary-comment"
915 runs-on : ubuntu-latest
16+ if : github.repository == 'leanprover-community/mathlib4'
1017
1118 steps :
1219 - name : Checkout code
1320 uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
1421 with :
22+ ref : ${{ github.event.pull_request.head.sha }}
1523 fetch-depth : 0
24+ path : pr-branch
25+
26+ # Checkout the master branch into a subdirectory
27+ - name : Checkout master branch
28+ uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
29+ with :
30+ # When testing the scripts, comment out the "ref: master"
31+ ref : master
32+ path : master-branch
1633
1734 - name : Update the merge-conflict label
1835 run : |
36+ cd pr-branch
1937 printf 'PR number: "%s"\n' "${{ github.event.pull_request.number }}"
38+ git config user.name "leanprover-community-mathlib4-bot"
39+ git config user.email "leanprover-community-mathlib4-bot@users.noreply.github.com"
40+
2041 if git merge origin/master --no-ff --no-commit
2142 then
2243 git merge --abort || true
2748 --url https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels/merge-conflict \
2849 --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}'
2950 else
30- echo "This PR has merge conflicts with main ."
51+ echo "This PR has merge conflicts with master ."
3152 # we use curl rather than octokit/request-action so that the job won't fail
3253 # (and send an annoying email) if the labels don't exist
3354 curl --request POST \
3657 --header 'X-GitHub-Api-Version: 2022-11-28' \
3758 --url https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels \
3859 --data '{"labels":["merge-conflict"]}'
39-
4060 fi
4161
4262 - name : Set up Python
@@ -52,10 +72,12 @@ jobs:
5272
5373 - name : Get changed and removed/renamed files
5474 run : |
75+ cd pr-branch
5576 git fetch origin ${{ github.base_ref }} # fetch the base branch
5677
5778 # Get the list of all changed files.
58- git diff --name-only origin/${{ github.base_ref }}... > changed_files.txt
79+ echo "Saving the changed files to 'changed_files.txt'..."
80+ git diff --name-only origin/${{ github.base_ref }}... | tee changed_files.txt
5981
6082 # Get all files which were removed or renamed.
6183 echo "Checking for removed files..."
@@ -87,61 +109,79 @@ jobs:
87109
88110 - name : Compute (re)moved files without deprecation
89111 run : |
112+ cd pr-branch
90113 touch moved_without_deprecation.txt
114+ touch extraneous_deprecated_module.txt
91115 git checkout ${{ github.base_ref }}
92- for file in $(cat removed_files.txt) ; do
116+ while IFS= read -r file
117+ do
93118 if grep ^deprecated_module "${file}" ; then
94- printf 'info: removed file %s contains a deprecation\n' "${file}"
119+ # shellcheck disable=SC2016
120+ printf '\n⚠️ **warning**: removed file `%s` contains a module deprecation: please add this in a follow-up PR instead\n' "${file}" |
121+ tee -a extraneous_deprecated_module.txt
95122 else
96- printf '\n⚠️ **warning**: file `%s` was removed without a module deprecation\n' "${file}" |
123+ # shellcheck disable=SC2016
124+ printf '\nnote: file `%s` was removed.\nPlease create a follow-up pull request adding a module deprecation. Thanks!\n' "${file}" |
97125 tee -a moved_without_deprecation.txt
98126 fi
99- done
127+ done < removed_files.txt
100128 IFS=$'\n'
101- for file in $(cat renamed_files.txt) ; do
102- printf '\n⚠️ **warning**: file %s without a module deprecation\n' "${file}" |
103- tee -a moved_without_deprecation.txt
104- done
129+ while IFS= read -r file
130+ do
131+ if grep ^deprecated_module "${file}" ; then
132+ # shellcheck disable=SC2016
133+ printf '\n⚠️ **warning**: renamed file `%s` contains a module deprecation: please add this in a follow-up PR instead\n' "${file}" |
134+ tee -a extraneous_deprecated_module.txt
135+ else
136+ # shellcheck disable=SC2016
137+ printf '\nnote: file `%s` without a module deprecation\nPlease create a follow-up pull request adding one. Thanks!\n' "${file}" |
138+ tee -a moved_without_deprecation.txt
139+ fi
140+ done < renamed_files.txt
105141
106142 # we return to the PR branch, since the next step wants it!
107143 git checkout -
108144
109145 - name : Compute transitive imports
110146 run : |
147+ cd pr-branch
111148 # the checkout dance, to avoid a detached head
112149 git checkout master
113150 git checkout -
114151 currentHash="$(git rev-parse HEAD)"
152+ printf 'currentHash=%s\n' "${currentHash}"
115153
116- # Compute the counts for the HEAD of the PR
117- python ./scripts/count-trans-deps.py "Mathlib/" > head.json
154+ echo " Compute the counts for the HEAD of the PR"
155+ python ../master-branch /scripts/count-trans-deps.py "Mathlib/" > head.json
118156
119157 # Checkout the merge base
120- git checkout "$(git merge-base master ${{ github.sha }})"
158+ git checkout "$(git merge-base master ${{ github.event.pull_request.head. sha }})"
121159
122- # Compute the counts for the merge base
123- python ./scripts/count-trans-deps.py "Mathlib/" > base.json
160+ echo " Compute the counts for the merge base"
161+ python ../master-branch /scripts/count-trans-deps.py "Mathlib/" > base.json
124162
125163 # switch back to the current branch: the `declarations_diff` script should be here
126- git checkout "${currentHash}"
164+ git checkout "${currentHash}" --
127165
128166 - name : Post or update the summary comment
129167 env :
130- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
168+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
131169 BRANCH_NAME : ${{ github.head_ref }}
132170 run : |
171+ cd pr-branch
172+ currentHash="$(git rev-parse HEAD)"
133173 PR="${{ github.event.pull_request.number }}"
134174 title="### PR summary"
135175
136- graphAndHighPercentReports=$(python ./scripts/import-graph-report.py base.json head.json changed_files.txt)
176+ graphAndHighPercentReports=$(python ../master-branch /scripts/import-graph-report.py base.json head.json changed_files.txt)
137177
138- ## Import count comment
178+ echo "Produce import count comment"
139179 importCount=$(
140180 printf '%s\n' "${graphAndHighPercentReports}" | sed '/^Import changes exceeding/Q'
141- ./scripts/import_trans_difference.sh
181+ ../master-branch /scripts/import_trans_difference.sh
142182 )
143183
144- ## High percentage imports
184+ echo "Produce high percentage imports"
145185 high_percentages=$(
146186 printf '%s\n' "${graphAndHighPercentReports}" | sed -n '/^Import changes exceeding/,$p'
147187 )
@@ -161,36 +201,43 @@ jobs:
161201 importCount="$(printf '#### Import changes for modified files\n\n%s\n' "${importCount}")"
162202 fi
163203
164- ## Declarations' diff comment
165- declDiff=$(./scripts/declarations_diff.sh)
204+ echo "Compute Declarations' diff comment"
205+ declDiff=$(../master-branch /scripts/declarations_diff.sh)
166206 if [ "$(printf '%s' "${declDiff}" | wc -l)" -gt 15 ]
167207 then
168208 declDiff="$(printf '<details><summary>\n\n%s\n\n</summary>\n\n%s\n\n</details>\n' "#### Declarations diff" "${declDiff}")"
169209 else
170210 declDiff="$(printf '#### Declarations diff\n\n%s\n' "${declDiff}")"
171211 fi
172- git checkout "${BRANCH_NAME}"
173- currentHash="$(git rev-parse HEAD)"
212+ git checkout "${currentHash}" --
174213 hashURL="https://github.com/${{ github.repository }}/pull/${{ github.event.pull_request.number }}/commits/${currentHash}"
214+ printf 'hashURL: %s' "${hashURL}"
175215
176- ## Technical debt changes
177- techDebtVar="$(./scripts/technical-debt-metrics.sh pr_summary)"
216+ echo "Compute technical debt changes"
217+ techDebtVar="$(../master-branch /scripts/technical-debt-metrics.sh pr_summary)"
178218
179219 # store in a file, to avoid "long arguments" error.
180220 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
181221
182- # At the end, include any errors about removed or renamed files without deprecation.
222+ echo "Include any errors about removed or renamed files without deprecation,"
223+ echo "as well as errors about extraneous deprecated_module additions."
183224 if [ -s moved_without_deprecation.txt ]
184225 then
185226 printf '\n\n---\n\n' >> please_merge_master.md
186227 cat moved_without_deprecation.txt >> please_merge_master.md
187228 fi
229+ if [ -s extraneous_deprecated_module.txt ]
230+ then
231+ printf '\n\n---\n\n' >> please_merge_master.md
232+ cat extraneous_deprecated_module.txt >> please_merge_master.md
233+ fi
188234
189235 cat please_merge_master.md
190- ./scripts/update_PR_comment.sh please_merge_master.md "${title}" "${PR}"
236+ ../master-branch /scripts/update_PR_comment.sh please_merge_master.md "${title}" "${PR}"
191237
192238 - name : Update the file-removed label
193239 run : |
240+ cd pr-branch
194241 undeprecatedMoves="$(cat moved_without_deprecation.txt)"
195242 if [ -n "$undeprecatedMoves" ]; then
196243 echo "This PR has undeprecated module (re)movals."
0 commit comments