Skip to content

Commit ff4b395

Browse files
conditionally run jobs based on detected changes
Signed-off-by: Swapnanil Gupta <swpnlg@amazon.com>
1 parent f75cb0e commit ff4b395

File tree

3 files changed

+159
-15
lines changed

3 files changed

+159
-15
lines changed

.github/workflows/ci-release.yaml

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,18 @@ on:
77
- '**.go'
88
- 'go.mod'
99
- 'go.sum'
10-
- '.github/workflows/e2e-macos.yaml'
11-
- '.github/workflows/e2e-windows.yaml'
12-
- '.github/workflows/e2e-linux.yaml'
1310
- 'contrib/packaging/**'
1411
- 'deps/**'
1512
- 'finch.yaml.d/**'
1613
- 'winres'
1714
- 'Makefile*'
1815
- '.golangci.yaml'
1916
- '!contrib/hello-finch/**'
17+
- '.github/workflows/e2e-macos.yaml'
18+
- '.github/workflows/e2e-windows.yaml'
19+
- '.github/workflows/e2e-linux.yaml'
20+
- '.github/workflows/e2e-ubuntu.yaml'
21+
- '.github/workflows/ci.yaml'
2022
- '.github/workflows/ci-release.yaml'
2123
- '.github/workflows/release-automation.yaml'
2224
- '.github/workflows/upload-installer-to-release.yaml'
@@ -27,10 +29,6 @@ on:
2729
- '.github/workflows/test-pkg.yaml'
2830
- '.github/workflows/build-and-test-msi.yaml'
2931
- '.github/workflows/build-and-test-deb.yaml'
30-
- '.github/workflows/e2e-macos.yaml'
31-
- '.github/workflows/e2e-windows.yaml'
32-
- '.github/workflows/e2e-linux.yaml'
33-
- '.github/workflows/e2e-ubuntu.yaml'
3432
- '.github/workflows/get-version-and-tag-for-ref.yaml'
3533
# - '.github/workflows/build-linux.yaml'
3634
pull_request:
@@ -44,15 +42,16 @@ on:
4442
- '.github/workflows/test-pkg.yaml'
4543
- '.github/workflows/build-and-test-msi.yaml'
4644
- '.github/workflows/build-and-test-deb.yaml'
47-
- '.github/workflows/get-version-and-tag-for-ref.yaml'
4845
- 'installer-builder/**'
4946
- 'msi-builder/**'
47+
- 'contrib/packaging/deb/**'
5048
# - '.github/workflows/build-linux.yaml'
5149
workflow_dispatch:
5250

5351
permissions:
5452
id-token: write
5553
contents: write
54+
pull-requests: read
5655

5756
env:
5857
DEBUG: ${{ secrets.ACTIONS_STEP_DEBUG }}
@@ -62,6 +61,10 @@ concurrency:
6261
cancel-in-progress: true
6362

6463
jobs:
64+
changes:
65+
uses: ./.github/workflows/detect-changes.yaml
66+
secrets: inherit
67+
6568
run-ci-checks:
6669
uses: ./.github/workflows/ci.yaml
6770
secrets: inherit
@@ -85,7 +88,8 @@ jobs:
8588
echo "version=$version" >> ${GITHUB_OUTPUT}
8689
8790
build-and-test-finch-pkg:
88-
needs: get-intermediate-version
91+
needs: [get-intermediate-version, changes]
92+
if: ${{ needs.changes.outputs.mac-build == 'true' }}
8993
uses: ./.github/workflows/build-and-test-pkg.yaml
9094
permissions:
9195
id-token: write
@@ -96,7 +100,8 @@ jobs:
96100
version: ${{ needs.get-intermediate-version.outputs.version }}
97101

98102
build-and-test-finch-msi:
99-
needs: get-intermediate-version
103+
needs: [get-intermediate-version, changes]
104+
if: ${{ needs.changes.outputs.win-build == 'true' }}
100105
uses: ./.github/workflows/build-and-test-msi.yaml
101106
permissions:
102107
id-token: write
@@ -107,7 +112,8 @@ jobs:
107112
version: ${{ needs.get-intermediate-version.outputs.version }}
108113

109114
build-and-test-finch-deb:
110-
needs: get-intermediate-version
115+
needs: [get-intermediate-version, changes]
116+
if: ${{ needs.changes.outputs.ubuntu-build == 'true' }}
111117
uses: ./.github/workflows/build-and-test-deb.yaml
112118
permissions:
113119
id-token: write

