Skip to content

Commit 74464e8

Browse files
authored
Fix wrong changes produced by style/repo. check bot (#46371)
* Fix wrong changes produced by style/repo. check bot --------- Co-authored-by: ydshieh <[email protected]>
1 parent 1b8ec34 commit 74464e8

1 file changed

Lines changed: 44 additions & 24 deletions

File tree

‎.github/workflows/pr-repo-consistency-bot.yml‎

Lines changed: 44 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,12 @@ jobs:
117117
run-repo-consistency-checks:
118118
runs-on: ubuntu-22.04
119119
needs: [get-pr-info, check-timestamps, init_comment_with_url]
120+
permissions:
121+
contents: read
122+
pull-requests: read
120123
outputs:
121124
changes_detected: ${{ steps.run_repo_checks.outputs.changes_detected || steps.run_style_checks.outputs.changes_detected }}
125+
util_scripts_modified: ${{ steps.check_util_scripts.outputs.util_scripts_modified }}
122126
steps:
123127
# Checkout the trusted base repository (main branch) - this is safe
124128
- name: Checkout base repository
@@ -158,32 +162,45 @@ jobs:
158162
git remote add upstream https://github.com/${{ github.repository }}.git
159163
git fetch upstream main:main
160164
161-
- name: Copy trusted scripts from main branch
162-
run: |
163-
# Security: Copy trusted scripts from main branch and run commands explicitly (not via make)
164-
# to avoid executing potentially malicious Makefile or scripts from the PR
165-
cp setup.py pr-repo/setup.py
166-
cp utils/custom_init_isort.py pr-repo/utils/custom_init_isort.py
167-
cp utils/sort_auto_mappings.py pr-repo/utils/sort_auto_mappings.py
168-
cp utils/check_doc_toc.py pr-repo/utils/check_doc_toc.py
169-
cp utils/check_copies.py pr-repo/utils/check_copies.py
170-
cp utils/check_modular_conversion.py pr-repo/utils/check_modular_conversion.py
171-
cp utils/check_dummies.py pr-repo/utils/check_dummies.py
172-
cp utils/check_pipeline_typing.py pr-repo/utils/check_pipeline_typing.py
173-
cp utils/check_doctest_list.py pr-repo/utils/check_doctest_list.py
174-
cp utils/check_docstrings.py pr-repo/utils/check_docstrings.py
175-
cp utils/add_dates.py pr-repo/utils/add_dates.py
165+
- name: Check if util scripts are modified in PR
166+
id: check_util_scripts
167+
uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6.4.1
168+
with:
169+
script: |
170+
// Re-fetch the PR file list from the API rather than using get-pr-info's PR_FILES
171+
// output, to avoid template injection and E2BIG issues (see pr_slow_ci_suggestion.yml).
172+
const UTIL_SCRIPTS = new Set([
173+
'setup.py',
174+
'utils/custom_init_isort.py',
175+
'utils/sort_auto_mappings.py',
176+
'utils/check_doc_toc.py',
177+
'utils/check_copies.py',
178+
'utils/check_modular_conversion.py',
179+
'utils/check_dummies.py',
180+
'utils/check_pipeline_typing.py',
181+
'utils/check_doctest_list.py',
182+
'utils/check_docstrings.py',
183+
'utils/add_dates.py',
184+
]);
185+
186+
const files = await github.paginate(github.rest.pulls.listFiles, {
187+
owner: context.repo.owner,
188+
repo: context.repo.repo,
189+
pull_number: context.payload.issue.number,
190+
});
176191
177-
- name: Install editable transformers from PR branch with copied scripts
192+
const modified = files.some(f => UTIL_SCRIPTS.has(f.filename));
193+
core.setOutput('util_scripts_modified', modified ? 'true' : 'false');
194+
195+
- name: Install editable transformers from PR branch
196+
if: steps.check_util_scripts.outputs.util_scripts_modified != 'true'
178197
run: |
179-
# Run commands in PR directory (with the copied trusted scripts)
180198
cd pr-repo
181-
182199
pip install -e .
183200
184201
- name: Run repo consistency checks with trusted script
185202
id: run_repo_checks
186-
if: startsWith(github.event.comment.body, '@bot /repo')
203+
if: steps.check_util_scripts.outputs.util_scripts_modified != 'true' && startsWith(github.event.comment.body, '@bot /repo')
187204
run: |
188205
# Continue on errors (like Makefile's - prefix)
189206
set +e
@@ -217,7 +234,7 @@ jobs:
217234
218235
- name: Run style checks with trusted script
219236
id: run_style_checks
220-
if: startsWith(github.event.comment.body, '@bot /style')
237+
if: steps.check_util_scripts.outputs.util_scripts_modified != 'true' && startsWith(github.event.comment.body, '@bot /style')
221238
run: |
222239
# Continue on errors (like Makefile's - prefix)
223240
set +e
@@ -243,7 +260,7 @@ jobs:
243260
fi
244261
245262
- name: Save modified files
246-
if: steps.run_repo_checks.outputs.changes_detected == 'true' || steps.run_style_checks.outputs.changes_detected == 'true'
263+
if: steps.check_util_scripts.outputs.util_scripts_modified != 'true' && (steps.run_repo_checks.outputs.changes_detected == 'true' || steps.run_style_checks.outputs.changes_detected == 'true')
247264
run: |
248265
cd pr-repo
249266
mkdir -p ../artifact-staging
@@ -255,7 +272,7 @@ jobs:
255272
done < ../artifact-staging/modified-files.txt
256273
257274
- name: Upload modified files
258-
if: steps.run_repo_checks.outputs.changes_detected == 'true' || steps.run_style_checks.outputs.changes_detected == 'true'
275+
if: steps.check_util_scripts.outputs.util_scripts_modified != 'true' && (steps.run_repo_checks.outputs.changes_detected == 'true' || steps.run_style_checks.outputs.changes_detected == 'true')
259276
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
260277
with:
261278
name: modified-files
@@ -335,6 +352,7 @@ jobs:
335352
if: needs.init_comment_with_url.result == 'success'
336353
env:
337354
CHANGES_DETECTED: ${{ needs.run-repo-consistency-checks.outputs.changes_detected }}
355+
UTIL_SCRIPTS_MODIFIED: ${{ needs.run-repo-consistency-checks.outputs.util_scripts_modified }}
338356
COMMENT_BODY: ${{ github.event.comment.body }}
339357
run: |
340358
# Determine which command was used
@@ -343,8 +361,10 @@ jobs:
343361
else
344362
MESSAGE_PREFIX="Repo. Consistency"
345363
fi
346-
347-
if [ "$CHANGES_DETECTED" = 'true' ]; then
364+
365+
if [ "$UTIL_SCRIPTS_MODIFIED" = 'true' ]; then
366+
echo "final_comment=${MESSAGE_PREFIX}: \`setup.py\` or some script files under the \`utils/\` directory are modified in this PR. Please run style/repo. checks/fixes locally." >> $GITHUB_OUTPUT
367+
elif [ "$CHANGES_DETECTED" = 'true' ]; then
348368
echo "final_comment=${MESSAGE_PREFIX} bot fixed some files and pushed the changes." >> $GITHUB_OUTPUT
349369
else
350370
echo "final_comment=${MESSAGE_PREFIX} fix runs successfully without any file modified." >> $GITHUB_OUTPUT

0 commit comments

Comments
 (0)