-
Notifications
You must be signed in to change notification settings - Fork 38
547 lines (506 loc) · 20.6 KB
/
Copy pathpublish-ghcr.yml
File metadata and controls
547 lines (506 loc) · 20.6 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
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
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
name: Publish GHCR Images
on:
push:
branches:
- develop
- main
tags:
- 'v*'
workflow_dispatch:
inputs:
version:
description: Immutable image tag to publish, for example v0.1.0
required: true
type: string
env:
REGISTRY: ghcr.io
# Serialize runs per ref without cancellation: every push still publishes its
# immutable develop-<sha> tag, and the newest run always moves the mutable
# channel alias last, so the alias cannot end up on a stale image after a race.
concurrency:
group: publish-ghcr-${{ github.ref }}
cancel-in-progress: false
jobs:
prepare:
name: Resolve build metadata
runs-on: blacksmith-4vcpu-ubuntu-2404
permissions:
contents: read
outputs:
owner: ${{ steps.vars.outputs.owner }}
version: ${{ steps.vars.outputs.version }}
product_version: ${{ steps.vars.outputs.product_version }}
app_env: ${{ steps.vars.outputs.app_env }}
extra_tag: ${{ steps.vars.outputs.extra_tag }}
steps:
- name: Checkout code
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
- name: Resolve image metadata
id: vars
shell: bash
run: |
set -euo pipefail
owner="$(printf '%s' "$GITHUB_REPOSITORY_OWNER" | tr '[:upper:]' '[:lower:]')"
app_env="production"
if [ "${GITHUB_REF_TYPE:-}" = "branch" ] && [ "${GITHUB_REF_NAME:-}" = "develop" ]; then
app_env="preview"
fi
# Every build publishes one immutable tag (develop-<sha>, main-<sha>,
# or v*). Branch and release builds additionally move a mutable
# channel alias (develop, main, latest) so deployments can track a
# channel without editing image references on every build. Manual
# dispatch publishes no alias, so re-publishing an old version never
# moves a channel backwards.
extra_tag=""
if [ "$GITHUB_EVENT_NAME" = "workflow_dispatch" ]; then
version="${{ inputs.version }}"
elif [ "${GITHUB_REF_TYPE:-}" = "branch" ] && [ "${GITHUB_REF_NAME:-}" = "develop" ]; then
version="develop-${GITHUB_SHA:0:8}"
extra_tag="develop"
elif [ "${GITHUB_REF_TYPE:-}" = "branch" ] && [ "${GITHUB_REF_NAME:-}" = "main" ]; then
version="main-${GITHUB_SHA:0:8}"
extra_tag="main"
else
version="${GITHUB_REF_NAME:-}"
extra_tag="latest"
fi
case "$version" in
latest|develop|main|'')
echo "Refusing to publish mutable or empty version tag: $version" >&2
exit 1
;;
esac
case "$version" in
*[!A-Za-z0-9._-]*)
echo "Refusing to publish invalid image tag: $version" >&2
exit 1
;;
esac
# The product (changelog) version is baked alongside the image tag
# so channel builds (develop-<sha>/main-<sha>) still know which
# product release they contain (used by the in-app release notices).
product_version="$(jq -r .version package.json)"
case "$product_version" in
''|null)
echo "Failed to read product version from package.json" >&2
exit 1
;;
esac
echo "owner=$owner" >> "$GITHUB_OUTPUT"
echo "version=$version" >> "$GITHUB_OUTPUT"
echo "product_version=$product_version" >> "$GITHUB_OUTPUT"
echo "app_env=$app_env" >> "$GITHUB_OUTPUT"
echo "extra_tag=$extra_tag" >> "$GITHUB_OUTPUT"
deployment-acceptance:
name: Deployment acceptance (amd64)
needs: prepare
runs-on: blacksmith-4vcpu-ubuntu-2404
permissions:
contents: read
packages: read
steps:
- name: Checkout code
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
- name: Setup environment
uses: ./.github/actions/setup-environment
with:
frozen-lockfile: 'true'
node-version: 24.13.1
pnpm-version: 10.29.3
- name: Set up Docker builder
uses: useblacksmith/setup-docker-builder@47a5d0102cc44712a17a633c2599f755008cc40e # v1
# The smoke test pulls the previous published release from GHCR as its
# upgrade baseline. The packages are public today, but authenticate
# anyway so a visibility change cannot silently break the release gate.
- name: Log in to GHCR
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Resolve previous published channel
id: baseline
shell: bash
env:
EXTRA_TAG: ${{ needs.prepare.outputs.extra_tag }}
CANDIDATE_VERSION: ${{ needs.prepare.outputs.version }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
baseline="$EXTRA_TAG"
if [ "$baseline" != 'develop' ]; then
# Release-channel runs (tag, main, manual dispatch) validate the
# upgrade path from the previous published release. gh prints the
# 404 error body to stdout, so only trust the output when the call
# succeeds; capturing it with `|| true` is how a JSON blob once
# became a docker tag.
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. With no
# usable previous release, skip upgrade validation entirely: the
# smoke test still verifies a fresh install of the candidate.
if [ "$baseline" = 'v0.0.1' ]; then
echo "Latest release is legacy v0.0.1 (no images); skipping upgrade validation." >&2
baseline=''
fi
# Manual dispatch can re-publish an older version while a newer
# release is latest. Validating baseline→candidate would then be
# a downgrade dressed up as an upgrade (newer migrations, older
# code), so only keep the upgrade leg when the candidate is
# strictly newer than the baseline.
if [ -n "$baseline" ]; then
case "$CANDIDATE_VERSION" in
v[0-9]*)
newest="$(printf '%s\n%s\n' "$baseline" "$CANDIDATE_VERSION" | sort -V | tail -n1)"
if [ "$CANDIDATE_VERSION" = "$baseline" ] || [ "$newest" != "$CANDIDATE_VERSION" ]; then
echo "Candidate $CANDIDATE_VERSION is not newer than latest release $baseline; skipping upgrade validation for re-publish." >&2
baseline=''
fi
;;
esac
fi
fi
# Never let anything that is not a known channel or v* release tag
# reach `docker pull`.
case "$baseline" in
'' | develop | v[0-9]*) ;;
*)
echo "Ignoring unexpected baseline '$baseline'; skipping upgrade validation." >&2
baseline=''
;;
esac
echo "version=$baseline" >> "$GITHUB_OUTPUT"
- name: Exercise deployment lifecycle
env:
BASELINE_VERSION: ${{ steps.baseline.outputs.version }}
CANDIDATE_VERSION: ${{ needs.prepare.outputs.version }}
run: pnpm deployment:smoke
# Builds run concurrently with the acceptance gate: the gate builds its own
# local images for the smoke test, so nothing here depends on it. The gate
# instead blocks `publish` — builds only push untagged per-arch digests, and
# nothing is consumable until publish assembles the tagged manifests, so a
# failed gate still prevents any image from shipping.
build:
name: Build ${{ matrix.app }} (${{ matrix.arch }})
needs: prepare
runs-on: ${{ matrix.runner }}
permissions:
contents: read
packages: write
strategy:
fail-fast: false
# Each arch builds natively (no QEMU: rustc segfaults under emulation,
# rust-lang/rust#147026) and pushes by digest; the merge job below
# assembles the digests into one multi-arch manifest per image.
matrix:
include:
- app: app
context: .
dockerfile: .docker/app/Dockerfile
target: runtime-app
image: roomote-app
arch: amd64
runner: blacksmith-4vcpu-ubuntu-2404
- app: app
context: .
dockerfile: .docker/app/Dockerfile
target: runtime-app
image: roomote-app
arch: arm64
runner: blacksmith-8vcpu-ubuntu-2404-arm
- app: worker
context: .
dockerfile: apps/worker/Dockerfile
target: runtime
image: roomote-worker
arch: amd64
runner: blacksmith-4vcpu-ubuntu-2404
- app: worker
context: .
dockerfile: apps/worker/Dockerfile
target: runtime
image: roomote-worker
arch: arm64
runner: blacksmith-4vcpu-ubuntu-2404-arm
# The Brain (deployment-hosted gbrain). Published so template-based
# deployments (Railway) can run it without a build step.
- app: gbrain
context: .docker/gbrain
dockerfile: .docker/gbrain/Dockerfile
image: roomote-gbrain
arch: amd64
runner: blacksmith-4vcpu-ubuntu-2404
- app: gbrain
context: .docker/gbrain
dockerfile: .docker/gbrain/Dockerfile
image: roomote-gbrain
arch: arm64
runner: blacksmith-4vcpu-ubuntu-2404-arm
steps:
- name: Checkout code
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
# Blacksmith's builder mounts a persistent NVMe layer cache into the
# runner (per repo/Dockerfile/arch). Unlike type=gha caching this has
# no 10GB repo cap or per-ref scoping, and skips the multi-minute
# cache export upload at the end of every build.
- name: Set up Docker builder
uses: useblacksmith/setup-docker-builder@47a5d0102cc44712a17a633c2599f755008cc40e # v1
- name: Log in to GHCR
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push ${{ matrix.app }} (${{ matrix.arch }}) by digest
id: build
uses: useblacksmith/build-push-action@fb9e3e6a9299c78462bfadd0d93352c316adc9b8 # v2
with:
context: ${{ matrix.context }}
file: ${{ matrix.dockerfile }}
target: ${{ matrix.target }}
platforms: linux/${{ matrix.arch }}
outputs: type=image,name=${{ env.REGISTRY }}/${{ needs.prepare.outputs.owner }}/${{ matrix.image }},push-by-digest=true,name-canonical=true,push=true
build-args: |
R_APP_ENV=${{ needs.prepare.outputs.app_env }}
RELEASE_VERSION=${{ needs.prepare.outputs.version }}
RELEASE_PRODUCT_VERSION=${{ needs.prepare.outputs.product_version }}
- name: Export digest
shell: bash
run: |
set -euo pipefail
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
with:
name: digests-${{ matrix.app }}-${{ matrix.arch }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1
publish:
name: Publish ${{ matrix.app }} manifest
needs: [prepare, build, deployment-acceptance]
runs-on: blacksmith-4vcpu-ubuntu-2404
permissions:
contents: read
packages: write
strategy:
fail-fast: false
matrix:
include:
- app: app
image: roomote-app
- app: worker
image: roomote-worker
- app: gbrain
image: roomote-gbrain
steps:
- name: Download digests
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4
with:
pattern: digests-${{ matrix.app }}-*
path: /tmp/digests
merge-multiple: true
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3
- name: Log in to GHCR
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Create multi-arch manifest
shell: bash
env:
IMAGE: ${{ env.REGISTRY }}/${{ needs.prepare.outputs.owner }}/${{ matrix.image }}
VERSION: ${{ needs.prepare.outputs.version }}
EXTRA_TAG: ${{ needs.prepare.outputs.extra_tag }}
run: |
set -euo pipefail
cd /tmp/digests
tag_args=(-t "$IMAGE:$VERSION")
if [ -n "$EXTRA_TAG" ]; then
tag_args+=(-t "$IMAGE:$EXTRA_TAG")
fi
digest_refs=()
for digest in *; do
digest_refs+=("$IMAGE@sha256:$digest")
done
[ "${#digest_refs[@]}" -eq 2 ] || {
echo "Expected 2 arch digests, found ${#digest_refs[@]}" >&2
exit 1
}
docker buildx imagetools create "${tag_args[@]}" "${digest_refs[@]}"
docker buildx imagetools inspect "$IMAGE:$VERSION"
# Product v* tags: only publish the GitHub Release after multi-arch images for
# both roomote-app and roomote-worker exist at :$version, so self-host install
# (releases/latest) never points at a tag whose images are not ready yet.
create-github-release:
name: Create GitHub Release
runs-on: blacksmith-4vcpu-ubuntu-2404
needs: [prepare, publish]
if: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') }}
permissions:
contents: write
packages: read
steps:
- name: Checkout code
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
with:
token: ${{ secrets.RELEASE_BOT_TOKEN || secrets.GITHUB_TOKEN }}
fetch-depth: 0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3
- name: Log in to GHCR
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Publish GitHub Release for product tag
id: publish_release
env:
GH_TOKEN: ${{ secrets.RELEASE_BOT_TOKEN || secrets.GITHUB_TOKEN }}
VERSION: ${{ needs.prepare.outputs.version }}
OWNER: ${{ needs.prepare.outputs.owner }}
shell: bash
run: |
set -euo pipefail
: "${VERSION:?version is required}"
tag="$VERSION"
case "$tag" in
v*) ;;
*)
echo "Expected a v* product tag, got: $tag" >&2
exit 1
;;
esac
version_no_v="${tag#v}"
for image in roomote-app roomote-worker; do
ref="${REGISTRY}/${OWNER}/${image}:${VERSION}"
echo "Verifying image exists: $ref"
docker buildx imagetools inspect "$ref" >/dev/null
done
if gh release view "$tag" >/dev/null 2>&1; then
echo "GitHub Release $tag already exists; skip."
echo "created=false" >> "$GITHUB_OUTPUT"
exit 0
fi
notes_file="$(mktemp)"
node scripts/release/extract-changelog-section.mjs "$version_no_v" > "$notes_file" || true
if [ ! -s "$notes_file" ]; then
printf 'Roomote %s\n' "$tag" > "$notes_file"
fi
gh release create "$tag" \
--title "Roomote $tag" \
--notes-file "$notes_file" \
--target "$(git rev-parse HEAD)" \
--latest
rm -f "$notes_file"
echo "created=true" >> "$GITHUB_OUTPUT"
echo "Published GitHub Release $tag (images ready)"
- name: Announce GitHub Release in Discord
if: ${{ steps.publish_release.outputs.created == 'true' }}
continue-on-error: true
env:
DISCORD_MAIN_WEBHOOK_URL: ${{ secrets.DISCORD_MAIN_WEBHOOK_URL }}
GH_TOKEN: ${{ secrets.RELEASE_BOT_TOKEN || secrets.GITHUB_TOKEN }}
VERSION: ${{ needs.prepare.outputs.version }}
shell: bash
run: |
set -euo pipefail
if [ -z "${DISCORD_MAIN_WEBHOOK_URL:-}" ]; then
echo "::notice::DISCORD_MAIN_WEBHOOK_URL is not configured; skipping the Discord release announcement."
exit 0
fi
# Custom Discord payloads use the base webhook endpoint. Also accept
# URLs copied from the native GitHub integration setup for convenience.
webhook_url="${DISCORD_MAIN_WEBHOOK_URL%/github}"
payload_file="$(mktemp)"
trap 'rm -f "$payload_file"' EXIT
gh release view "$VERSION" \
--json name,body,url,publishedAt,tagName \
| node scripts/release/build-discord-release-payload.mjs \
> "$payload_file"
curl \
--fail-with-body \
--silent \
--show-error \
--retry 3 \
--retry-all-errors \
--connect-timeout 10 \
--max-time 30 \
--header 'Content-Type: application/json' \
--data-binary "@$payload_file" \
"$webhook_url"
echo "Announced GitHub Release $VERSION in Discord"
# This job only follows successful develop image publishes. (The old
# notify-ops job that dispatched hand-built fleet deploys to Roomote-Ops
# was removed 2026-08-01 with that repo's retirement: every tenant is
# Cloud-managed, and the dispatch had been redeploying quiesced legacy
# projects on every main build.)
notify-staging-cloud:
name: Notify staging Cloud
runs-on: ubuntu-latest
needs:
- prepare
- publish
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/develop' && vars.ROOMOTE_CLOUD_REPO != '' }}
permissions:
contents: read
steps:
- name: Send staging repository dispatch
env:
GH_TOKEN: ${{ secrets.ROOMOTE_CLOUD_DISPATCH_TOKEN }}
CLOUD_REPO: ${{ vars.ROOMOTE_CLOUD_REPO }}
IMAGE_TAG: ${{ needs.prepare.outputs.version }}
run: |
set -euo pipefail
: "${GH_TOKEN:?ROOMOTE_CLOUD_DISPATCH_TOKEN is required}"
case "$CLOUD_REPO" in
RooCodeInc/Roomote-Cloud) ;;
*)
echo "Refusing unexpected ROOMOTE_CLOUD_REPO: $CLOUD_REPO" >&2
exit 1
;;
esac
gh api "repos/${CLOUD_REPO}/dispatches" \
-f event_type=roomote-develop-build \
-f "client_payload[image_tag]=${IMAGE_TAG}" \
-f "client_payload[sha]=${GITHUB_SHA}" \
-f "client_payload[ref]=${GITHUB_REF}"
# Production Cloud rolls its tenant fleet from immutable main builds the
# same way staging follows develop builds. The Cloud-side workflow
# validates the tag against the commit before touching anything.
notify-production-cloud:
name: Notify production Cloud
runs-on: ubuntu-latest
needs:
- prepare
- publish
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' && vars.ROOMOTE_CLOUD_REPO != '' }}
permissions:
contents: read
steps:
- name: Send production repository dispatch
env:
GH_TOKEN: ${{ secrets.ROOMOTE_CLOUD_DISPATCH_TOKEN }}
CLOUD_REPO: ${{ vars.ROOMOTE_CLOUD_REPO }}
IMAGE_TAG: ${{ needs.prepare.outputs.version }}
run: |
set -euo pipefail
: "${GH_TOKEN:?ROOMOTE_CLOUD_DISPATCH_TOKEN is required}"
case "$CLOUD_REPO" in
RooCodeInc/Roomote-Cloud) ;;
*)
echo "Refusing unexpected ROOMOTE_CLOUD_REPO: $CLOUD_REPO" >&2
exit 1
;;
esac
gh api "repos/${CLOUD_REPO}/dispatches" \
-f event_type=roomote-main-build \
-f "client_payload[image_tag]=${IMAGE_TAG}" \
-f "client_payload[sha]=${GITHUB_SHA}" \
-f "client_payload[ref]=${GITHUB_REF}"