99
1010permissions :
1111 contents : read
12+ pull-requests : read # for dorny/paths-filter in changes job
1213
1314concurrency :
1415 group : ci-${{ github.workflow }}-${{ github.ref }}
1516 cancel-in-progress : ${{ github.ref != 'refs/heads/main' }}
1617
1718jobs :
19+ changes :
20+ # Detect whether source code changed. On non-PR events (push, merge_group,
21+ # workflow_dispatch) this job is skipped, which causes all downstream jobs to
22+ # run unconditionally via the `needs.changes.result == 'skipped'` guard.
23+ if : github.event_name == 'pull_request'
24+ runs-on : ubuntu-latest
25+ permissions :
26+ pull-requests : read
27+ outputs :
28+ code : ${{ steps.filter.outputs.code }}
29+ steps :
30+ - uses : dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
31+ id : filter
32+ with :
33+ filters : |
34+ code:
35+ - 'src/**'
36+ - 'test/**'
37+ - 'scripts/**'
38+ - 'package.json'
39+ - 'package-lock.json'
40+ - 'tsconfig*.json'
41+ - '.nvmrc'
42+ - '.github/actions/**'
43+ - '.github/workflows/ci.yml'
44+
1845 unit-test :
46+ needs : [changes]
47+ if : always()
1948 strategy :
2049 fail-fast : false
2150 matrix :
@@ -28,19 +57,32 @@ jobs:
2857 with :
2958 egress-policy : audit
3059
60+ - name : Check if application build/tests are needed
61+ id : should-run
62+ run : |
63+ if [ "${{ github.event_name }}" = "pull_request" ] && [ "${{ needs.changes.outputs.code }}" != "true" ]; then
64+ echo "run=false" >> "$GITHUB_OUTPUT"
65+ echo "Only documentation or non-code changes detected. Skipping application build and tests."
66+ else
67+ echo "run=true" >> "$GITHUB_OUTPUT"
68+ fi
69+
3170 - name : Checkout
71+ if : steps.should-run.outputs.run == 'true' || github.event_name != 'pull_request'
3272 uses : actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
3373 with :
3474 persist-credentials : false
3575
3676 - name : Setup Node.js
77+ if : steps.should-run.outputs.run == 'true' || github.event_name != 'pull_request'
3778 uses : ./.github/actions/setup-node
3879
3980 - name : Run tests
81+ if : steps.should-run.outputs.run == 'true' || github.event_name != 'pull_request'
4082 run : npm test
4183
4284 - name : Check code coverage
43- if : matrix.os == 'ubuntu-latest'
85+ if : (steps.should-run.outputs.run == 'true' || github.event_name != 'pull_request') && matrix.os == 'ubuntu-latest'
4486 id : coverage
4587 run : |
4688 output=$(npm run test:coverage 2>&1)
4991 echo "percentage=$pct" >> "$GITHUB_OUTPUT"
5092
5193 - name : Determine badge color
52- if : matrix.os == 'ubuntu-latest'
94+ if : (steps.should-run.outputs.run == 'true' || github.event_name != 'pull_request') && matrix.os == 'ubuntu-latest'
5395 id : color
5496 run : |
5597 pct="${{ steps.coverage.outputs.percentage }}"
67109 fi
68110
69111 - name : Update coverage badge
70- if : matrix.os == 'ubuntu-latest' && github.event_name == 'push' && github.ref == 'refs/heads/main'
112+ if : (steps.should-run.outputs.run == 'true' || github.event_name != 'pull_request') && matrix.os == 'ubuntu-latest' && github.event_name == 'push' && github.ref == 'refs/heads/main'
71113 continue-on-error : true
72114 uses : schneegans/dynamic-badges-action@0e50b8bad39e7e1afd3e4e9c2b7dd145fad07501 # v1.8.0
73115 with :
79121 color : ${{ steps.color.outputs.color }}
80122
81123 build :
124+ needs : [changes]
125+ if : always()
82126 runs-on : ubuntu-latest
83127 timeout-minutes : 10
84128 steps :
@@ -87,22 +131,37 @@ jobs:
87131 with :
88132 egress-policy : audit
89133
134+ - name : Check if application build is needed
135+ id : should-run
136+ run : |
137+ if [ "${{ github.event_name }}" = "pull_request" ] && [ "${{ needs.changes.outputs.code }}" != "true" ]; then
138+ echo "run=false" >> "$GITHUB_OUTPUT"
139+ echo "Only documentation or non-code changes detected. Skipping application build."
140+ else
141+ echo "run=true" >> "$GITHUB_OUTPUT"
142+ fi
143+
90144 - name : Checkout
145+ if : steps.should-run.outputs.run == 'true' || github.event_name != 'pull_request'
91146 uses : actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
92147 with :
93148 persist-credentials : false
94149
95150 - name : Setup Node.js
151+ if : steps.should-run.outputs.run == 'true' || github.event_name != 'pull_request'
96152 uses : ./.github/actions/setup-node
97153
98154 - name : Compile
155+ if : steps.should-run.outputs.run == 'true' || github.event_name != 'pull_request'
99156 run : npm run compile
100157
101158 - name : Package extension
159+ if : steps.should-run.outputs.run == 'true' || github.event_name != 'pull_request'
102160 run : npm run package
103161
104162 integration-test :
105- needs : [unit-test, build]
163+ needs : [changes, unit-test, build]
164+ if : always()
106165 strategy :
107166 fail-fast : false
108167 matrix :
@@ -116,35 +175,50 @@ jobs:
116175 with :
117176 egress-policy : audit
118177
178+ - name : Check if application tests are needed
179+ id : should-run
180+ run : |
181+ if [ "${{ github.event_name }}" = "pull_request" ] && [ "${{ needs.changes.outputs.code }}" != "true" ]; then
182+ echo "run=false" >> "$GITHUB_OUTPUT"
183+ echo "Only documentation or non-code changes detected. Skipping integration tests."
184+ else
185+ echo "run=true" >> "$GITHUB_OUTPUT"
186+ fi
187+
119188 - name : Checkout
189+ if : steps.should-run.outputs.run == 'true' || github.event_name != 'pull_request'
120190 uses : actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
121191 with :
122192 persist-credentials : false
123193
124194 - name : Setup Node.js
195+ if : steps.should-run.outputs.run == 'true' || github.event_name != 'pull_request'
125196 uses : ./.github/actions/setup-node
126197
127198 - name : Compile extension and tests
199+ if : steps.should-run.outputs.run == 'true' || github.event_name != 'pull_request'
128200 run : npm run compile && npm run compile-tests
129201
130202 - name : Run extension integration tests (Linux)
131- if : runner.os == 'Linux'
203+ if : (steps.should-run.outputs.run == 'true' || github.event_name != 'pull_request') && runner.os == 'Linux'
132204 run : xvfb-run -a npm run test:extension
133205
134206 - name : Run extension integration tests
135- if : runner.os != 'Linux'
207+ if : (steps.should-run.outputs.run == 'true' || github.event_name != 'pull_request') && runner.os != 'Linux'
136208 run : npm run test:extension
137209
138210 - name : Setup UI test VS Code
211+ if : steps.should-run.outputs.run == 'true' || github.event_name != 'pull_request'
139212 run : npx extest setup-tests --code_version max --extensions_dir .vscode-test/extensions
140213
141214 - name : Patch test VS Code to run as background app
215+ if : steps.should-run.outputs.run == 'true' || github.event_name != 'pull_request'
142216 run : bash scripts/hide-test-vscode.sh
143217
144218 - name : Run UI tests (Linux)
145- if : runner.os == 'Linux'
219+ if : (steps.should-run.outputs.run == 'true' || github.event_name != 'pull_request') && runner.os == 'Linux'
146220 run : xvfb-run -a npx extest run-tests './out-uitest/test/ui/*.test.js' --extensions_dir .vscode-test/extensions
147221
148222 - name : Run UI tests
149- if : runner.os != 'Linux'
223+ if : (steps.should-run.outputs.run == 'true' || github.event_name != 'pull_request') && runner.os != 'Linux'
150224 run : npx extest run-tests './out-uitest/test/ui/*.test.js' --extensions_dir .vscode-test/extensions
0 commit comments