Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f9b7588

Browse files
authored
refactor(ci): conditionally run jobs based on file changes (#4242)
* refactor(ci): only run ts jobs on ts changes This modifies the `style-lint-typescript` and `test-js` jobs to only run when there are changes in `site`. * refactor(ci): only run lint-shellcheck on sh changes * refactor(ci): only run go jobs on go changes * refactor(ci): only run style-fmt when needed This adds a new item to `changes` for `**.tf` changes. Now it will only run `style-fmt` if PR includes changes to `site/**`, `**.tf`, or `**.ts`. * refactor(ci): run e2e on go, ts or tf changes * refactor(ci): run gen on gen changes * refactor(ci): delete old comments * fixup: try moving if step inside test-go job * fixup: try if all steps * fixup!: refactor(ci): run gen on gen changes * Revert "refactor(ci): run gen on gen changes" This reverts commit d0a5ba1.
1 parent c9bedc5 commit f9b7588

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

.github/workflows/coder.yaml

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,12 @@ jobs:
6464
- '**'
6565
docs:
6666
- 'docs/**'
67-
# For testing:
68-
# - '.github/**'
6967
sh:
7068
- "**.sh"
69+
go:
70+
- "**.go"
71+
tf:
72+
- "**.tf"
7173
ts:
7274
- 'site/**'
7375
k8s:
@@ -92,6 +94,8 @@ jobs:
9294
name: style/lint/golangci
9395
timeout-minutes: 5
9496
runs-on: ubuntu-latest
97+
needs: changes
98+
if: needs.changes.outputs.go == 'true'
9599
steps:
96100
- uses: actions/checkout@v3
97101
- uses: actions/setup-go@v3
@@ -115,6 +119,8 @@ jobs:
115119
name: style/lint/shellcheck
116120
timeout-minutes: 5
117121
runs-on: ubuntu-latest
122+
needs: changes
123+
if: needs.changes.outputs.sh == 'true'
118124
steps:
119125
- uses: actions/checkout@v3
120126
- name: Run ShellCheck
@@ -128,6 +134,8 @@ jobs:
128134
name: "style/lint/typescript"
129135
timeout-minutes: 5
130136
runs-on: ubuntu-latest
137+
needs: changes
138+
if: needs.changes.outputs.ts == 'true'
131139
steps:
132140
- name: Checkout
133141
uses: actions/checkout@v3
@@ -247,6 +255,8 @@ jobs:
247255
name: "style/fmt"
248256
runs-on: ubuntu-latest
249257
timeout-minutes: 5
258+
needs: changes
259+
if: needs.changes.outputs.sh == 'true' || needs.changes.outputs.ts == 'true' || needs.changes.outputs.tf == 'true'
250260
steps:
251261
- name: Checkout
252262
uses: actions/checkout@v3
@@ -280,6 +290,7 @@ jobs:
280290
name: "test/go"
281291
runs-on: ${{ matrix.os }}
282292
timeout-minutes: 20
293+
needs: changes
283294
strategy:
284295
matrix:
285296
os:
@@ -288,30 +299,36 @@ jobs:
288299
- windows-2022
289300
steps:
290301
- uses: actions/checkout@v3
302+
if: needs.changes.outputs.go == 'true'
291303

292304
- uses: actions/setup-go@v3
305+
if: needs.changes.outputs.go == 'true'
293306
with:
294307
go-version: "~1.19"
295308

296309
- name: Echo Go Cache Paths
310+
if: needs.changes.outputs.go == 'true'
297311
id: go-cache-paths
298312
run: |
299313
echo "::set-output name=go-build::$(go env GOCACHE)"
300314
echo "::set-output name=go-mod::$(go env GOMODCACHE)"
301315
302316
- name: Go Build Cache
317+
if: needs.changes.outputs.go == 'true'
303318
uses: actions/cache@v3
304319
with:
305320
path: ${{ steps.go-cache-paths.outputs.go-build }}
306321
key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.**', '**.go') }}
307322

308323
- name: Go Mod Cache
324+
if: needs.changes.outputs.go == 'true'
309325
uses: actions/cache@v3
310326
with:
311327
path: ${{ steps.go-cache-paths.outputs.go-mod }}
312328
key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }}
313329

314330
- name: Install gotestsum
331+
if: needs.changes.outputs.go == 'true'
315332
uses: jaxxstorm/[email protected]
316333
env:
317334
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -320,11 +337,13 @@ jobs:
320337
tag: v1.7.0
321338

322339
- uses: hashicorp/setup-terraform@v2
340+
if: needs.changes.outputs.go == 'true'
323341
with:
324342
terraform_version: 1.1.9
325343
terraform_wrapper: false
326344

327345
- name: Test with Mock Database
346+
if: needs.changes.outputs.go == 'true'
328347
id: test
329348
shell: bash
330349
run: |
@@ -350,7 +369,7 @@ jobs:
350369
# that is no guarantee, see:
351370
# https://github.com/codecov/codecov-action/issues/788
352371
continue-on-error: true
353-
if: steps.test.outputs.cover && github.actor != 'dependabot[bot]' && !github.event.pull_request.head.repo.fork
372+
if: steps.test.outputs.cover && github.actor != 'dependabot[bot]' && !github.event.pull_request.head.repo.fork && needs.changes.outputs.go == 'true'
354373
with:
355374
token: ${{ secrets.CODECOV_TOKEN }}
356375
files: ./gotests.coverage
@@ -364,6 +383,8 @@ jobs:
364383
# goroutines. Setting this to the timeout +5m should work quite well
365384
# even if some of the preceding steps are slow.
366385
timeout-minutes: 25
386+
needs: changes
387+
if: needs.changes.outputs.go == 'true'
367388
steps:
368389
- uses: actions/checkout@v3
369390

@@ -518,6 +539,8 @@ jobs:
518539
name: "test/js"
519540
runs-on: ubuntu-latest
520541
timeout-minutes: 20
542+
needs: changes
543+
if: needs.changes.outputs.ts == 'true'
521544
steps:
522545
- uses: actions/checkout@v3
523546

@@ -556,9 +579,8 @@ jobs:
556579

557580
test-e2e:
558581
name: "test/e2e/${{ matrix.os }}"
559-
needs:
560-
- changes
561-
if: needs.changes.outputs.docs-only == 'false'
582+
needs: changes
583+
if: needs.changes.outputs.go == 'true' || needs.changes.outputs.ts == 'true' || needs.changes.outputs.tf == 'true'
562584
runs-on: ${{ matrix.os }}
563585
timeout-minutes: 20
564586
strategy:

0 commit comments

Comments
 (0)