Skip to content

Commit eb4bcfe

Browse files
committed
[CI] Improve handling of comment when no test files are present in the commit
1 parent 19e685a commit eb4bcfe

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

.github/workflows/pr-comments.yml

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,30 @@ jobs:
7171
- name: Checkout code
7272
uses: actions/checkout@v4
7373

74-
- name: Check and comment if no unit test files modified
74+
- name: Get changed test files
75+
id: changed-test-files
76+
uses: tj-actions/changed-files@v45
77+
with:
78+
files_yaml: |
79+
test:
80+
- '**/*_test.py' # Matches files ending with `_test.py` (e.g., `some_module_test.py`)
81+
- '**/test_*.py' # Matches files starting with `test_` (e.g., `test_helper.py`)
82+
- '**/*_tests.py' # Matches files ending with `_tests.py` (e.g., `some_module_tests.py`)
83+
- '**/tests_*.py' # Matches files starting with `tests_` (e.g., `tests_helper.py`)
84+
- '**/test{s,}.py' # Matches both `test.py` and `tests.py` (e.g., `some_folder/test.py`, `some_folder/tests.py`)
85+
- '**/*.test.*' # Matches files containing `.test.` anywhere in the name (e.g., `test_file.test.py`, `module.test.js`)
86+
87+
- name: Check if test files were modified
88+
id: check-test-files
7589
run: |
76-
git fetch origin master
77-
changed_files=$(git diff --name-only origin/master)
78-
79-
if echo "$changed_files" | grep -qE '(^test|_test\.py|^tests|_tests\.py|.test)'; then
80-
echo "✅ Unit test files were modified."
90+
if [[ "${{ steps.changed-test-files.outputs.test_any_changed }}" == "true" ]]; then
91+
echo "comment_message=✅ Test files were modified. Ensure that the tests cover all relevant changes" >> $GITHUB_ENV
8192
else
82-
echo "⚠️ No unit test files modified."
83-
84-
curl -X POST \
85-
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
86-
-H "Accept: application/vnd.github.v3+json" \
87-
-d '{"body":"⚠️ No unit test files modified. Please ensure that changes are properly tested. ⚠️"}' \
88-
"https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments"
93+
echo "comment_message=⚠️ No test files modified. Please ensure that changes are properly tested. ⚠️" >> $GITHUB_ENV
8994
fi
95+
96+
- name: Update PR with test file change status
97+
uses: mshick/add-pr-comment@v2
98+
with:
99+
message: "${{ env.comment_message }}"
100+
allow-repeats: false

0 commit comments

Comments
 (0)