.github/workflows/ci.yaml

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,26 @@ on:
2626
- '**.go'
2727
- 'go.mod'
2828
- 'go.sum'
29-
- '.github/workflows/e2e-macos.yaml'
30-
- '.github/workflows/e2e-windows.yaml'
31-
- '.github/workflows/e2e-linux.yaml'
32-
- '.github/workflows/e2e-ubuntu.yaml'
3329
- 'contrib/packaging/**'
3430
- 'deps/**'
3531
- 'finch.yaml.d/**'
3632
- 'winres'
3733
- 'Makefile*'
3834
- '.golangci.yaml'
3935
- '!contrib/hello-finch/**'
36+
- '.github/workflows/ci.yaml'
37+
- '.github/workflows/e2e-macos.yaml'
38+
- '.github/workflows/e2e-windows.yaml'
39+
- '.github/workflows/e2e-linux.yaml'
40+
- '.github/workflows/e2e-ubuntu.yaml'
41+
- '.github/workflows/get-version-and-tag-for-ref.yaml'
4042
workflow_dispatch:
4143
workflow_call:
4244

4345
permissions:
4446
id-token: write
4547
contents: write
48+
pull-requests: read
4649

4750
env:
4851
DEBUG: ${{ secrets.ACTIONS_STEP_DEBUG }}
@@ -53,6 +56,10 @@ concurrency:
5356
cancel-in-progress: true
5457

5558
jobs:
59+
changes:
60+
uses: ./.github/workflows/detect-changes.yaml
61+
secrets: inherit
62+
5663
git-secrets:
5764
runs-on: ubuntu-latest
5865
timeout-minutes: 2
@@ -88,6 +95,8 @@ jobs:
8895
uses: "WyriHaximus/github-action-get-previous-tag@04e8485ecb6487243907e330d522ff60f02283ce" # v1.4.0
8996

9097
gen-code-no-diff:
98+
needs: [changes]
99+
if: ${{ needs.changes.outputs.code == 'true' }}
91100
strategy:
92101
matrix:
93102
os: [macos-latest, windows-latest, ubuntu-latest]
@@ -103,6 +112,8 @@ jobs:
103112
- run: git diff --exit-code
104113

105114
unit-tests:
115+
needs: [changes]
116+
if: ${{ needs.changes.outputs.code == 'true' }}
106117
strategy:
107118
fail-fast: false
108119
matrix:
@@ -123,6 +134,8 @@ jobs:
123134

124135
# It's recommended to run golangci-lint in a job separate from other jobs (go test, etc) because different jobs run in parallel.
125136
go-linter:
137+
needs: [changes]
138+
if: ${{ needs.changes.outputs.code == 'true' }}
126139
name: lint
127140
runs-on: ubuntu-latest
128141
timeout-minutes: 5
@@ -168,6 +181,8 @@ jobs:
168181
continue-on-error: true
169182

170183
go-mod-tidy-check:
184+
needs: [changes]
185+
if: ${{ needs.changes.outputs.code == 'true' }}
171186
runs-on: ubuntu-latest
172187
timeout-minutes: 1
173188
steps:
@@ -179,6 +194,8 @@ jobs:
179194
- run: go mod tidy -diff
180195

181196
check-licenses:
197+
needs: [changes]
198+
if: ${{ needs.changes.outputs.code == 'true' || needs.changes.outputs.deps == 'true' }}
182199
runs-on: ubuntu-latest
183200
timeout-minutes: 1
184201
steps:
@@ -190,6 +207,8 @@ jobs:
190207
- run: make check-licenses
191208

192209
macos-e2e-tests:
210+
needs: [changes]
211+
if: ${{ needs.changes.outputs.mac-e2e == 'true' }}
193212
strategy:
194213
fail-fast: false
195214
matrix:
@@ -206,6 +225,8 @@ jobs:
206225
test-command: ${{ matrix.test-command }}
207226

208227
windows-e2e-tests:
228+
needs: [changes]
229+
if: ${{ needs.changes.outputs.win-e2e == 'true' }}
209230
strategy:
210231
fail-fast: false
211232
matrix:
@@ -220,6 +241,8 @@ jobs:
220241
test-command: ${{ matrix.test-command }}
221242

222243
linux-e2e-tests:
244+
needs: [changes]
245+
if: ${{ needs.changes.outputs.linux-e2e == 'true' }}
223246
strategy:
224247
fail-fast: false
225248
matrix:
@@ -236,6 +259,8 @@ jobs:
236259
runner-type: ${{ matrix.runner-type }}
237260

238261
ubuntu-e2e-tests:
262+
needs: [changes]
263+
if: ${{ needs.changes.outputs.ubuntu-e2e == 'true' }}
239264
strategy:
240265
fail-fast: false
241266
matrix:
@@ -252,6 +277,8 @@ jobs:
252277
output-arch: ${{ matrix.output-arch }}
253278

