Skip to content

Commit d10513f

Browse files
authored
ci: optimize jobs with path filtering (#3074)
1 parent 1ddff0a commit d10513f

File tree

1 file changed

+59
-3
lines changed

1 file changed

+59
-3
lines changed

.github/workflows/coder.yaml

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ on:
66
- main
77
tags:
88
- "*"
9-
paths-ignore:
10-
- "docs/**"
119

1210
pull_request:
1311

@@ -32,9 +30,48 @@ concurrency:
3230
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
3331

3432
jobs:
33+
changes:
34+
runs-on: ubuntu-latest
35+
outputs:
36+
docs-only: ${{ steps.filter.outputs.docs_count == steps.filter.outputs.all_count }}
37+
go: ${{ steps.filter.outputs.go }}
38+
sh: ${{ steps.filter.outputs.sh }}
39+
steps:
40+
# For pull requests it's not necessary to checkout the code
41+
- uses: dorny/paths-filter@v2
42+
id: filter
43+
with:
44+
filters: |
45+
all:
46+
- '**'
47+
docs:
48+
- 'docs/**'
49+
# For testing:
50+
# - '.github/**'
51+
go:
52+
- "**.go"
53+
- "**.mod"
54+
- "**.sum"
55+
sh:
56+
- "**.sh"
57+
- id: debug
58+
run: |
59+
echo "${{ toJSON(steps.filter )}}"
60+
61+
# Debug step
62+
show-changes:
63+
needs: changes
64+
runs-on: ubuntu-latest
65+
steps:
66+
- id: log
67+
run: |
68+
echo "${{ toJSON(needs.changes) }}"
69+
3570
style-lint-golangci:
3671
name: style/lint/golangci
3772
timeout-minutes: 5
73+
needs: changes
74+
if: needs.changes.outputs.go == 'true'
3875
runs-on: ubuntu-latest
3976
steps:
4077
- uses: actions/checkout@v3
@@ -50,6 +87,8 @@ jobs:
5087
name: style/lint/shellcheck
5188
timeout-minutes: 5
5289
runs-on: ubuntu-latest
90+
needs: changes
91+
if: needs.changes.outputs.sh == 'true'
5392
steps:
5493
- uses: actions/checkout@v3
5594
- name: Run ShellCheck
@@ -62,6 +101,8 @@ jobs:
62101
style-lint-typescript:
63102
name: "style/lint/typescript"
64103
timeout-minutes: 5
104+
needs: changes
105+
if: needs.changes.outputs.docs-only == 'false'
65106
runs-on: ubuntu-latest
66107
steps:
67108
- name: Checkout
@@ -89,6 +130,8 @@ jobs:
89130
name: "style/gen"
90131
timeout-minutes: 5
91132
runs-on: ubuntu-latest
133+
needs: changes
134+
if: needs.changes.outputs.docs-only == 'false'
92135
steps:
93136
- uses: actions/checkout@v3
94137

@@ -124,6 +167,8 @@ jobs:
124167

125168
style-fmt:
126169
name: "style/fmt"
170+
needs: changes
171+
if: needs.changes.outputs.docs-only == 'false'
127172
runs-on: ubuntu-latest
128173
timeout-minutes: 5
129174
steps:
@@ -156,6 +201,8 @@ jobs:
156201
157202
test-go:
158203
name: "test/go"
204+
needs: changes
205+
if: needs.changes.outputs.docs-only == 'false'
159206
runs-on: ${{ matrix.os }}
160207
timeout-minutes: 20
161208
strategy:
@@ -232,6 +279,8 @@ jobs:
232279

233280
test-go-postgres:
234281
name: "test/go/postgres"
282+
needs: changes
283+
if: needs.changes.outputs.docs-only == 'false'
235284
runs-on: ubuntu-latest
236285
# This timeout must be greater than the timeout set by `go test` in
237286
# `make test-postgres` to ensure we receive a trace of running
@@ -303,7 +352,10 @@ jobs:
303352
name: "deploy"
304353
runs-on: ubuntu-latest
305354
timeout-minutes: 30
306-
if: github.ref == 'refs/heads/main' && !github.event.pull_request.head.repo.fork
355+
needs: changes
356+
if: |
357+
github.ref == 'refs/heads/main' && !github.event.pull_request.head.repo.fork
358+
&& needs.changes.outputs.docs-only == 'false'
307359
permissions:
308360
contents: read
309361
id-token: write
@@ -409,6 +461,8 @@ jobs:
409461

410462
test-js:
411463
name: "test/js"
464+
needs: changes
465+
if: needs.changes.outputs.docs-only == 'false'
412466
runs-on: ubuntu-latest
413467
timeout-minutes: 20
414468
steps:
@@ -462,6 +516,8 @@ jobs:
462516

463517
test-e2e:
464518
name: "test/e2e/${{ matrix.os }}"
519+
needs: changes
520+
if: needs.changes.outputs.docs-only == 'false'
465521
runs-on: ${{ matrix.os }}
466522
timeout-minutes: 20
467523
strategy:

0 commit comments

Comments
 (0)