@@ -71,19 +71,28 @@ jobs:
71
71
- name : Checkout code
72
72
uses : actions/checkout@v4
73
73
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{s,}.py' # Matches files ending with `_test.py` (e.g., `some_module_test.py`, `some_module_tests.py`)
81
+ - '**/test{s,}_*.py' # Matches files starting with `test_` (e.g., `test_helper.py`, `tests_helper.py`)
82
+ - '**/test{s,}.py' # Matches both `test.py` and `tests.py` (e.g., `some_folder/test.py`, `some_folder/tests.py`)
83
+ - '**/*.test.*' # Matches files containing `.test.` anywhere in the name (e.g., `test_file.test.py`, `module.test.js`)
84
+
85
+ - name : Check if test files were modified
86
+ id : check-test-files
75
87
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."
88
+ if [[ "${{ steps.changed-test-files.outputs.test_any_changed }}" == "true" ]]; then
89
+ echo "comment_message=✅ Test files were modified. Ensure that the tests cover all relevant changes" >> $GITHUB_ENV
81
90
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"
91
+ echo "comment_message=⚠️ No test files modified. Please ensure that changes are properly tested. ⚠️" >> $GITHUB_ENV
89
92
fi
93
+
94
+ - name : Update PR with test file change status
95
+ uses : mshick/add-pr-comment@v2
96
+ with :
97
+ message : " ${{ env.comment_message }}"
98
+ allow-repeats : false
0 commit comments