@@ -31,12 +31,16 @@ jobs:
3131 # we use curl rather than octokit/request-action so that the job won't fail
3232 # (and send an annoying email) if the labels don't exist
3333 curl --request POST \
34- --url https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels/merge-conflict \
35- --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}'
34+ --header 'Accept: application/vnd.github+json' \
35+ --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
36+ --header 'X-GitHub-Api-Version: 2022-11-28' \
37+ --url https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels \
38+ --data '{"labels":["merge-conflict"]}'
39+
3640 fi
3741
3842 - name : Set up Python
39- uses : actions/setup-python@8d9ed9ac5c53483de85588cdf95a591a75ab9f55 # v5.5 .0
43+ uses : actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6 .0
4044 with :
4145 python-version : 3.12
4246
@@ -46,10 +50,61 @@ jobs:
4650 sudo apt-get install -y jq
4751 # If you have additional dependencies, install them here
4852
49- - name : Get changed files
53+ - name : Get changed and removed/renamed files
5054 run : |
5155 git fetch origin ${{ github.base_ref }} # fetch the base branch
52- git diff --name-only origin/${{ github.base_ref }}... > changed_files.txt # get the list of changed files
56+
57+ # Get the list of all changed files.
58+ git diff --name-only origin/${{ github.base_ref }}... > changed_files.txt
59+
60+ # Get all files which were removed or renamed.
61+ echo "Checking for removed files..."
62+
63+ # Shows the `D`eleted files, one per line.
64+ git diff --name-only --diff-filter D origin/${{ github.base_ref }}... | tee removed_files.txt
65+ echo "Checking for renamed files..."
66+
67+ # Shows the `R`enamed files, in human readable format
68+ # The `awk` pipe
69+ # * extracts into an array the old name as the key and the new name as the value
70+ # * eventually prints "`oldName` was renamed to `newName`" for each key-value pair.
71+ git diff -p --summary --diff-filter=R origin/${{ github.base_ref }}... |
72+ awk '
73+ /^rename from / {
74+ file=$0
75+ gsub(/rename from /, "", file)
76+ oldFile=file
77+ }
78+ /^rename to / {
79+ file=$0
80+ gsub(/rename to /, "", file)
81+ oldNew[oldFile]=file
82+ } END {
83+ for(old in oldNew) {
84+ printf("`%s` was renamed to `%s`\n", old, oldNew[old])
85+ }
86+ }' | tee renamed_files.txt
87+
88+ - name : Compute (re)moved files without deprecation
89+ run : |
90+ touch moved_without_deprecation.txt
91+ git checkout ${{ github.base_ref }}
92+ for file in $(cat removed_files.txt) ; do
93+ if grep ^deprecated_module "${file}" ; then
94+ printf 'info: removed file %s contains a deprecation\n' "${file}"
95+ else
96+ printf '\n⚠️ **warning**: file `%s` was removed without a module deprecation\n' "${file}" |
97+ tee -a moved_without_deprecation.txt
98+ fi
99+ done
100+ 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
105+
106+ # we return to the PR branch, since the next step wants it!
107+ git checkout -
53108
54109 - name : Compute transitive imports
55110 run : |
69124
70125 # switch back to the current branch: the `declarations_diff` script should be here
71126 git checkout "${currentHash}"
127+
72128 - name : Post or update the summary comment
73129 env :
74130 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
@@ -123,5 +179,34 @@ jobs:
123179 # store in a file, to avoid "long arguments" error.
124180 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
125181
182+ # At the end, include any errors about removed or renamed files without deprecation.
183+ if [ -s moved_without_deprecation.txt ]
184+ then
185+ printf '\n\n---\n\n' >> please_merge_master.md
186+ cat moved_without_deprecation.txt >> please_merge_master.md
187+ fi
188+
126189 cat please_merge_master.md
127190 ./scripts/update_PR_comment.sh please_merge_master.md "${title}" "${PR}"
191+
192+ - name : Update the file-removed label
193+ run : |
194+ undeprecatedMoves="$(cat moved_without_deprecation.txt)"
195+ if [ -n "$undeprecatedMoves" ]; then
196+ echo "This PR has undeprecated module (re)movals."
197+ # we use curl rather than octokit/request-action so that the job won't fail
198+ # (and send an annoying email) if the labels don't exist
199+ curl --request POST \
200+ --header 'Accept: application/vnd.github+json' \
201+ --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
202+ --header 'X-GitHub-Api-Version: 2022-11-28' \
203+ --url https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels \
204+ --data '{"labels":["file-removed"]}'
205+ else
206+ echo "This PR (re)moves no modules without deprecations."
207+ # we use curl rather than octokit/request-action so that the job won't fail
208+ # (and send an annoying email) if the labels don't exist
209+ curl --request DELETE \
210+ --url https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels/file-removed \
211+ --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}'
212+ fi
0 commit comments