Skip to content

Commit 07471c0

Browse files
authored
Preventing tests from running if no relenant changes pushed
1 parent 9e616f7 commit 07471c0

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

.github/workflows/test.yml

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,35 @@ on:
66
- main
77

88
jobs:
9+
check-changes:
10+
runs-on: ubuntu-latest
11+
outputs:
12+
RUN_TESTS: ${{ steps.check_changes.outputs.RUN_TESTS }}
13+
14+
steps:
15+
- name: Checkout Repository
16+
uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 2 # Ensure we have commit history for comparison
19+
20+
- name: Check Modified Files
21+
id: check_changes
22+
run: |
23+
git fetch origin main --depth=2
24+
CHANGED_FILES=$(git diff --name-only HEAD^ HEAD)
25+
26+
# Check if cli_monitor.py or tests/ directory has been changed
27+
if echo "$CHANGED_FILES" | grep -qE '^(cli_monitor.py|tests/)'; then
28+
echo "RUN_TESTS=true" >> $GITHUB_ENV
29+
echo "RUN_TESTS=true" >> $GITHUB_OUTPUT
30+
else
31+
echo "RUN_TESTS=false" >> $GITHUB_ENV
32+
echo "RUN_TESTS=false" >> $GITHUB_OUTPUT
33+
fi
34+
935
test:
36+
needs: check-changes
37+
if: needs.check-changes.outputs.RUN_TESTS == 'true' # Skip if no relevant changes
1038
runs-on: ${{ matrix.os }}
1139
strategy:
1240
matrix:
@@ -43,4 +71,4 @@ jobs:
4371
with:
4472
name: TEST_RESULT_${{ matrix.os }}_${{ matrix.python-version }}
4573
path: test-results/
46-
retention-days: 1
74+
retention-days: 1

0 commit comments

Comments
 (0)