Skip to content

Commit 52002e4

Browse files
authored
ci: do not run full application build/tests for docs-only changes (#162)
Markdown-only changes (e.g. AGENTS.md, README, *.md) were triggering the entire CI matrix (unit tests x3, build, integration x3). - Added `changes` job using dorny/paths-filter (consistent with patchloom). - Jobs now always declare (so required status checks like "unit-test (ubuntu-latest)" report success) but early-exit with a cheap step when only non-code files changed on PRs. - On push/main, merge_group, etc. full runs still happen. - Filter includes source, tests, package files, tsconfig, actions, and ci.yml itself. Fixes unnecessary builds when changing one .md file (as seen in #161). See ci-workflow-hygiene and patchloom for the pattern. Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
1 parent b0dcde9 commit 52002e4

1 file changed

Lines changed: 85 additions & 8 deletions

File tree

.github/workflows/ci.yml

Lines changed: 85 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,42 @@ on:
99

1010
permissions:
1111
contents: read
12+
pull-requests: read # for dorny/paths-filter in changes job
1213

1314
concurrency:
1415
group: ci-${{ github.workflow }}-${{ github.ref }}
1516
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
1617

1718
jobs:
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,33 @@ jobs:
2857
with:
2958
egress-policy: audit
3059

60+
- name: Check if application build/tests are needed
61+
id: should-run
62+
shell: bash
63+
run: |
64+
if [ "${{ github.event_name }}" = "pull_request" ] && [ "${{ needs.changes.outputs.code }}" != "true" ]; then
65+
echo "run=false" >> "$GITHUB_OUTPUT"
66+
echo "Only documentation or non-code changes detected. Skipping application build and tests."
67+
else
68+
echo "run=true" >> "$GITHUB_OUTPUT"
69+
fi
70+
3171
- name: Checkout
72+
if: steps.should-run.outputs.run == 'true' || github.event_name != 'pull_request'
3273
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
3374
with:
3475
persist-credentials: false
3576

3677
- name: Setup Node.js
78+
if: steps.should-run.outputs.run == 'true' || github.event_name != 'pull_request'
3779
uses: ./.github/actions/setup-node
3880

3981
- name: Run tests
82+
if: steps.should-run.outputs.run == 'true' || github.event_name != 'pull_request'
4083
run: npm test
4184

4285
- name: Check code coverage
43-
if: matrix.os == 'ubuntu-latest'
86+
if: (steps.should-run.outputs.run == 'true' || github.event_name != 'pull_request') && matrix.os == 'ubuntu-latest'
4487
id: coverage
4588
run: |
4689
output=$(npm run test:coverage 2>&1)
@@ -49,7 +92,7 @@ jobs:
4992
echo "percentage=$pct" >> "$GITHUB_OUTPUT"
5093
5194
- name: Determine badge color
52-
if: matrix.os == 'ubuntu-latest'
95+
if: (steps.should-run.outputs.run == 'true' || github.event_name != 'pull_request') && matrix.os == 'ubuntu-latest'
5396
id: color
5497
run: |
5598
pct="${{ steps.coverage.outputs.percentage }}"
@@ -67,7 +110,7 @@ jobs:
67110
fi
68111
69112
- name: Update coverage badge
70-
if: matrix.os == 'ubuntu-latest' && github.event_name == 'push' && github.ref == 'refs/heads/main'
113+
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'
71114
continue-on-error: true
72115
uses: schneegans/dynamic-badges-action@0e50b8bad39e7e1afd3e4e9c2b7dd145fad07501 # v1.8.0
73116
with:
@@ -79,6 +122,8 @@ jobs:
79122
color: ${{ steps.color.outputs.color }}
80123

81124
build:
125+
needs: [changes]
126+
if: always()
82127
runs-on: ubuntu-latest
83128
timeout-minutes: 10
84129
steps:
@@ -87,22 +132,38 @@ jobs:
87132
with:
88133
egress-policy: audit
89134

135+
- name: Check if application build is needed
136+
id: should-run
137+
shell: bash
138+
run: |
139+
if [ "${{ github.event_name }}" = "pull_request" ] && [ "${{ needs.changes.outputs.code }}" != "true" ]; then
140+
echo "run=false" >> "$GITHUB_OUTPUT"
141+
echo "Only documentation or non-code changes detected. Skipping application build."
142+
else
143+
echo "run=true" >> "$GITHUB_OUTPUT"
144+
fi
145+
90146
- name: Checkout
147+
if: steps.should-run.outputs.run == 'true' || github.event_name != 'pull_request'
91148
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
92149
with:
93150
persist-credentials: false
94151

95152
- name: Setup Node.js
153+
if: steps.should-run.outputs.run == 'true' || github.event_name != 'pull_request'
96154
uses: ./.github/actions/setup-node
97155

98156
- name: Compile
157+
if: steps.should-run.outputs.run == 'true' || github.event_name != 'pull_request'
99158
run: npm run compile
100159

101160
- name: Package extension
161+
if: steps.should-run.outputs.run == 'true' || github.event_name != 'pull_request'
102162
run: npm run package
103163

104164
integration-test:
105-
needs: [unit-test, build]
165+
needs: [changes, unit-test, build]
166+
if: always()
106167
strategy:
107168
fail-fast: false
108169
matrix:
@@ -116,35 +177,51 @@ jobs:
116177
with:
117178
egress-policy: audit
118179

180+
- name: Check if application tests are needed
181+
id: should-run
182+
shell: bash
183+
run: |
184+
if [ "${{ github.event_name }}" = "pull_request" ] && [ "${{ needs.changes.outputs.code }}" != "true" ]; then
185+
echo "run=false" >> "$GITHUB_OUTPUT"
186+
echo "Only documentation or non-code changes detected. Skipping integration tests."
187+
else
188+
echo "run=true" >> "$GITHUB_OUTPUT"
189+
fi
190+
119191
- name: Checkout
192+
if: steps.should-run.outputs.run == 'true' || github.event_name != 'pull_request'
120193
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
121194
with:
122195
persist-credentials: false
123196

124197
- name: Setup Node.js
198+
if: steps.should-run.outputs.run == 'true' || github.event_name != 'pull_request'
125199
uses: ./.github/actions/setup-node
126200

127201
- name: Compile extension and tests
202+
if: steps.should-run.outputs.run == 'true' || github.event_name != 'pull_request'
128203
run: npm run compile && npm run compile-tests
129204

130205
- name: Run extension integration tests (Linux)
131-
if: runner.os == 'Linux'
206+
if: (steps.should-run.outputs.run == 'true' || github.event_name != 'pull_request') && runner.os == 'Linux'
132207
run: xvfb-run -a npm run test:extension
133208

134209
- name: Run extension integration tests
135-
if: runner.os != 'Linux'
210+
if: (steps.should-run.outputs.run == 'true' || github.event_name != 'pull_request') && runner.os != 'Linux'
136211
run: npm run test:extension
137212

138213
- name: Setup UI test VS Code
214+
if: steps.should-run.outputs.run == 'true' || github.event_name != 'pull_request'
139215
run: npx extest setup-tests --code_version max --extensions_dir .vscode-test/extensions
140216

141217
- name: Patch test VS Code to run as background app
218+
if: steps.should-run.outputs.run == 'true' || github.event_name != 'pull_request'
142219
run: bash scripts/hide-test-vscode.sh
143220

144221
- name: Run UI tests (Linux)
145-
if: runner.os == 'Linux'
222+
if: (steps.should-run.outputs.run == 'true' || github.event_name != 'pull_request') && runner.os == 'Linux'
146223
run: xvfb-run -a npx extest run-tests './out-uitest/test/ui/*.test.js' --extensions_dir .vscode-test/extensions
147224

148225
- name: Run UI tests
149-
if: runner.os != 'Linux'
226+
if: (steps.should-run.outputs.run == 'true' || github.event_name != 'pull_request') && runner.os != 'Linux'
150227
run: npx extest run-tests './out-uitest/test/ui/*.test.js' --extensions_dir .vscode-test/extensions

0 commit comments

Comments
 (0)