-
Notifications
You must be signed in to change notification settings - Fork 6
374 lines (355 loc) · 13.8 KB
/
Copy pathCI.yml
File metadata and controls
374 lines (355 loc) · 13.8 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
name: CI
on:
push:
branches: [main, develop]
pull_request:
branches: [main, develop]
workflow_dispatch:
permissions:
contents: read
env:
NODE_VERSION: 24.13.1
PNPM_VERSION: 10.29.3
jobs:
changes:
name: Detect changed paths
runs-on: blacksmith-4vcpu-ubuntu-2404
outputs:
docs_only: ${{ steps.changed-paths.outputs.docs_only }}
worker_image_affected: ${{ steps.changed-paths.outputs.worker_image_affected }}
steps:
- name: Checkout code
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
with:
fetch-depth: 0
- name: Classify changed paths
id: changed-paths
shell: bash
run: |
set -euo pipefail
# Fail safe: when we cannot compute a reliable diff (manual dispatch,
# force-push over a gone base, or an empty diff), build everything.
emit_build_all() {
echo "docs_only=false" >> "$GITHUB_OUTPUT"
echo "worker_image_affected=true" >> "$GITHUB_OUTPUT"
}
if [ "$GITHUB_EVENT_NAME" = "workflow_dispatch" ]; then
emit_build_all
exit 0
fi
if [ "$GITHUB_EVENT_NAME" = "pull_request" ]; then
base="${{ github.event.pull_request.base.sha }}"
head="${{ github.event.pull_request.head.sha }}"
changed_files="$(git diff --name-only "$base...$head")"
else
before="${{ github.event.before }}"
if [ "$before" = "0000000000000000000000000000000000000000" ]; then
changed_files="$(git diff-tree --no-commit-id --name-only -r "$GITHUB_SHA")"
elif git cat-file -e "$before" 2>/dev/null; then
changed_files="$(git diff --name-only "$before" "$GITHUB_SHA")"
else
# Force-pushed over the previous tip; the base is gone, so run everything.
emit_build_all
exit 0
fi
fi
if [ -z "$changed_files" ]; then
emit_build_all
exit 0
fi
# docs_only: every changed file is documentation or markdown, so all
# heavy jobs can skip.
#
# worker_image_affected: the worker image (apps/worker/Dockerfile)
# builds FROM ubuntu and copies no monorepo source, so it is affected
# only by its own Dockerfile/context inputs. The app image, by
# contrast, copies apps/worker (and packages the worker release), so a
# worker-only change still rebuilds the app image; the app rows stay
# gated on docs_only alone.
#
# This is a closed allowlist: worker_image_affected starts false and
# only the paths matched below flip it true, so an unrecognized path
# does NOT trigger a worker build. If the worker image ever consumes a
# new build-context input, add its path to the case below or the
# worker build will be skipped for changes to it. The build-everything
# fail-safe only covers the uncertain-diff cases handled by
# emit_build_all above (manual dispatch, gone base, empty diff).
docs_only=true
worker_image_affected=false
while IFS= read -r path; do
case "$path" in
apps/docs/*|*.md|*.mdx)
;;
*)
docs_only=false
;;
esac
case "$path" in
apps/worker/*|.docker/sandbox/*|.dockerignore|.github/workflows/CI.yml)
worker_image_affected=true
;;
esac
done <<< "$changed_files"
echo "docs_only=$docs_only" >> "$GITHUB_OUTPUT"
echo "worker_image_affected=$worker_image_affected" >> "$GITHUB_OUTPUT"
lint:
name: Lint
needs: changes
if: ${{ needs.changes.outputs.docs_only != 'true' }}
runs-on: blacksmith-4vcpu-ubuntu-2404
steps:
- name: Checkout code
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
- name: Setup environment
uses: ./.github/actions/setup-environment
with:
enable-turbo-cache: 'true'
frozen-lockfile: 'true'
node-version: ${{ env.NODE_VERSION }}
pnpm-version: ${{ env.PNPM_VERSION }}
turbo-cache-scope: lint
- name: Run lint workflow
run: pnpm lint
knip:
name: Knip
needs: changes
if: ${{ needs.changes.outputs.docs_only != 'true' }}
runs-on: blacksmith-4vcpu-ubuntu-2404
steps:
- name: Checkout code
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
- name: Setup environment
uses: ./.github/actions/setup-environment
with:
frozen-lockfile: 'true'
node-version: ${{ env.NODE_VERSION }}
pnpm-version: ${{ env.PNPM_VERSION }}
- name: Check unused dependencies and files
run: pnpm knip
check-types:
name: Type Check
needs: changes
if: ${{ needs.changes.outputs.docs_only != 'true' }}
runs-on: blacksmith-4vcpu-ubuntu-2404
steps:
- name: Checkout code
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
- name: Setup environment
uses: ./.github/actions/setup-environment
with:
enable-turbo-cache: 'true'
frozen-lockfile: 'true'
node-version: ${{ env.NODE_VERSION }}
pnpm-version: ${{ env.PNPM_VERSION }}
turbo-cache-scope: check-types
- name: Run type checker
run: pnpm check-types
test:
name: Test
needs: changes
if: ${{ needs.changes.outputs.docs_only != 'true' }}
runs-on: blacksmith-4vcpu-ubuntu-2404
services:
postgres:
image: postgres:17.5@sha256:aadf2c0696f5ef357aa7a68da995137f0cf17bad0bf6e1f17de06ae5c769b302
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_DB: test
ports:
- 5432:5432
options: >-
--health-cmd "pg_isready -U postgres -d test"
--health-interval 10s
--health-timeout 5s
--health-retries 5
redis:
image: redis:7@sha256:b2b95679e3b46fb51864949ed25ea976fc3a6bcc00a40a1bc00d568cb2822e50
ports:
- 6379:6379
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Checkout code
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
- name: Setup environment
uses: ./.github/actions/setup-environment
with:
enable-turbo-cache: 'true'
frozen-lockfile: 'true'
node-version: ${{ env.NODE_VERSION }}
pnpm-version: ${{ env.PNPM_VERSION }}
turbo-cache-scope: test
- name: Setup database schema
run: pnpm --filter @roomote/db db:push:test --force
env:
DATABASE_URL: postgres://postgres:password@localhost:5432/test
- name: Run unit tests
run: pnpm test:ci
env:
DATABASE_URL: postgres://postgres:password@localhost:5432/test
REDIS_URL: redis://localhost:6379
- name: Run release script unit tests
run: pnpm test:release-scripts
backup-restore:
name: Fresh-host Backup Restore
needs: changes
if: ${{ needs.changes.outputs.docs_only != 'true' }}
runs-on: blacksmith-4vcpu-ubuntu-2404
steps:
- name: Checkout code
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
- name: Restore an encrypted bundle onto empty volumes
run: bash deploy/host/tests/backup-restore.integration.sh
upgrade-compatibility:
name: Upgrade Compatibility
needs: changes
if: ${{ needs.changes.outputs.docs_only != 'true' }}
runs-on: blacksmith-4vcpu-ubuntu-2404
steps:
- name: Checkout code
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
- name: Setup environment
uses: ./.github/actions/setup-environment
with:
frozen-lockfile: 'true'
node-version: ${{ env.NODE_VERSION }}
pnpm-version: ${{ env.PNPM_VERSION }}
# Boots the previous published release from GHCR, applies this branch's
# migrations to it, and requires the previous release to stay healthy on
# the candidate schema (the expand/contract policy in deploy/README.md).
#
# develop-based runs validate against the continuously published
# `develop` channel. main-based runs (promote PRs) validate against the
# previous published *release* rather than the raw `main` channel alias:
# before the first release ships there is no usable baseline at all, and
# the gate skips instead of booting a known-incompatible image.
- name: Resolve upgrade baseline
id: baseline
shell: bash
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BASE_CHANNEL: ${{ github.base_ref || github.ref_name }}
run: |
set -euo pipefail
baseline="$BASE_CHANNEL"
if [ "$baseline" = 'main' ]; then
# gh prints the 404 error body to stdout; only trust the output
# when the call succeeds.
if ! baseline="$(gh api "repos/$GITHUB_REPOSITORY/releases/latest" --jq .tag_name 2>/dev/null)"; then
baseline=''
fi
# v0.0.1 predates the release pipeline and has no images.
if [ "$baseline" = 'v0.0.1' ]; then
baseline=''
fi
case "$baseline" in
'' | v[0-9]*) ;;
*)
echo "Ignoring unexpected baseline '$baseline'; skipping upgrade validation." >&2
baseline=''
;;
esac
fi
echo "channel=$baseline" >> "$GITHUB_OUTPUT"
- name: Apply candidate migrations to the previous release
env:
BASELINE_CHANNEL: ${{ steps.baseline.outputs.channel }}
run: bash deploy/ci/upgrade-compatibility.sh
docker-build-app:
name: Docker Build (${{ matrix.app }}, ${{ matrix.arch }})
needs: changes
if: ${{ needs.changes.outputs.docs_only != 'true' }}
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: false
# Each arch builds natively, mirroring the publish workflow (no QEMU:
# rustc segfaults under emulation, rust-lang/rust#147026).
matrix:
include:
- app: app
dockerfile: .docker/app/Dockerfile
target: runtime-app
arch: amd64
runner: blacksmith-4vcpu-ubuntu-2404
- app: app
dockerfile: .docker/app/Dockerfile
target: runtime-app
arch: arm64
runner: blacksmith-4vcpu-ubuntu-2404-arm
steps:
- name: Checkout code
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
- name: Validate production Compose security contract
if: matrix.arch == 'amd64'
run: deploy/scripts/validate-compose-security.sh
- name: Set up Docker builder
uses: useblacksmith/setup-docker-builder@47a5d0102cc44712a17a633c2599f755008cc40e # v1
- name: Build ${{ matrix.app }} Dockerfile (${{ matrix.arch }})
uses: useblacksmith/build-push-action@fb9e3e6a9299c78462bfadd0d93352c316adc9b8 # v2
with:
context: .
file: ${{ matrix.dockerfile }}
target: ${{ matrix.target }}
platforms: linux/${{ matrix.arch }}
push: false
build-args: R_APP_ENV=development
# The worker image builds FROM ubuntu and copies no monorepo source, so it is
# skipped unless its own Dockerfile or build context changed (see the
# worker_image_affected classifier). The app image copies apps/worker and
# packages the worker release, so worker-only changes still rebuild the app
# image above via the docs_only gate.
docker-build-worker:
name: Docker Build (${{ matrix.app }}, ${{ matrix.arch }})
needs: changes
if: ${{ needs.changes.outputs.docs_only != 'true' && needs.changes.outputs.worker_image_affected == 'true' }}
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: false
# Each arch builds natively, mirroring the publish workflow (no QEMU:
# rustc segfaults under emulation, rust-lang/rust#147026).
matrix:
include:
- app: worker
dockerfile: apps/worker/Dockerfile
target: runtime
arch: amd64
runner: blacksmith-4vcpu-ubuntu-2404
- app: worker
dockerfile: apps/worker/Dockerfile
target: runtime
arch: arm64
runner: blacksmith-4vcpu-ubuntu-2404-arm
steps:
- name: Checkout code
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
- name: Set up Docker builder
uses: useblacksmith/setup-docker-builder@47a5d0102cc44712a17a633c2599f755008cc40e # v1
- name: Build ${{ matrix.app }} Dockerfile (${{ matrix.arch }})
uses: useblacksmith/build-push-action@fb9e3e6a9299c78462bfadd0d93352c316adc9b8 # v2
with:
context: .
file: ${{ matrix.dockerfile }}
target: ${{ matrix.target }}
platforms: linux/${{ matrix.arch }}
push: false
build-args: R_APP_ENV=development
deployment-config:
name: Deployment artifacts
needs: changes
if: ${{ needs.changes.outputs.docs_only != 'true' }}
runs-on: blacksmith-4vcpu-ubuntu-2404
steps:
- name: Checkout code
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
- name: Setup environment
uses: ./.github/actions/setup-environment
with:
frozen-lockfile: 'true'
node-version: ${{ env.NODE_VERSION }}
pnpm-version: ${{ env.PNPM_VERSION }}
- name: Validate Compose, installers, and platform templates
run: pnpm deployment:validate