1+ name : ci
2+
3+ on : [pull_request] # yamllint disable-line rule:truthy
4+
5+ concurrency :
6+ group : ${{ github.workflow }}-${{ github.event.pull-request.number || github.ref }}
7+ cancel-in-progress : true
8+
9+ defaults :
10+ run :
11+ shell : bash
12+
13+ permissions :
14+ contents : read
15+
16+ jobs :
17+ changes :
18+ name : categorize changes
19+ runs-on : ubuntu-latest
20+ outputs :
21+ non-docs : ${{ steps.detect.outputs.non-docs }}
22+ yaml : ${{ steps.detect.outputs.yaml }}
23+ steps :
24+ - name : Get base depth
25+ id : base-depth
26+ env :
27+ PR_COMMITS : ${{ github.event.pull_request.commits }}
28+ run : echo "base-depth=$(expr "${PR_COMMITS}" + 1)" >> $GITHUB_OUTPUT
29+ - uses : actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
30+ with :
31+ ref : ${{ github.event.pull_request.head.sha }}
32+ fetch-depth : ${{ steps.base-depth.outputs.base-depth }}
33+ persist-credentials : false
34+ - name : detect
35+ id : detect
36+ env :
37+ GITHUB_BASE_REF_NAME : ${{ github.base_ref }}
38+ BASE_SHA : ${{ github.event.pull_request.base.sha }}
39+ HEAD_SHA : ${{ github.event.pull_request.head.sha }}
40+ run : |
41+ git fetch origin "${GITHUB_BASE_REF_NAME}"
42+ CHANGED_FILES=$(git diff --name-only "${BASE_SHA}...${HEAD_SHA}" | tr ' ' '\n')
43+
44+ echo -e "Changed files:\n${CHANGED_FILES}"
45+
46+ if [[ -n "${CHANGED_FILES}" ]]; then
47+ NON_DOCS='false'
48+ YAML='false'
49+
50+ while read -r file; do
51+ if [[ "$file" != *.md ]]; then
52+ NON_DOCS='true'
53+ break
54+ fi
55+ done <<< "${CHANGED_FILES}"
56+
57+ while read -r file; do
58+ if [[ "$file" == *.yaml || "$file" == *.yml ]]; then
59+ YAML='true'
60+ break
61+ fi
62+ done <<< "${CHANGED_FILES}"
63+
64+ echo "non-docs=${NON_DOCS}" | tee -a $GITHUB_OUTPUT
65+ echo "yaml=${YAML}" | tee -a $GITHUB_OUTPUT
66+ fi
67+
68+ build :
69+ name : build
70+ runs-on : ubuntu-latest
71+ needs : [changes]
72+ if : ${{ needs.changes.outputs.non-docs == 'true' }}
73+ steps :
74+ - uses : actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
75+ with :
76+ persist-credentials : false
77+ - uses : actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
78+ with :
79+ go-version-file : " go.mod"
80+ - name : build
81+ run : |
82+ go build -v ./...
83+ linting :
84+ name : lint
85+ runs-on : ubuntu-latest
86+ needs : [changes]
87+ permissions :
88+ contents : read
89+ checks : write # Used by golangci-lint-action to annotate code in the PR
90+ steps :
91+ - uses : actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
92+ with :
93+ fetch-depth : 0
94+ persist-credentials : false
95+ - uses : actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
96+ with :
97+ go-version-file : " go.mod"
98+ - name : gofmt
99+ if : ${{ needs.changes.outputs.non-docs == 'true' }}
100+ run : |
101+ gofmt_out=$(gofmt -d $(find * -name '*.go' ! -path 'vendor/*' ! -path 'third_party/*'))
102+ if [[ -n "$gofmt_out" ]]; then
103+ failed=1
104+ fi
105+ echo "$gofmt_out"
106+ - name : golangci-lint
107+ uses : golangci/golangci-lint-action@1e7e51e771db61008b38414a730f564565cf7c20 # v9.2.0
108+ if : ${{ needs.changes.outputs.non-docs == 'true' }}
109+ with :
110+ version : v2.8.0
111+ args : --new-from-merge-base=origin/${{ github.base_ref }} --timeout=10m
112+ - name : yamllint
113+ if : ${{ needs.changes.outputs.yaml == 'true' }}
114+ run : |
115+ sudo apt-get update && sudo apt-get install -y yamllint
116+ make yamllint
117+ - name : check-license
118+ if : ${{ needs.changes.outputs.non-docs == 'true' }}
119+ run : |
120+ go install github.com/google/go-licenses@v1.0.0
121+ go-licenses check ./...
122+ tests :
123+ needs : [build]
124+ name : test
125+ runs-on : ubuntu-latest
126+ steps :
127+ - uses : actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
128+ with :
129+ persist-credentials : false
130+ - uses : actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
131+ with :
132+ go-version-file : " go.mod"
133+ - name : unit-test
134+ run : |
135+ make test-unit-verbose-and-race
136+ generated :
137+ needs : [build]
138+ name : Check generated code
139+ runs-on : ubuntu-latest
140+ steps :
141+ - uses : actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
142+ with :
143+ persist-credentials : false
144+ - uses : actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
145+ with :
146+ go-version-file : " go.mod"
147+ - name : generated
148+ run : |
149+ ./hack/verify-codegen.sh
150+ multi-arch-build :
151+ needs : [build]
152+ name : Multi-arch build
153+ runs-on : ubuntu-latest
154+ env :
155+ KOCACHE : /tmp/ko-cache
156+ steps :
157+ - uses : actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
158+ with :
159+ persist-credentials : false
160+ - uses : actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
161+ with :
162+ go-version-file : " go.mod"
163+ - name : Cache ko build cache
164+ uses : actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
165+ with :
166+ path : /tmp/ko-cache
167+ key : ${{ runner.os }}-${{ runner.arch }}-ko-${{ hashFiles('go.sum') }}
168+ restore-keys : |
169+ ${{ runner.os }}-${{ runner.arch }}-ko-
170+ - uses : ko-build/setup-ko@d006021bd0c28d1ce33a07e7943d48b079944c8d # v0.9
171+ - name : ko-resolve
172+ run : |
173+ KO_DOCKER_REPO=example.com ko resolve --platform=all --push=false -R -f config 1>/dev/null
174+ KO_DOCKER_REPO=example.com ko resolve --platform=all --push=false -f config/interceptors 1>/dev/null
175+ e2e-tests :
176+ needs : [build]
177+ uses : ./.github/workflows/e2e-matrix.yml
178+
179+ ci-summary :
180+ name : CI summary
181+ needs : [build, linting, tests, generated, multi-arch-build, e2e-tests]
182+ runs-on : ubuntu-latest
183+ if : always()
184+ steps :
185+ - name : Check CI results
186+ env :
187+ BUILD : ${{ needs.build.result }}
188+ LINTING : ${{ needs.linting.result }}
189+ TESTS : ${{ needs.tests.result }}
190+ GENERATED : ${{ needs.generated.result }}
191+ MULTI_ARCH_BUILD : ${{ needs.multi-arch-build.result }}
192+ E2E_TESTS : ${{ needs.e2e-tests.result }}
193+ run : |
194+ results=(
195+ "build=${BUILD}"
196+ "linting=${LINTING}"
197+ "tests=${TESTS}"
198+ "generated=${GENERATED}"
199+ "multi-arch-build=${MULTI_ARCH_BUILD}"
200+ "e2e-tests=${E2E_TESTS}"
201+ )
202+ failed=0
203+ for r in "${results[@]}"; do
204+ name="${r%%=*}"
205+ result="${r#*=}"
206+ echo "${name}: ${result}"
207+ if [ "$result" != "success" ] && [ "$result" != "skipped" ]; then
208+ failed=1
209+ fi
210+ done
211+ if [ "$failed" -eq 1 ]; then
212+ echo ""
213+ echo "Some CI jobs failed or were cancelled"
214+ exit 1
215+ fi
216+ echo ""
217+ echo "All CI checks passed"
0 commit comments