-
-
Notifications
You must be signed in to change notification settings - Fork 26
476 lines (408 loc) · 14.9 KB
/
lint-test-build.yml
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
name: Lint, Test & Build
on:
workflow_dispatch:
pull_request:
branches:
- main
- feature/*
push:
branches:
- main
- feature/*
concurrency:
group: lint-test-build-${{ github.ref }}
cancel-in-progress: true
jobs:
should_run:
name: Should run?
runs-on: ubuntu-latest
outputs:
should-run: "${{ (github.event_name == 'workflow_dispatch' || steps.regex-match.outputs.match != 'ci: skip') && (github.event_name != 'pull_request' || !github.event.pull_request.draft || steps.regex-match.outputs.match == 'ci: force') }}"
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Get last commit message
run: |
git log -1 --no-merges --pretty=format:"%B" -n 1 HEAD | tee commit_message.txt
COMMIT_MSG=$(cat commit_message.txt)
echo "COMMIT_MSG<<EOF" >> $GITHUB_ENV
echo "$COMMIT_MSG" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- uses: actions-ecosystem/action-regex-match@v2
id: regex-match
with:
text: ${{ env.COMMIT_MSG }}
regex: '\bci: (force|skip)\b'
approve:
name: Approve the run
runs-on: ubuntu-latest
needs: [should_run]
if: ${{ needs.should_run.outputs.should-run == 'true' }}
environment: ${{ (github.ref != 'refs/heads/main' && github.ref != 'refs/heads/feature/*' && github.event_name != 'workflow_dispatch') && 'lint-test-build' || '' }}
steps:
- name: Dummy step
run: echo "Approving the run"
lint:
name: Run Lint
runs-on: ubuntu-latest
container: ghcr.io/scuffletv/build:latest
needs: [approve]
services:
cockroach:
image: ghcr.io/scuffletv/cockroach:latest
ports:
- 26257:26257
env:
DATABASE_URL: postgres://root@cockroach:26257/scuffle
CARGO_INCREMENTAL: 1
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: pnpm/action-setup@v2
with:
version: latest
- name: Install Node
uses: actions/setup-node@v3
with:
cache: "pnpm"
node-version: 18
- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
- name: Install dependencies
run: mask bootstrap --no-db --no-docker --no-env --no-rust
- name: Run migrations
run: mask db migrate
- name: Run JS, Terraform & Proto Lint
run: mask lint --no-rust
- name: Restore cached lint build
uses: tespkg/actions-cache@v1
with:
accessKey: ${{ secrets.CI_CACHE_ACCESS_KEY_ID }}
secretKey: ${{ secrets.CI_CACHE_SECRET_ACCESS_KEY }}
bucket: ${{ secrets.CI_CACHE_BUCKET_NAME }}
endpoint: ${{ secrets.CI_CACHE_ENDPOINT }}
path: |
target/
key: lint-rust-${{ github.ref_name }}-${{ hashFiles('Cargo.lock') }}
restore-keys: |
lint-rust-${{ github.ref_name }}-
lint-rust-main-
lint-rust-
- name: Cargo Sweep Start
run: cargo sweep -s
- name: Run Rust Lint
run: mask lint --no-js --no-terraform --no-proto
- name: Cargo Sweep Finish
run: cargo sweep -f
test:
name: Run Tests
runs-on: ubuntu-latest
container: ghcr.io/scuffletv/build:latest
needs: [approve]
services:
cockroach:
image: ghcr.io/scuffletv/cockroach:latest
ports:
- 26257:26257
rmq:
image: bitnami/rabbitmq:latest
ports:
- 5672:5672
env:
RABBITMQ_USERNAME: rabbitmq
RABBITMQ_PASSWORD: rabbitmq
RABBITMQ_VHOSTS: scuffle
RABBITMQ_DISK_FREE_ABSOLUTE_LIMIT: 50MB
redis:
image: redis:latest
ports:
- 6379:6379
env:
DATABASE_URL: postgres://root@cockroach:26257/scuffle
RMQ_URL: amqp://rabbitmq:rabbitmq@rmq:5672/scuffle
REDIS_URL: redis://redis:6379
CARGO_INCREMENTAL: 1
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: pnpm/action-setup@v2
with:
version: latest
- name: Install Node
uses: actions/setup-node@v3
with:
cache: "pnpm"
node-version: 18
- name: Install dependencies
run: mask bootstrap --no-db --no-docker --no-env --no-rust
- name: Run migrations
run: mask db migrate
- name: Restore cached test build
id: cache-test
uses: tespkg/actions-cache@v1
with:
accessKey: ${{ secrets.CI_CACHE_ACCESS_KEY_ID }}
secretKey: ${{ secrets.CI_CACHE_SECRET_ACCESS_KEY }}
bucket: ${{ secrets.CI_CACHE_BUCKET_NAME }}
endpoint: ${{ secrets.CI_CACHE_ENDPOINT }}
path: |
target/
key: test-rust-${{ github.ref_name }}-${{ hashFiles('Cargo.lock') }}
restore-keys: |
test-rust-${{ github.ref_name }}-
test-rust-main-
test-rust-
- name: Run Rust Tests
run: |
set -ex
mkdir -p target
touch target/tmp.profraw
rm -rf target/*.profraw
cargo sweep -s
export LLVM_PROFILE_FILE="$(pwd)/target/scuffle-%p-%24m.profraw"
export RUSTFLAGS="-C instrument-coverage -C llvm-args=--instrprof-atomic-counter-update-all --cfg=coverage --cfg=trybuild_no_target"
export CARGO_INCREMENTAL=1
cargo build -r --tests
cargo sweep -f
cp -r target target-cache
cargo nextest run --tests -r --no-fail-fast -E "not test(_v6)" --status-level all --profile ci
export CARGO_LLVM_COV="1"
export CARGO_LLVM_COV_TARGET_DIR="$(pwd)/target"
cargo llvm-cov report -r --lcov --output-path lcov.info --ignore-filename-regex "(main\.rs|tests|.*\.nocov\.rs)"
rm -rf target
mv target-cache target
shell: bash
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: lcov.info
fail_ci_if_error: true
- name: Install Playwright Dependencies
run: pnpm --filter website exec playwright install-deps
- name: Run Test JavaScript
run: mask test --no-rust
build:
name: Run Build
runs-on: ubuntu-latest
container: ghcr.io/scuffletv/build:latest
needs: [lint, test]
env:
CARGO_INCREMENTAL: 1
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: pnpm/action-setup@v2
with:
version: latest
- name: Setup Node
uses: actions/setup-node@v3
with:
cache: "pnpm"
node-version: 18
- name: Install dependencies
run: mask bootstrap --no-db --no-docker --no-env --no-js-tests --no-rust
- name: Restore cached build
uses: tespkg/actions-cache@v1
with:
accessKey: ${{ secrets.CI_CACHE_ACCESS_KEY_ID }}
secretKey: ${{ secrets.CI_CACHE_SECRET_ACCESS_KEY }}
bucket: ${{ secrets.CI_CACHE_BUCKET_NAME }}
endpoint: ${{ secrets.CI_CACHE_ENDPOINT }}
path: |
target/
key: build-rust-${{ github.ref_name }}-${{ hashFiles('Cargo.lock') }}
restore-keys: |
build-rust-${{ github.ref_name }}-
build-rust-main-
build-rust-
- name: Cargo Sweep Start
run: cargo sweep -s
- name: Run Build Rust
run: mask build rust
- name: Cargo Sweep Finish
run: cargo sweep -f
- name: Run Build Website
run: mask build website
- name: Upload build artifacts
uses: actions/upload-artifact@v3
with:
name: build
path: |
target/x86_64-unknown-linux-gnu/release/api
target/x86_64-unknown-linux-gnu/release/edge
target/x86_64-unknown-linux-gnu/release/ingest
target/x86_64-unknown-linux-gnu/release/edge
target/x86_64-unknown-linux-gnu/release/transcoder
frontend/website/build
frontend/player/dist
frontend/player/pkg
frontend/player/demo-dist
docker:
name: Build docker images
runs-on: ubuntu-latest
needs: [build]
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Download build artifacts
uses: actions/download-artifact@v3
with:
name: build
- name: Set up Docker Buildx
uses: docker/[email protected]
- name: Login to GitHub Container Registry
uses: docker/[email protected]
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build API image
id: docker_build_api
uses: docker/[email protected]
with:
context: .
file: ./docker/api.Dockerfile
load: true
tags: ghcr.io/scuffletv/api:${{ github.sha }}
- name: Build Edge image
id: docker_build_edge
uses: docker/[email protected]
with:
context: .
file: ./docker/edge.Dockerfile
load: true
tags: ghcr.io/scuffletv/edge:${{ github.sha }}
- name: Build Ingest image
id: docker_build_ingest
uses: docker/[email protected]
with:
context: .
file: ./docker/ingest.Dockerfile
load: true
tags: ghcr.io/scuffletv/ingest:${{ github.sha }}
- name: Build Transcoder image
id: docker_build_transcoder
uses: docker/[email protected]
with:
context: .
file: ./docker/transcoder.Dockerfile
load: true
tags: ghcr.io/scuffletv/transcoder:${{ github.sha }}
- name: Build Website image
id: docker_build_website
uses: docker/[email protected]
with:
context: .
file: ./docker/website.Dockerfile
load: true
tags: ghcr.io/scuffletv/website:${{ github.sha }}
- name: Scan API image
uses: aquasecurity/trivy-action@master
if: ${{ always() && steps.docker_build_api.outcome == 'success' }}
with:
image-ref: ghcr.io/scuffletv/api:${{ github.sha }}
format: "table"
exit-code: "1"
ignore-unfixed: true
vuln-type: "os,library"
severity: "CRITICAL,HIGH"
- name: Scan Edge image
uses: aquasecurity/trivy-action@master
if: ${{ always() && steps.docker_build_edge.outcome == 'success' }}
with:
image-ref: ghcr.io/scuffletv/edge:${{ github.sha }}
format: "table"
exit-code: "1"
ignore-unfixed: true
vuln-type: "os,library"
severity: "CRITICAL,HIGH"
- name: Scan Ingest image
uses: aquasecurity/trivy-action@master
if: ${{ always() && steps.docker_build_ingest.outcome == 'success' }}
with:
image-ref: ghcr.io/scuffletv/ingest:${{ github.sha }}
format: "table"
exit-code: "1"
ignore-unfixed: true
vuln-type: "os,library"
severity: "CRITICAL,HIGH"
- name: Scan Transcoder image
uses: aquasecurity/trivy-action@master
if: ${{ always() && steps.docker_build_transcoder.outcome == 'success' }}
with:
image-ref: ghcr.io/scuffletv/transcoder:${{ github.sha }}
format: "table"
exit-code: "1"
ignore-unfixed: true
vuln-type: "os,library"
severity: "CRITICAL,HIGH"
- name: Scan Website image
uses: aquasecurity/trivy-action@master
if: ${{ always() && steps.docker_build_website.outcome == 'success' }}
with:
image-ref: ghcr.io/scuffletv/website:${{ github.sha }}
format: "table"
exit-code: "1"
ignore-unfixed: true
vuln-type: "os,library"
severity: "CRITICAL,HIGH"
- name: Tag images and push
if: ${{ (github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/feature/'))) || github.event_name == 'workflow_dispatch' }}
# If the push is to the main branch, tag the image as latest
# If the workflow is triggered by a workflow_dispatch event, tag the image as workflow_dispatch
# Otherwise, tag the image with the branch name, in the format of feature-branch-name
env:
TAG: ${{ github.ref == 'refs/heads/main' && 'latest' || github.event_name == 'workflow_dispatch' && 'workflow_dispatch' || github.ref_name }}
run: |
# We need to replace the / in the branch name with a - so that it can be used as a tag
TAG="${TAG//\//-}"
docker tag ghcr.io/scuffletv/api:${{ github.sha }} ghcr.io/scuffletv/api:$TAG
docker tag ghcr.io/scuffletv/edge:${{ github.sha }} ghcr.io/scuffletv/edge:$TAG
docker tag ghcr.io/scuffletv/ingest:${{ github.sha }} ghcr.io/scuffletv/ingest:$TAG
docker tag ghcr.io/scuffletv/transcoder:${{ github.sha }} ghcr.io/scuffletv/transcoder:$TAG
docker tag ghcr.io/scuffletv/website:${{ github.sha }} ghcr.io/scuffletv/website:$TAG
docker push ghcr.io/scuffletv/api:${{ github.sha }}
docker push ghcr.io/scuffletv/api:$TAG
docker push ghcr.io/scuffletv/edge:${{ github.sha }}
docker push ghcr.io/scuffletv/edge:$TAG
docker push ghcr.io/scuffletv/ingest:${{ github.sha }}
docker push ghcr.io/scuffletv/ingest:$TAG
docker push ghcr.io/scuffletv/transcoder:${{ github.sha }}
docker push ghcr.io/scuffletv/transcoder:$TAG
docker push ghcr.io/scuffletv/website:${{ github.sha }}
docker push ghcr.io/scuffletv/website:$TAG
deploy:
name: Deploy to Production
runs-on: ubuntu-latest
needs: [docker]
environment: prod
if: ${{ (github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event_name == 'workflow_dispatch' }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }}
- name: Run Terraform Apply
run: |
terraform -chdir=terraform init
terraform -chdir=terraform workspace select prod
cat > terraform/terraform.tfvars <<EOT
api_docker_image = "ghcr.io/scuffletv/api:${{ github.sha }}"
edge_docker_image = "ghcr.io/scuffletv/edge:${{ github.sha }}"
ingest_docker_image = "ghcr.io/scuffletv/ingest:${{ github.sha }}"
transcoder_docker_image = "ghcr.io/scuffletv/transcoder:${{ github.sha }}"
website_docker_image = "ghcr.io/scuffletv/website:${{ github.sha }}"
EOT
terraform -chdir=terraform apply