forked from capactio/capact
-
Notifications
You must be signed in to change notification settings - Fork 0
517 lines (490 loc) · 15.9 KB
/
pr-build.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
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
name: PR build
on:
pull_request_target:
types: [ opened, synchronize, reopened ]
paths:
- "**.go"
- "**.py"
- "go.mod"
- "go.sum"
- "**.graphql"
- ".github/workflows/**"
- "**.sh"
- "Makefile"
- "deploy/**"
- "hub-js/**"
- "Dockerfile"
- "!**.md"
- ".goreleaser.latest.yml"
- "**.yaml.tmpl"
branches:
- "main"
jobs:
cancel-previous-workflows:
name: Cancel previous workflows
runs-on: ubuntu-latest
if: github.event.pull_request.draft == false
# https://github.com/styfle/cancel-workflow-action#advanced-token-permissions
permissions:
actions: write
steps:
- name: Cancel Previous Runs
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}
entry-tests:
name: Lint and test code
runs-on: ubuntu-latest
if: github.event.pull_request.draft == false
permissions:
contents: read
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Setup environment
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
. ./hack/ci/setup-env.sh
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: ${{env.GO_VERSION}}
- name: Run linting
run: |
make test-lint
env:
SKIP_GOLANGCI_LINT: true
- name: Run unit tests
run: make test-unit
- name: Check generated files
run: |
make test-generated
golangci-lint:
name: Lint Go code
runs-on: ubuntu-latest
if: github.event.pull_request.draft == false
permissions:
contents: read
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Setup environment
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
. ./hack/ci/setup-env.sh
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: ${{env.GO_VERSION}}
- name: Run golangci-lint
uses: golangci/[email protected]
with:
version: ${{env.GOLANGCI_LINT_VERSION}}
args: --timeout=${{env.GOLANGCI_LINT_TIMEOUT}}
python-tests:
name: Lint and test python code
runs-on: ubuntu-latest
if: github.event.pull_request.draft == false
permissions:
contents: read
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Set up Python 3.x
uses: actions/setup-python@v2
with:
# Semantic version range syntax or exact version of a Python version
python-version: '3.x'
# Optional - x64 or x86 architecture, defaults to x64
architecture: 'x64'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install hack/images/jinja2/jinja2-cli
- name: Lint with flake8
run: |
pip install flake8
flake8 . --count --exit-zero --max-line-length=127 --statistics
continue-on-error: true
- name: Test with pytest
run: |
pip install pytest
pytest .
documentation-sanity:
name: Check documentation
runs-on: ubuntu-latest
if: github.event.pull_request.draft == false
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Run LanguageTool
uses: reviewdog/action-languagetool@v1
with:
github_token: ${{ secrets.github_token }}
reporter: github-pr-review
level: info
custom_api_endpoint: ''
### Flags for LanguageTool ###
# Ref: https://languagetool.org/http-api/swagger-ui/#!/default/post_check
language: 'en-US'
enabled_rules: ''
disabled_rules: 'WHITESPACE_RULE,EN_QUOTES,DASH_RULE,WORD_CONTAINS_UNDERSCORE,UPPERCASE_SENTENCE_START,ARROWS,COMMA_PARENTHESIS_WHITESPACE,UNLIKELY_OPENING_PUNCTUATION,SENTENCE_WHITESPACE,CURRENCY,EN_UNPAIRED_BRACKETS,PHRASE_REPETITION,PUNCTUATION_PARAGRAPH_END,METRIC_UNITS_EN_US,ENGLISH_WORD_REPEAT_BEGINNING_RULE,DOUBLE_PUNCTUATION'
enabled_categories: ''
disabled_categories: 'TYPOS,TYPOGRAPHY,CASING'
enabled_only: 'false'
- name: Run misspell check
uses: reviewdog/action-misspell@v1
with:
github_token: ${{ secrets.github_token }}
reporter: github-pr-review
level: info
locale: "US"
exclude: |
./hub-js/package-lock.json
./hub-js/package.json
./go.mod
./go.sum
- name: Check links in *.md files
if: always() # validate also *.md even if errors found in mdx files.
uses: gaurav-nelson/github-action-markdown-link-check@v1
with:
use-quiet-mode: 'yes'
file-extension: '.md'
check-modified-files-only: 'yes'
config-file: '.mlc.config.json'
folder-path: '.'
base-branch: 'main'
prepare-matrix:
name: Prepare components build matrix
runs-on: ubuntu-latest
if: github.event.pull_request.draft == false
outputs:
matrix-app: ${{ steps.set-matrix-app.outputs.matrix }}
matrix-test: ${{ steps.set-matrix-test.outputs.matrix }}
matrix-infra: ${{ steps.set-matrix-infra.outputs.matrix }}
matrix-tool: ${{ steps.set-matrix-tool.outputs.matrix }}
permissions:
contents: read
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: setup env
run: . ./hack/ci/setup-env.sh
- id: set-matrix-app
run: echo "::set-output ${APPS}"
- id: set-matrix-test
run: echo "::set-output ${TESTS}"
- id: set-matrix-infra
run: echo "::set-output ${INFRAS}"
- id: set-matrix-tool
run: echo "::set-output ${TOOLS}"
build-apps:
name: Build ${{ matrix.APP }}
runs-on: ubuntu-latest
if: github.event.pull_request.draft == false
needs: prepare-matrix
strategy:
matrix: ${{fromJson(needs.prepare-matrix.outputs.matrix-app)}}
permissions:
contents: read
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Setup environment
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
. ./hack/ci/setup-env.sh
- run: |
make build-app-image-${{ matrix.APP }}
make save-app-image-${{ matrix.APP }}
- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: ${{ matrix.APP }}-${{github.sha}}
path: /tmp/${{ matrix.APP }}.tar
retention-days: 1
push-apps:
name: Push ${{ matrix.APP }}
runs-on: ubuntu-latest
if: github.event.pull_request.draft == false
needs: [prepare-matrix, build-apps]
strategy:
matrix: ${{fromJson(needs.prepare-matrix.outputs.matrix-app)}}
permissions:
contents: read
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
persist-credentials: false
- name: Download artifact
uses: actions/download-artifact@v2
with:
name: ${{ matrix.APP }}-${{github.sha}}
path: /tmp
- name: Load image
run: docker load --input /tmp/${{ matrix.APP }}.tar
- name: Log into registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Setup environment
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
. ./hack/ci/setup-env.sh
- run: make push-app-image-${{ matrix.APP }}
- name: Delete Docker image artifact
uses: geekyeggo/delete-artifact@v1
with:
name: ${{ matrix.APP }}-${{github.sha}}
build-tests:
name: Build ${{ matrix.TEST }}
runs-on: ubuntu-latest
if: github.event.pull_request.draft == false
needs: prepare-matrix
strategy:
matrix: ${{fromJson(needs.prepare-matrix.outputs.matrix-test)}}
permissions:
contents: read
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Setup environment
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
. ./hack/ci/setup-env.sh
- run: |
make build-test-image-${{ matrix.TEST }}
make save-test-image-${{ matrix.TEST }}
- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: test-${{ matrix.TEST }}-${{github.sha}}
path: /tmp/${{ matrix.TEST }}-test.tar
retention-days: 1
push-tests:
name: Push ${{ matrix.TEST }}
runs-on: ubuntu-latest
if: github.event.pull_request.draft == false
needs: [prepare-matrix, build-tests]
strategy:
matrix: ${{fromJson(needs.prepare-matrix.outputs.matrix-test)}}
permissions:
contents: read
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
persist-credentials: false
- name: Download artifact
uses: actions/download-artifact@v2
with:
name: test-${{ matrix.TEST }}-${{github.sha}}
path: /tmp
- name: Load image
run: docker load --input /tmp/${{ matrix.TEST }}-test.tar
- name: Log into registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Setup environment
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
. ./hack/ci/setup-env.sh
- run: make push-test-image-${{ matrix.TEST }}
- name: Delete Docker image artifact
uses: geekyeggo/delete-artifact@v1
with:
name: test-${{ matrix.TEST }}-${{github.sha}}
build-infra:
name: Build ${{ matrix.INFRA }}
runs-on: ubuntu-latest
if: ${{ needs.prepare-matrix.outputs.matrix-infra != '' && github.event.pull_request.draft == false }}
needs: prepare-matrix
strategy:
matrix: ${{fromJson(needs.prepare-matrix.outputs.matrix-infra)}}
permissions:
contents: read
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Setup environment
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
. ./hack/ci/setup-env.sh
- run: |
make build-infra-image-${{ matrix.INFRA }}
make save-infra-image-${{ matrix.INFRA }}
- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: infra-${{ matrix.INFRA }}-${{github.sha}}
path: /tmp/infra-${{ matrix.INFRA }}.tar
retention-days: 1
push-infra:
name: Push ${{ matrix.INFRA }}
runs-on: ubuntu-latest
if: github.event.pull_request.draft == false
needs: [prepare-matrix, build-infra]
strategy:
matrix: ${{fromJson(needs.prepare-matrix.outputs.matrix-infra)}}
permissions:
contents: read
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
persist-credentials: false
- name: Download artifact
uses: actions/download-artifact@v2
with:
name: infra-${{ matrix.INFRA }}-${{github.sha}}
path: /tmp
- name: Load image
run: docker load --input /tmp/infra-${{ matrix.INFRA }}.tar
- name: Log into registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Setup environment
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
. ./hack/ci/setup-env.sh
- run: make push-infra-image-${{ matrix.INFRA }}
- name: Delete Docker image artifact
uses: geekyeggo/delete-artifact@v1
with:
name: infra-${{ matrix.INFRA }}-${{github.sha}}
build-cli:
name: Build Capact CLI
runs-on: ubuntu-latest
if: github.event.pull_request.draft == false
permissions:
contents: read
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Setup environment
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
. ./hack/ci/setup-env.sh
# Go is available by default but the expected version may differ, better to "hardcode" version
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: ${{env.GO_VERSION}}
- name: Set up GoReleaser
run: go install github.com/goreleaser/[email protected]
- run: make build-tool-cli
- name: Share Capact CLI for integration tests bootstrapping
uses: actions/upload-artifact@v2
with:
name: cli_${{github.sha}}
path: ${{ github.workspace }}/bin/capact_linux_amd64/capact
retention-days: 1 # Default 90 days
local-hub-tests:
name: Local Hub integration tests
runs-on: ubuntu-latest
if: github.event.pull_request.draft == false
needs: [ push-apps, push-tests, build-cli ]
permissions:
contents: read
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Setup environment
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
. ./hack/ci/setup-env.sh
- name: Run local Hub integration tests
env:
BUILD_IMAGES: "false"
run: |
make test-local-hub
integration-tests:
name: Integration tests
runs-on: ubuntu-latest
if: github.event.pull_request.draft == false
needs: [ push-apps, push-tests, build-cli ]
strategy:
matrix:
cluster: [ kind, k3d ]
permissions:
contents: read
env:
CAPACT_BINARY: "${{ github.workspace}}/capact"
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Setup environment
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
. ./hack/ci/setup-env.sh
- name: Download Capact CLI
uses: actions/download-artifact@v2
with:
name: cli_${{github.sha}}
path: ${{ github.workspace }}
- name: Setup Capact CLI
run: |
chmod +x $CAPACT_BINARY
$CAPACT_BINARY version
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: ${{env.GO_VERSION}}
- name: Run K8s Controller integration tests
run: |
make test-k8s-controller
- name: Run cross-functional integration tests
env:
BUILD_IMAGES: "false"
ARTIFACTS: "output/"
DISABLE_MONITORING_INSTALLATION: "true"
CLUSTER_TYPE: ${{ matrix.cluster }}
DISABLE_K3D_REGISTRY: "true"
run: |
make test-integration
- name: Upload artifacts
uses: actions/upload-artifact@v2
if: ${{ always() }}
with:
name: cluster_dump_${{github.sha}}
path: "output"
retention-days: 5 # Default 90 days
- name: Delete Capact CLI artifact
uses: geekyeggo/delete-artifact@v1
with:
name: cli_${{github.sha}}