-
-
Notifications
You must be signed in to change notification settings - Fork 26
360 lines (305 loc) · 11.2 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
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'
lint-test:
name: Run Lint + Test
runs-on: ubuntu-latest
container: ghcr.io/scuffletv/build: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' || '' }}
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
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
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: Cargo Cache
uses: Swatinem/rust-cache@v2
continue-on-error: false
with:
prefix-key: lint-test
- name: Install dependencies
run: mask bootstrap --no-db --no-docker --no-env --no-rust
- name: Run migrations
run: mask db migrate
- name: Run Lint
run: mask lint
- name: Run Test Rust
run: mask test --no-js --ci
- 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]
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: Cargo Cache
uses: Swatinem/rust-cache@v2
continue-on-error: false
with:
prefix-key: build
- name: Install dependencies
run: mask bootstrap --no-db --no-docker --no-env --no-js-tests --no-rust
- name: Run Build
run: mask build
- 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 and push 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 and push 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 and push 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 and push 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 and push 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