-
Notifications
You must be signed in to change notification settings - Fork 337
366 lines (363 loc) · 14.2 KB
/
build-test-distribute.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
name: "build-test-distribute"
on:
push:
branches: ["master", "release-*", "!*-merge-master"]
tags: ["*"]
pull_request:
branches: ["master", "release-*"]
concurrency:
group: ${{ github.head_ref || github.run_id }}
cancel-in-progress: true
env:
# This is automatically managed by CI
K8S_MIN_VERSION: v1.23.17-k3s1
K8S_MAX_VERSION: v1.28.1-k3s1
GH_OWNER: ${{ github.repository_owner }}
KUMA_DIR: "."
CI_TOOLS_DIR: /home/runner/work/kuma/kuma/.ci_tools
jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: "Check if should run on all arch/os combinations"
if: github.event_name == 'push' || contains(github.event.pull_request.labels.*.name, 'ci/run-full-matrix')
run: |
echo 'RUN_FULL_MATRIX=true' > .run-full-matrix
echo 'RUN_FULL_MATRIX=true' >> $GITHUB_ENV
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache-dependency-path: |
.run-full-matrix
go.sum
- uses: actions/cache@v3
with:
path: |
${{ env.CI_TOOLS_DIR }}
key: ${{ runner.os }}-${{ runner.arch }}-devtools-${{ hashFiles('mk/dependencies/deps.lock') }}
restore-keys: |
${{ runner.os }}-${{ runner.arch }}-devtools
- run: |
make dev/tools
- run: |
make clean
- run: |
make check
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: "Check if should run on all arch/os combinations"
if: github.event_name == 'push' || contains(github.event.pull_request.labels.*.name, 'ci/run-full-matrix')
run: |
echo 'RUN_FULL_MATRIX=true' > .run-full-matrix
echo 'RUN_FULL_MATRIX=true' >> $GITHUB_ENV
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache-dependency-path: |
.run-full-matrix
go.sum
- uses: actions/cache@v3
with:
path: |
${{ env.CI_TOOLS_DIR }}
key: ${{ runner.os }}-${{ runner.arch }}-devtools-${{ hashFiles('mk/dependencies/deps.lock') }}
restore-keys: |
${{ runner.os }}-${{ runner.arch }}-devtools
- run: |
make dev/tools
- name: Free up disk space for the Runner
run: |
echo "Disk usage before cleanup"
sudo df -h
echo "Removing big directories"
sudo rm -rf /usr/share/dotnet /usr/local/lib/android /opt/ghc
echo "Removing images"
docker system prune --all -f
echo "Disk usage after cleanup"
sudo df -h
- name: "Set switches based on if run full matrix"
if: ${{ env.RUN_FULL_MATRIX == 'true' }}
id: set-full-matrix-switches
run: |
echo 'ENABLED_GOARCHES=arm64 amd64' >> $GITHUB_ENV
echo 'ENABLED_GOOSES=linux darwin' >> $GITHUB_ENV
- run: |
make build
- run: |
make -j build/distributions
- name: Install dependencies for cross builds
run: |
sudo apt-get update; sudo apt-get install -y qemu-user-static binfmt-support
- run: |
make -j images
- run: |
make -j docker/save
- name: Cleanup redundant build outputs
run: |
find ./build/artifacts-* -maxdepth 0 -type d | xargs -I % rm -rf %
find ./build/distributions/* -maxdepth 0 -type d | grep -v '/out' | xargs -I % rm -rf %
find ./build/tools-* -maxdepth 0 -type d | xargs -I % rm -rf %
rm -rf ./build/oapitmp
rm -rf ./build/ebpf/
- name: Upload build output
uses: actions/upload-artifact@v4
with:
name: build-output
path: build
retention-days: 1
- name: Run container structure test
if: ${{ !contains(github.event.pull_request.labels.*.name, 'ci/skip-container-structure-test') && !contains(github.event.pull_request.labels.*.name, 'ci/skip-test') }}
run: |
make test/container-structure
test:
runs-on: ubuntu-latest
if: ${{ ! contains(github.event.pull_request.labels.*.name, 'ci/skip-test') }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: "Check if should run on all arch/os combinations"
if: github.event_name == 'push' || contains(github.event.pull_request.labels.*.name, 'ci/run-full-matrix')
run: |
echo 'RUN_FULL_MATRIX=true' > .run-full-matrix
echo 'RUN_FULL_MATRIX=true' >> $GITHUB_ENV
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache-dependency-path: |
.run-full-matrix
go.sum
- uses: actions/cache@v3
with:
path: |
${{ env.CI_TOOLS_DIR }}
key: ${{ runner.os }}-${{ runner.arch }}-devtools-${{ hashFiles('mk/dependencies/deps.lock') }}
restore-keys: |
${{ runner.os }}-${{ runner.arch }}-devtools
- run: |
make dev/tools
- name: Free up disk space for the Runner
run: |
echo "Disk usage before cleanup"
sudo df -h
echo "Removing big directories"
sudo rm -rf /usr/share/dotnet /usr/local/lib/android /opt/ghc
echo "Removing images"
docker system prune --all -f
echo "Disk usage after cleanup"
sudo df -h
- name: Run tests
run: |
make test TEST_REPORTS=1
- name: Save test reports
uses: actions/upload-artifact@v4
with:
name: test-reports
path: build/reports
retention-days: 7
distributions:
needs: ["check", "test", "test_e2e", "test_e2e_env"]
if: ${{ always() }}
runs-on: ubuntu-latest
steps:
- name: "Halt due to previous failures"
if: ${{ contains(needs.*.result, 'failure')|| contains(needs.*.result, 'cancelled') }}
run: |
exit 1
# for some reason, GH Action will always trigger a downstream job even if there are errors in an dependent job
# so we manually check it here. An example could be found here: https://github.com/kumahq/kuma/actions/runs/7044980149
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: "Check if should run on all arch/os combinations"
if: github.event_name == 'push' || contains(github.event.pull_request.labels.*.name, 'ci/run-full-matrix')
run: |
echo 'RUN_FULL_MATRIX=true' > .run-full-matrix
echo 'RUN_FULL_MATRIX=true' >> $GITHUB_ENV
- name: "Set switches based on if run full matrix"
if: ${{ env.RUN_FULL_MATRIX == 'true' }}
id: set-full-matrix-switches
run: |
echo 'ENABLED_GOARCHES=arm64 amd64' >> $GITHUB_ENV
echo 'ENABLED_GOOSES=linux darwin' >> $GITHUB_ENV
- name: "Check if force push"
if: github.event_name == 'push' || contains(github.event.pull_request.labels.*.name, 'ci/force-publish')
run: |
echo 'ALLOW_PUSH=true' >> $GITHUB_ENV
- name: Install dependencies for cross builds
run: |
sudo apt-get update; sudo apt-get install -y qemu-user-static binfmt-support
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache-dependency-path: |
.run-full-matrix
go.sum
- uses: actions/cache@v3
with:
path: |
${{ env.CI_TOOLS_DIR }}
key: ${{ runner.os }}-${{ runner.arch }}-devtools-${{ hashFiles('mk/dependencies/deps.lock') }}
restore-keys: |
${{ runner.os }}-${{ runner.arch }}-devtools
# FIXME: Workaround for Request Timeout issue of artifacts https://github.com/actions/download-artifact/issues/249
- name: Download artifacts with retry
uses: Wandalen/wretry.action@master
with:
action: actions/download-artifact@v4
with: |
path: build
name: build-output
attempt_limit: 5
attempt_delay: 1000
- name: Inspect created tars
run: |
for i in build/distributions/out/*.tar.gz; do echo $i; tar -tvf $i; done
- name: Publish distributions to Pulp
env:
PULP_USERNAME: ${{ vars.PULP_USERNAME }}
PULP_PASSWORD: ${{ secrets.PULP_PASSWORD }}
CLOUDSMITH_API_KEY: ${{ secrets.CLOUDSMITH_API_KEY }}
run: |
make publish/pulp
- name: Load images
run: |
make docker/load
- name: Publish images
env:
DOCKER_API_KEY: ${{ secrets.DOCKER_API_KEY }}
DOCKER_USERNAME: ${{ vars.DOCKER_USERNAME }}
run: |-
make docker/login
# ensure we always logout
function on_exit() {
make docker/logout
}
trap on_exit EXIT
make docker/push
make docker/manifest
- name: package-helm-chart
id: package-helm
env:
HELM_DEV: ${{ !startsWith(github.event.ref, 'refs/tags/') }}
GH_USER: "github-actions[bot]"
GH_EMAIL: "<41898282+github-actions[bot]@users.noreply.github.com>"
run: |
make helm/update-version
git config user.name "${GH_USER}"
git config user.email "${GH_EMAIL}"
git add -u deployments/charts
# This commit never ends up in the repo
git commit --allow-empty -m "ci(helm): update versions"
# To get an idea of what's in the commit to debug
git show
make helm/package
PKG_FILENAME=$(find .cr-release-packages -type f -printf "%f\n")
echo "filename=${PKG_FILENAME}" >> $GITHUB_OUTPUT
- name: Upload packaged chart
uses: actions/upload-artifact@v4
with:
name: ${{ steps.package-helm.outputs.filename }}
path: .cr-release-packages/${{ steps.package-helm.outputs.filename }}
retention-days: ${{ github.event_name == 'pull_request' && 1 || 30 }}
# Everything from here is only running on releases.
# Ideally we'd finish the workflow early but this isn't possible: https://github.com/actions/runner/issues/662
- name: Generate GitHub app token
id: github-app-token
if: ${{ startsWith(github.event.ref, 'refs/tags/') }}
uses: tibdex/github-app-token@3beb63f4bd073e61482598c45c71c1019b59b73a # v2.1.0
with:
app_id: ${{ secrets.APP_ID }}
private_key: ${{ secrets.APP_PRIVATE_KEY }}
- name: Release chart
if: ${{ startsWith(github.event.ref, 'refs/tags/') }}
env:
GITHUB_APP: "true"
GH_TOKEN: ${{ steps.github-app-token.outputs.token }}
run: make helm/release
gen_e2e_matrix:
runs-on: ubuntu-latest
if: ${{ !contains(github.event.pull_request.labels.*.name, 'ci/skip-test') && !contains(github.event.pull_request.labels.*.name, 'ci/skip-e2e-test') }}
outputs:
matrix: ${{ steps.generate-matrix.outputs.matrix }}
steps:
- name: "Check if should run on all arch/os combinations"
if: github.event_name == 'push' || contains(github.event.pull_request.labels.*.name, 'ci/run-full-matrix')
run: |
echo 'RUN_FULL_MATRIX=true' > .run-full-matrix
echo 'RUN_FULL_MATRIX=true' >> $GITHUB_ENV
- id: generate-matrix
name: Generate matrix
env:
BASE_MATRIX: |-
{
"test_e2e": {
"target": [""],
"k8sVersion": ["kindIpv6", "${{ env.K8S_MIN_VERSION }}", "${{ env.K8S_MAX_VERSION }}"],
"arch": ["amd64", "arm64"],
"parallelism": [3],
"cniNetworkPlugin": ["flannel"],
"legacyKDS": [false]
},
"test_e2e_env": {
"target": ["kubernetes", "universal", "multizone"],
"k8sVersion": ["kind", "kindIpv6", "${{ env.K8S_MIN_VERSION }}", "${{ env.K8S_MAX_VERSION }}"],
"arch": ["amd64", "arm64"],
"parallelism": [1],
"cniNetworkPlugin": ["flannel"],
"legacyKDS": [false],
"exclude":[
{"target": "kubernetes", "k8sVersion":"kind"},
{"target": "multizone", "k8sVersion":"kind"},
{"arch": "arm64", "k8sVersion":"${{ env.K8S_MIN_VERSION }}"},
{"target":"universal", "k8sVersion":"${{ env.K8S_MIN_VERSION }}"},
{"target":"universal", "k8sVersion":"${{ env.K8S_MAX_VERSION }}"}
],
"include":[
{"legacyKDS": true, "k8sVersion": "${{ env.K8S_MAX_VERSION }}", "target": "multizone", "arch": "amd64"},
{"cniNetworkPlugin": "calico", "k8sVersion": "${{ env.K8S_MAX_VERSION }}", "target": "multizone", "arch": "amd64"}
]
}
}
OVERRIDE_JQ_CMD: |-
.test_e2e = false
| .test_e2e_env.include = []
| .test_e2e_env.exclude += [{"arch": "arm64"}, {"k8sVersion": "kindIpv6"}, {"k8sVersion": "${{ env.K8S_MIN_VERSION}}"}]
run: |-
BASE_MATRIX_ALL='${{ env.BASE_MATRIX }}'
if [[ "${RUN_FULL_MATRIX}" != "true" ]]; then
BASE_MATRIX_ALL=$(echo $BASE_MATRIX_ALL | jq -r '${{ env.OVERRIDE_JQ_CMD }}')
fi
echo "final matrix: $BASE_MATRIX_ALL"
echo "matrix<<EOF" >> $GITHUB_OUTPUT
echo "$BASE_MATRIX_ALL" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
test_e2e:
needs: ["gen_e2e_matrix", "build"]
if: fromJSON(needs.gen_e2e_matrix.outputs.matrix).test_e2e
strategy:
matrix: ${{ fromJSON(needs.gen_e2e_matrix.outputs.matrix).test_e2e }}
fail-fast: false
uses: ./.github/workflows/e2e.yaml
with:
matrix: ${{ toJSON(matrix) }}
secrets:
circleCIToken: ${{ secrets.CIRCLECI_TOKEN }}
test_e2e_env:
needs: ["gen_e2e_matrix", "build"]
if: fromJSON(needs.gen_e2e_matrix.outputs.matrix).test_e2e_env
strategy:
matrix: ${{ fromJSON(needs.gen_e2e_matrix.outputs.matrix).test_e2e_env }}
fail-fast: false
uses: ./.github/workflows/e2e.yaml
with:
matrix: ${{ toJSON(matrix) }}
secrets:
circleCIToken: ${{ secrets.CIRCLECI_TOKEN }}