@@ -2,9 +2,6 @@ name: Python CI
22
33on :
44 pull_request :
5- paths-ignore :
6- - " **.md"
7- - " LICENSE"
85 push :
96 branches :
107 - main
@@ -18,8 +15,40 @@ concurrency:
1815 cancel-in-progress : ${{ github.event_name == 'pull_request' }}
1916
2017jobs :
18+ classify-changes :
19+ name : Classify Changes
20+ runs-on : ubuntu-latest
21+ outputs :
22+ code_changed : ${{ steps.classify.outputs.code_changed }}
23+ steps :
24+ - uses : actions/checkout@v6
25+ with :
26+ fetch-depth : 0
27+
28+ - name : Check whether this PR changes non-doc files
29+ id : classify
30+ env :
31+ BASE_SHA : ${{ github.event.pull_request.base.sha }}
32+ HEAD_SHA : ${{ github.event.pull_request.head.sha }}
33+ run : |
34+ if [[ "${{ github.event_name }}" != "pull_request" ]]; then
35+ echo "code_changed=true" >> "$GITHUB_OUTPUT"
36+ exit 0
37+ fi
38+
39+ changed_files="$(git diff --name-only "$BASE_SHA" "$HEAD_SHA")"
40+ echo "$changed_files"
41+
42+ if printf '%s\n' "$changed_files" | grep -Ev '(^$|\.md$|^LICENSE$)' > /dev/null; then
43+ echo "code_changed=true" >> "$GITHUB_OUTPUT"
44+ else
45+ echo "code_changed=false" >> "$GITHUB_OUTPUT"
46+ fi
47+
2148 lint :
2249 name : Lint and Format
50+ needs : classify-changes
51+ if : needs.classify-changes.outputs.code_changed == 'true'
2352 runs-on : ubuntu-latest
2453 timeout-minutes : 10
2554 steps :
4372
4473 type-check :
4574 name : Type Check (${{ matrix.type-checker }})
75+ needs : classify-changes
76+ if : needs.classify-changes.outputs.code_changed == 'true'
4677 runs-on : ubuntu-latest
4778 timeout-minutes : 10
4879 strategy :
71102
72103 test :
73104 name : Test (py${{ matrix.python-version }}, ${{ matrix.os }})
105+ needs : classify-changes
106+ if : needs.classify-changes.outputs.code_changed == 'true'
74107 runs-on : ${{ matrix.os }}
75108 timeout-minutes : 30
76109 strategy :
@@ -151,6 +184,8 @@ jobs:
151184
152185 test-npx-fallback :
153186 name : Test npx fallback (py${{ matrix.python-version }}, ${{ matrix.os }})
187+ needs : classify-changes
188+ if : needs.classify-changes.outputs.code_changed == 'true'
154189 runs-on : ${{ matrix.os }}
155190 timeout-minutes : 30
156191 strategy :
@@ -223,6 +258,8 @@ jobs:
223258
224259 build :
225260 name : Build Package
261+ needs : classify-changes
262+ if : needs.classify-changes.outputs.code_changed == 'true'
226263 runs-on : ubuntu-latest
227264 timeout-minutes : 10
228265 steps :
@@ -246,7 +283,7 @@ jobs:
246283
247284 ci-success :
248285 name : CI Success
249- needs : [lint, type-check, test, test-npx-fallback, build]
286+ needs : [classify-changes, lint, type-check, test, test-npx-fallback, build]
250287 if : always()
251288 runs-on : ubuntu-latest
252289 steps :
0 commit comments