254279
mdlint:
280+
needs: [changes]
281+
if: ${{ needs.changes.outputs.docs == 'true' }}
255282
runs-on: ubuntu-latest
256283
timeout-minutes: 5
257284
steps:
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
name: Detect Changes
2+
on:
3+
workflow_call:
4+
inputs:
5+
ref_name:
6+
description: "The ref name. Defaults to github.head_ref if present, otherwise github.ref_name"
7+
required: false
8+
type: string
9+
outputs:
10+
code:
11+
value: ${{ jobs.changes.outputs.code }}
12+
docs:
13+
value: ${{ jobs.changes.outputs.docs }}
14+
deps:
15+
value: ${{ jobs.changes.outputs.deps }}
16+
mac-build:
17+
value: ${{ jobs.changes.outputs.mac-build }}
18+
mac-e2e:
19+
value: ${{ jobs.changes.outputs.mac-e2e }}
20+
win-build:
21+
value: ${{ jobs.changes.outputs.win-build }}
22+
win-e2e:
23+
value: ${{ jobs.changes.outputs.win-e2e }}
24+
ubuntu-build:
25+
value: ${{ jobs.changes.outputs.ubuntu-build }}
26+
ubuntu-e2e:
27+
value: ${{ jobs.changes.outputs.ubuntu-e2e }}
28+
linux-build:
29+
value: ${{ jobs.changes.outputs.linux-build }}
30+
linux-e2e:
31+
value: ${{ jobs.changes.outputs.linux-e2e }}
32+
33+
permissions:
34+
contents: read
35+
pull-requests: read
36+
37+
jobs:
38+
changes:
39+
runs-on: ubuntu-latest
40+
outputs:
41+
code: ${{ steps.filter.outputs.code }}
42+
docs: ${{ steps.filter.outputs.docs }}
43+
deps: ${{ steps.filter.outputs.deps }}
44+
mac-build: ${{ steps.filter.outputs.mac-build }}
45+
mac-e2e: ${{ steps.filter.outputs.mac-e2e }}
46+
win-build: ${{ steps.filter.outputs.win-build }}
47+
win-e2e: ${{ steps.filter.outputs.win-e2e }}
48+
ubuntu-build: ${{ steps.filter.outputs.ubuntu-build }}
49+
ubuntu-e2e: ${{ steps.filter.outputs.ubuntu-e2e }}
50+
linux-build: ${{ steps.filter.outputs.linux-build }}
51+
linux-e2e: ${{ steps.filter.outputs.linux-e2e }}
52+
steps:
53+
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
54+
with:
55+
ref: ${{ inputs.ref_name || github.head_ref || github.ref_name }}
56+
- uses: dorny/paths-filter@v3
57+
id: filter
58+
with:
59+
# predicate-quantifier: 'every'
60+
list-files: 'csv'
61+
filters: |
62+
code: &code
63+
- '**.go'
64+
- 'go.mod'
65+
- 'go.sum'
66+
- 'Makefile*'
67+
- 'finch.yaml.d/**'
68+
docs:
69+
- '**/*.md'
70+
deps: &deps
71+
- 'deps/**'
72+
mac-build:
73+
- *code
74+
- *deps
75+
- 'installer-builder/**'
76+
- '.github/workflows/build-and-test-pkg.yaml'
77+
- '.github/workflows/build-pkg.yaml'
78+
- '.github/workflows/test-pkg.yaml'
79+
- '.github/workflows/upload-installer-to-release.yaml'
80+
mac-e2e:
81+
- *code
82+
- *deps
83+
- '.github/workflows/e2e-macos.yaml'
84+
win-build:
85+
- *code
86+
- *deps
87+
- '.github/workflows/build-and-test-msi.yaml'
88+
- '.github/workflows/upload-msi-to-release.yaml'
89+
- 'winres/**'
90+
win-e2e:
91+
- *code
92+
- *deps
93+
- '.github/workflows/e2e-windows.yaml'
94+
ubuntu-build:
95+
- *code
96+
- *deps
97+
- 'contrib/packaging/deb/**'
98+
- '.github/workflows/build-and-test-deb.yaml'
99+
- '.github/workflows/upload-deb-to-release.yaml'
100+
ubuntu-e2e:
101+
- *code
102+
- *deps
103+
- 'contrib/packaging/deb/**'
104+
- '.github/workflows/e2e-ubuntu.yaml'
105+
linux-build: &linux-build
106+
- *code
107+
- *deps
108+
- 'contrib/packaging/rpm/**'
109+
linux-e2e:
110+
- *linux-build
111+
- '.github/workflows/e2e-linux.yaml'

0 commit comments

Comments
 (0)