-
-
Notifications
You must be signed in to change notification settings - Fork 14
447 lines (378 loc) · 12.9 KB
/
ci.yaml
File metadata and controls
447 lines (378 loc) · 12.9 KB
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
name: build
on:
push:
branches:
- main
pull_request:
branches:
- main
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
jobs:
changes:
runs-on: ubuntu-latest
outputs:
app: ${{ steps.filter.outputs.app }}
docker: ${{ steps.filter.outputs.docker }}
docs: ${{ steps.filter.outputs.docs }}
frontend: ${{ steps.filter.outputs.frontend }}
infra-app: ${{ steps.filter.outputs.infra-app }}
infra-db: ${{ steps.filter.outputs.infra-db }}
infra-o11y: ${{ steps.filter.outputs.infra-o11y }}
steps:
- name: Checkout Source
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- name: Detect changes
uses: dorny/paths-filter@fbd0ab8f3e69293af611ebaee6363fc25e6d187d # v4.0.1
id: filter
with:
filters: |
app:
- 'src/**'
- 'tests/**'
- 'pyproject.toml'
- 'uv.lock'
- '.github/workflows/ci.yaml'
docker:
- 'Dockerfile'
- 'scripts/start*.sh'
- 'pyproject.toml'
- 'uv.lock'
docs:
- 'docs/**'
frontend:
- 'src/spellbot/web/templates/**/*.js'
- 'tests-js/**'
- 'package.json'
- 'package-lock.json'
- 'vitest.config.js'
- '.github/workflows/ci.yaml'
infra-app:
- 'infrastructure/app/**'
infra-db:
- 'infrastructure/db/**'
infra-o11y:
- 'infrastructure/o11y/**'
build:
needs: changes
if: needs.changes.outputs.app == 'true'
runs-on: ubuntu-latest
concurrency:
group: ${{ github.workflow }}-build-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
strategy:
max-parallel: 4
matrix:
python-version: ["3.14"]
postgres-version: ["17"]
database-url:
["postgresql+psycopg://postgres:postgres@localhost:5432/postgres"]
services:
postgres:
image: postgres:${{ matrix.postgres-version }}
env:
POSTGRES_PASSWORD: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
--name postgres
ports:
- 5432:5432
env:
PGHOST: localhost
PGUSER: postgres
PGDATABASE: postgres
PGPASSWORD: postgres
steps:
- name: Install postgresql-client
run: |
sudo apt-get update
sudo apt-get install --yes postgresql-client
- name: Connect to PostgreSQL with CLI
run: psql -c 'SELECT VERSION();'
- name: Show PostgreSQL config file
run: psql -c 'SHOW config_file;'
- name: Alter max connections
run: |
docker exec -i postgres bash << EOF
sed -i -e 's/max_connections = 100/max_connections = 1000/' /var/lib/postgresql/data/postgresql.conf
sed -i -e 's/shared_buffers = 128MB/shared_buffers = 2GB/' /var/lib/postgresql/data/postgresql.conf
EOF
docker restart --time 0 postgres
sleep 5
- name: Show max connections
run: psql -c 'SHOW max_connections;'
- name: Checkout Source
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- name: Install uv
uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0
with:
version: latest
enable-cache: true
- name: Install Python ${{ matrix.python-version }}
run: uv python install ${{ matrix.python-version }}
- name: Run Tests
run: uv run --frozen pytest -n auto -vv --cov --cov-report=html --cov-report=xml
env:
DATABASE_URL: ${{ matrix.database-url }}
- name: Send Reports to Codecov
uses: codecov/codecov-action@e79a6962e0d4c0c17b229090214935d2e33f8354 # v6.0.1
env:
PYTHON: ${{ matrix.python-version }}
POSTGRES: ${{ matrix.postgres-version }}
DB_URL: ${{ matrix.database-url }}
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
env_vars: PYTHON,POSTGRES,DB_URL
docker:
needs: changes
if: needs.changes.outputs.docker == 'true'
runs-on: ubuntu-latest
concurrency:
group: ${{ github.workflow }}-docker-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
steps:
- name: Checkout Source
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@d7f5e7f509e45cec5c76c4d5afdd7de93d0b3df5 # v4.1.0
- name: Build Docker image
uses: docker/build-push-action@f9f3042f7e2789586610d6e8b85c8f03e5195baf # v7.2.0
with:
context: .
push: false
load: true
tags: spellbot:test
cache-from: type=gha,scope=docker-build
cache-to: type=gha,mode=max,scope=docker-build
- name: Verify CLI runs
run: |
docker run --rm spellbot:test /spellbot/.venv/bin/python -c "from spellbot import main; main()" --help
- name: Check image size
run: |
SIZE=$(docker image inspect spellbot:test --format='{{.Size}}')
SIZE_MB=$((SIZE / 1024 / 1024))
echo "Image size: ${SIZE_MB}MB"
# Fail if image is larger than 500MB
if [ $SIZE_MB -gt 500 ]; then
echo "::warning::Image size (${SIZE_MB}MB) exceeds 500MB"
fi
docs:
needs: changes
if: needs.changes.outputs.docs == 'true'
runs-on: ubuntu-latest
concurrency:
group: ${{ github.workflow }}-docs-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
steps:
- name: Checkout Source
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- name: Setup Ruby
uses: ruby/setup-ruby@afeafc3d1ab54a631816aba4c914a0081c12ff2f # v1
with:
ruby-version: "3.3"
bundler-cache: true
working-directory: docs
- name: Build Jekyll site
run: bundle exec jekyll build --strict_front_matter
working-directory: docs
vitest:
needs: changes
if: needs.changes.outputs.frontend == 'true'
runs-on: ubuntu-latest
concurrency:
group: ${{ github.workflow }}-vitest-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
steps:
- name: Checkout Source
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- name: Setup Node
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version: "24"
cache: "npm"
- name: Install dependencies
run: npm ci
- name: Run Vitest
run: npm test
terraform-app:
needs: changes
if: needs.changes.outputs.infra-app == 'true'
runs-on: ubuntu-latest
concurrency:
group: ${{ github.workflow }}-tf-app-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
steps:
- name: Checkout Source
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- name: Setup Terraform
uses: hashicorp/setup-terraform@dfe3c3f87815947d99a8997f908cb6525fc44e9e # v4.0.1
with:
terraform_version: "1.12"
- name: Setup TFLint
uses: terraform-linters/setup-tflint@b480b8fcdaa6f2c577f8e4fa799e89e756bb7c93 # v6.2.2
with:
tflint_version: latest
- name: Terraform Format Check
run: terraform fmt -check -recursive
working-directory: infrastructure/app
- name: Terraform Init
run: terraform init -backend=false
working-directory: infrastructure/app
- name: Terraform Validate
run: terraform validate
working-directory: infrastructure/app
- name: TFLint Init
run: tflint --init
working-directory: infrastructure/app
- name: TFLint
run: tflint --format=compact
working-directory: infrastructure/app
terraform-db:
needs: changes
if: needs.changes.outputs.infra-db == 'true'
runs-on: ubuntu-latest
concurrency:
group: ${{ github.workflow }}-tf-db-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
steps:
- name: Checkout Source
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- name: Setup Terraform
uses: hashicorp/setup-terraform@dfe3c3f87815947d99a8997f908cb6525fc44e9e # v4.0.1
with:
terraform_version: "1.12"
- name: Setup TFLint
uses: terraform-linters/setup-tflint@b480b8fcdaa6f2c577f8e4fa799e89e756bb7c93 # v6.2.2
with:
tflint_version: latest
- name: Terraform Format Check
run: terraform fmt -check -recursive
working-directory: infrastructure/db
- name: Terraform Init
run: terraform init -backend=false
working-directory: infrastructure/db
- name: Terraform Validate
run: terraform validate
working-directory: infrastructure/db
- name: TFLint Init
run: tflint --init
working-directory: infrastructure/db
- name: TFLint
run: tflint --format=compact
working-directory: infrastructure/db
terraform-o11y:
needs: changes
if: needs.changes.outputs.infra-o11y == 'true'
runs-on: ubuntu-latest
concurrency:
group: ${{ github.workflow }}-tf-o11y-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
steps:
- name: Checkout Source
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- name: Setup Terraform
uses: hashicorp/setup-terraform@dfe3c3f87815947d99a8997f908cb6525fc44e9e # v4.0.1
with:
terraform_version: "1.12"
- name: Setup TFLint
uses: terraform-linters/setup-tflint@b480b8fcdaa6f2c577f8e4fa799e89e756bb7c93 # v6.2.2
with:
tflint_version: latest
- name: Terraform Format Check
run: terraform fmt -check -recursive
working-directory: infrastructure/o11y
- name: Terraform Init
run: terraform init -backend=false
working-directory: infrastructure/o11y
- name: Terraform Validate
run: terraform validate
working-directory: infrastructure/o11y
- name: TFLint Init
run: tflint --init
working-directory: infrastructure/o11y
- name: TFLint
run: tflint --format=compact
working-directory: infrastructure/o11y
deploy-stage:
name: Deploy to stage
needs:
[
changes,
build,
docker,
docs,
vitest,
terraform-app,
terraform-db,
terraform-o11y,
]
if: |
always() &&
github.ref == 'refs/heads/main' &&
github.event_name == 'push' &&
!contains(needs.*.result, 'failure') &&
!contains(needs.*.result, 'cancelled')
uses: ./.github/workflows/deploy.yml
with:
environment: stage
secrets: inherit
# Gate job - this is the only required check for PRs
ci:
runs-on: ubuntu-latest
needs:
[
changes,
build,
docker,
docs,
vitest,
terraform-app,
terraform-db,
terraform-o11y,
deploy-stage,
]
if: always()
steps:
- name: Check required jobs
run: |
# Check if any job failed (not skipped, not successful)
if [[ "${{ needs.changes.result }}" == "failure" ]]; then
echo "changes job failed"
exit 1
fi
if [[ "${{ needs.build.result }}" == "failure" ]]; then
echo "build job failed"
exit 1
fi
if [[ "${{ needs.docker.result }}" == "failure" ]]; then
echo "docker job failed"
exit 1
fi
if [[ "${{ needs.docs.result }}" == "failure" ]]; then
echo "docs job failed"
exit 1
fi
if [[ "${{ needs.vitest.result }}" == "failure" ]]; then
echo "vitest job failed"
exit 1
fi
if [[ "${{ needs.terraform-app.result }}" == "failure" ]]; then
echo "terraform-app job failed"
exit 1
fi
if [[ "${{ needs.terraform-db.result }}" == "failure" ]]; then
echo "terraform-db job failed"
exit 1
fi
if [[ "${{ needs.terraform-o11y.result }}" == "failure" ]]; then
echo "terraform-o11y job failed"
exit 1
fi
if [[ "${{ needs.deploy-stage.result }}" == "failure" ]]; then
echo "deploy-stage job failed"
exit 1
fi
echo "All required jobs passed or were skipped"