@@ -2,145 +2,161 @@ name: build-test
22
33on :
44 pull_request :
5- types :
6- - opened
7- - reopened
8- - synchronize
9- - ready_for_review
10- branches :
11- - v1beta3
5+ types : [opened, reopened, synchronize, ready_for_review]
6+ branches : [v1beta3]
127 push :
13- branches :
14- - " v1beta3"
8+ branches : [v1beta3]
159
1610concurrency :
1711 group : ${{ github.workflow }}-${{ github.ref }}
1812 cancel-in-progress : true
1913
2014jobs :
21- fail_if_pull_request_is_draft :
22- if : github.event.pull_request.draft == true
15+ # Detect changes to optimize test execution
16+ changes :
2317 runs-on : ubuntu-latest
18+ outputs :
19+ go-files : ${{ steps.filter.outputs.go-files }}
20+ preflight : ${{ steps.filter.outputs.preflight }}
21+ support-bundle : ${{ steps.filter.outputs.support-bundle }}
22+ examples : ${{ steps.filter.outputs.examples }}
2423 steps :
25- - name : Fails in order to indicate that pull request needs to be marked as ready to review and unit tests workflow needs to pass.
26- run : exit 1
24+ - uses : actions/checkout@v5
25+ - uses : dorny/paths-filter@v3
26+ id : filter
27+ with :
28+ filters : |
29+ go-files:
30+ - '**/*.go'
31+ - 'go.{mod,sum}'
32+ - 'Makefile'
33+ preflight:
34+ - 'cmd/preflight/**'
35+ - 'pkg/preflight/**'
36+ support-bundle:
37+ - 'cmd/troubleshoot/**'
38+ - 'pkg/supportbundle/**'
39+ examples:
40+ - 'examples/**'
41+ - 'test/run-examples.sh'
2742
28- test-integration :
43+ # Validation jobs
44+ validate :
45+ if : needs.changes.outputs.go-files == 'true'
46+ needs : changes
2947 runs-on : ubuntu-latest
48+ timeout-minutes : 10
3049 steps :
3150 - uses : actions/checkout@v5
32- - uses : actions/setup-go@v6
33- with :
34- go-version-file : ' go. mod'
35- - uses : replicatedhq/action-k3s@main
36- id : k3s
37- with :
38- version : v1.31.2-k3s1
39- # test-integration includes unit tests
40- - run : make test-integration
51+ - uses : ./.github/ actions/setup-go
52+
53+ - name : Check go mod tidy
54+ run : |
55+ go mod tidy
56+ git diff --exit-code go.mod go.sum || {
57+ echo "::error::Please run 'go mod tidy' and commit changes"
58+ exit 1
59+ }
4160
42- compile-preflight :
61+ - name : Format and vet
62+ run : |
63+ make fmt
64+ git diff --exit-code || {
65+ echo "::error::Please run 'make fmt' and commit changes"
66+ exit 1
67+ }
68+ make vet
69+
70+ # Unit and integration tests
71+ test :
72+ if : needs.changes.outputs.go-files == 'true'
73+ needs : [changes, validate]
4374 runs-on : ubuntu-latest
75+ timeout-minutes : 20
4476 steps :
4577 - uses : actions/checkout@v5
46- - uses : actions/setup-go@v6
47- with :
48- go-version-file : ' go.mod'
49- - run : make preflight
50- - uses : actions/upload-artifact@v4
78+ - uses : ./.github/actions/setup-go
79+
80+ - name : Setup K3s
81+ uses : replicatedhq/action-k3s@main
5182 with :
52- name : preflight
53- path : bin/preflight
83+ version : v1.31.2-k3s1
84+
85+ - name : Run tests
86+ run : make test-integration
5487
55- validate-preflight-e2e :
88+ # Build binaries
89+ build :
90+ if : needs.changes.outputs.go-files == 'true'
91+ needs : [changes, validate]
5692 runs-on : ubuntu-latest
57- needs : compile-preflight
93+ timeout-minutes : 10
5894 steps :
5995 - uses : actions/checkout@v5
60- - uses : replicatedhq/action-k3s@main
61- id : k3s
62- with :
63- version : v1.31.2-k3s1
64- - name : Download preflight binary
65- uses : actions/download-artifact@v5
96+ - uses : ./.github/actions/setup-go
97+ - run : make build
98+ - uses : actions/upload-artifact@v4
6699 with :
67- name : preflight
100+ name : binaries
68101 path : bin/
69- - run : chmod +x bin/preflight
70- - run : make preflight-e2e-test
102+ retention-days : 1
71103
72- run-examples :
104+ # Examples validation
105+ examples :
106+ if : needs.changes.outputs.examples == 'true' || needs.changes.outputs.go-files == 'true'
107+ needs : changes
73108 runs-on : ubuntu-latest
109+ timeout-minutes : 10
74110 steps :
75111 - uses : actions/checkout@v5
76112 - run : make run-examples
77113
78- compile-supportbundle :
114+ # E2E tests
115+ e2e :
116+ if : needs.changes.outputs.go-files == 'true' || github.event_name == 'push'
117+ needs : [changes, build]
79118 runs-on : ubuntu-latest
119+ timeout-minutes : 15
120+ strategy :
121+ fail-fast : false
122+ matrix :
123+ include :
124+ - name : preflight
125+ target : preflight-e2e-test
126+ needs-k3s : true
127+ - name : support-bundle-shell
128+ target : support-bundle-e2e-test
129+ needs-k3s : true
130+ - name : support-bundle-go
131+ target : support-bundle-e2e-go-test
132+ needs-k3s : false
80133 steps :
81134 - uses : actions/checkout@v5
82- - uses : actions/setup-go@v6
83- with :
84- go-version-file : ' go.mod'
85- - run : make support-bundle
86- - uses : actions/upload-artifact@v4
87- with :
88- name : support-bundle
89- path : bin/support-bundle
90135
91- validate-supportbundle-e2e :
92- runs-on : ubuntu-latest
93- needs : compile-supportbundle
94- steps :
95- - uses : actions/checkout@v5
96- - uses : replicatedhq/action-k3s@main
97- id : k3s
136+ - name : Setup K3s
137+ if : matrix.needs-k3s
138+ uses : replicatedhq/action-k3s@main
98139 with :
99140 version : v1.31.2-k3s1
100- - name : Download support bundle binary
101- uses : actions/download-artifact@v5
102- with :
103- name : support-bundle
104- path : bin/
105- - run : chmod +x bin/support-bundle
106- - run : make support-bundle-e2e-test
107-
108- # Additional e2e tests for support bundle that run in Go, these create a Kind cluster
109- validate-supportbundle-e2e-go :
110- runs-on : ubuntu-latest
111- needs : compile-supportbundle
112- steps :
113- - uses : actions/checkout@v5
114- - name : Download support bundle binary
115- uses : actions/download-artifact@v5
116- with :
117- name : support-bundle
118- path : bin/
119- - run : chmod +x bin/support-bundle
120- - name : Download preflight binary
121- uses : actions/download-artifact@v5
141+
142+ - uses : actions/download-artifact@v4
122143 with :
123- name : preflight
144+ name : binaries
124145 path : bin/
125- - run : chmod +x bin/preflight
126- - run : make support-bundle-e2e-go-test
127146
128- # Summary job - all tests must pass for this to succeed
129- validate-success :
130- runs-on : ubuntu-latest
131- needs :
132- - tidy-check
133- - test-integration
134- - run-examples
135- - validate-preflight-e2e
136- - validate-supportbundle-e2e
137- - validate-supportbundle-e2e-go
147+ - run : chmod +x bin/*
148+ - run : make ${{ matrix.target }}
149+
150+ # Success summary
151+ success :
138152 if : always()
153+ needs : [validate, test, build, examples, e2e]
154+ runs-on : ubuntu-latest
139155 steps :
140- # Check if all required jobs succeeded
141- - name : fail if any required job failed
142- if : contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')
143- run : exit 1
144- # Success message
145- - name : All tests passed
146- run : echo "All build and test jobs completed successfully "
156+ - name : Check results
157+ run : |
158+ if [[ "${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }}" == "true" ]]; then
159+ echo "::error::Some jobs failed or were cancelled"
160+ exit 1
161+ fi
162+ echo "✅ All tests passed! "
0 commit comments