Repository navigation
313 lines (286 loc) · 14.2 KB
/
Copy pathbuild-release.yml
File metadata and controls
313 lines (286 loc) · 14.2 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
name: 'Build: Release'
on:
push:
tags:
- 'v*.*.*' # Triggers on version tags like v1.0.0
# Pins an existing release on deploy/production without rebuilding it —
# only pin-production runs. The first production pin and rollback
# (dispatch the previous tag) both go through here.
workflow_dispatch:
inputs:
tag:
description: 'vX.Y.Z, an existing release'
required: true
type: string
# Never cancel a half-published release. Two tags pushed back to back queue
# rather than racing each other to the `production` and `latest` floating tags.
concurrency:
group: build-release-${{ github.ref_name }}
cancel-in-progress: false
# Read-only by default; the jobs that need to write say so themselves.
permissions:
contents: read
jobs:
# The same gate CI runs, against the exact tagged commit.
#
# main's branch protection already requires the "Test & Build" check to
# merge, so the code in a release has normally passed. "Normally" is the
# problem: a tag can be pushed at ANY commit — an older one, a hotfix
# merged with admin override, a hand-moved tag — and check-ci.yml does not
# run on tags at all, so nothing re-checks what is actually being shipped.
# This job makes the tag itself the unit that gets verified.
#
# Shares the sequence with check-ci.yml through a COMPOSITE action rather
# than a `workflow_call` reusable workflow. A reusable workflow would rename
# the check from "Test & Build" to "<caller> / Test & Build", and main's
# required status check matches on that exact string — every PR to main
# would block forever waiting for a check that no longer reports. A
# composite action runs inside this job, so the name is untouched.
verify:
name: Test & Build
if: github.event_name == 'push'
runs-on: ubuntu-latest
timeout-minutes: 25
steps:
- name: Checkout code
uses: actions/checkout@v7.0.1
- name: Lint, typecheck, test and build
uses: ./.github/actions/verify
# Same shape as build-migrate: one leg per arch, each on a runner of that
# arch — NOT QEMU. On Node 26, `prisma generate` under emulated aarch64 dies
# with `Unable to parse JSON … [Context: getDmmf]`. Release run 40233672280
# (v0.96.3) published no app image because of it, as staging run 40131915205
# (0.95.9) did before 98d7255a; Node 24 survived QEMU. Each leg pushes
# :<tag>-<arch>; merge-app joins them into :<tag>, :production and :latest.
build-app:
name: Build App Image (${{ matrix.arch }})
needs: verify
if: github.event_name == 'push'
strategy:
matrix:
include:
- arch: amd64
runner: ubuntu-latest
- arch: arm64
runner: ubuntu-24.04-arm
runs-on: ${{ matrix.runner }}
timeout-minutes: 30
permissions:
contents: read
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v7.0.1
- name: Build and push APP
uses: ./.github/actions/docker-publish
with:
file: ./Dockerfile.app
platforms: linux/${{ matrix.arch }}
registry-token: ${{ secrets.GITHUB_TOKEN }}
tags: |
ghcr.io/${{ github.repository_owner }}/helldiversbot:${{ github.ref_name }}-${{ matrix.arch }}
build-args: |
NODE_ENV=production
NEXT_PUBLIC_DEPLOY_ENV=production
NEXT_PUBLIC_SENTRY_DSN=${{ vars.NEXT_PUBLIC_SENTRY_DSN }}
NEXT_PUBLIC_VAPID_PUBLIC_KEY=${{ vars.NEXT_PUBLIC_VAPID_PUBLIC_KEY }}
# Sentry credentials go in build-secrets, NOT build-args —
# build-args land in the provenance attestation pushed to
# GHCR, where anyone with pull access can read them. See #284.
build-secrets: |
sentry_auth_token=${{ secrets.SENTRY_AUTH_TOKEN }}
sentry_url=${{ vars.SENTRY_URL }}
sentry_org=${{ secrets.SENTRY_ORG }}
sentry_project=${{ secrets.SENTRY_PROJECT }}
merge-app:
name: Publish App Manifest
needs: build-app
if: github.event_name == 'push'
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
contents: read
packages: write
steps:
- name: Log in to GitHub Container Registry
uses: docker/login-action@v4.8.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Join the two arches into the release tags
env:
IMAGE: ghcr.io/${{ github.repository_owner }}/helldiversbot
TAG: ${{ github.ref_name }}
run: |
docker buildx imagetools create -t "$IMAGE:$TAG" -t "$IMAGE:production" -t "$IMAGE:latest" "$IMAGE:$TAG-amd64" "$IMAGE:$TAG-arm64"
out=$(docker buildx imagetools inspect "$IMAGE:$TAG")
echo "$out"
for p in linux/amd64 linux/arm64; do
grep -qE "Platform: +$p$" <<< "$out" || { echo "::error::$IMAGE:$TAG has no $p manifest"; exit 1; }
done
# Always build migrate in Production — unlike staging, no skip logic here.
# Each tag needs a versioned image, releases are infrequent (~$3/yr CI cost),
# and a missing migration image causes broken deploys. Not worth optimizing.
build-migrate:
name: Build Migrate Image (${{ matrix.arch }})
needs: verify
if: github.event_name == 'push'
# One leg per arch, each on a runner of that arch — NOT QEMU. `prisma
# generate` dies under QEMU aarch64 emulation with `qemu: uncaught
# target signal 4 (Illegal instruction)`, exit 132: Prisma's engine
# binary uses instructions QEMU doesn't implement. Building both arches
# on one x86 runner (8b5b2058) broke the first release that tried it —
# v0.90.4, where the app image published and this one failed, leaving
# no migrate image for the tag — and it went amd64-only (061334c2).
# Built natively on arm64 the same Dockerfile works: `prisma generate`
# at build and the schema engine at run time, checked on every PR that
# touches it by check-migrate-arm64.yml. Each leg pushes
# :<tag>-<arch>; merge-migrate joins them into the release tags.
strategy:
matrix:
include:
- arch: amd64
runner: ubuntu-latest
- arch: arm64
runner: ubuntu-24.04-arm
runs-on: ${{ matrix.runner }}
timeout-minutes: 30
permissions:
contents: read
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v7.0.1
- name: Build and push MIGRATE
uses: ./.github/actions/docker-publish
with:
file: ./Dockerfile.migrate
registry-token: ${{ secrets.GITHUB_TOKEN }}
platforms: linux/${{ matrix.arch }}
tags: |
ghcr.io/${{ github.repository_owner }}/helldiversbot-migrate:${{ github.ref_name }}-${{ matrix.arch }}
build-args: |
NODE_ENV=production
merge-migrate:
name: Publish Migrate Manifest
needs: build-migrate
if: github.event_name == 'push'
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
contents: read
packages: write
steps:
- name: Log in to GitHub Container Registry
uses: docker/login-action@v4.8.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Join the two arches into the release tags
env:
IMAGE: ghcr.io/${{ github.repository_owner }}/helldiversbot-migrate
TAG: ${{ github.ref_name }}
run: |
docker buildx imagetools create -t "$IMAGE:$TAG" -t "$IMAGE:production" -t "$IMAGE:latest" "$IMAGE:$TAG-amd64" "$IMAGE:$TAG-arm64"
out=$(docker buildx imagetools inspect "$IMAGE:$TAG")
echo "$out"
for p in linux/amd64 linux/arm64; do
grep -qE "Platform: +$p$" <<< "$out" || { echo "::error::$IMAGE:$TAG has no $p manifest"; exit 1; }
done
github-release:
name: Create GitHub Release
needs: [merge-app, merge-migrate]
if: github.event_name == 'push'
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: write # creates the GitHub Release for the tag
steps:
- name: Checkout code
uses: actions/checkout@v7.0.1
- name: Extract changelog for this version
id: changelog
env:
TAG_NAME: ${{ github.ref_name }}
run: |
VERSION="${TAG_NAME#v}"
# State-machine awk: find the "## <version>" header, collect until the next "## " header or EOF.
# The heading's first word must equal the version exactly, with or without brackets and
# with or without a trailing date: "## 0.98.0", "## [0.98.0] - 2026-11-10" (#618).
awk -v ver="$VERSION" '
/^## / { if (found) exit; v = $2; gsub(/[][]/, "", v); if (v == ver) { found=1; next } }
found { print }
' CHANGELOG.md > /tmp/release-notes.md
# Fail if changelog section is missing or empty
if [ ! -s /tmp/release-notes.md ] || [ -z "$(tr -d '[:space:]' < /tmp/release-notes.md)" ]; then
echo "::warning::No changelog entry found for ${VERSION} — using tag name as release body"
echo "Release ${TAG_NAME}" > /tmp/release-notes.md
fi
# Append Docker image references
OWNER=$(echo "$GITHUB_REPOSITORY_OWNER" | tr '[:upper:]' '[:lower:]')
{
echo ""
echo "---"
echo ""
echo "### Docker Images"
echo ""
echo '```'
echo "docker pull ghcr.io/${OWNER}/helldiversbot:${TAG_NAME}"
echo "docker pull ghcr.io/${OWNER}/helldiversbot-migrate:${TAG_NAME}"
echo '```'
} >> /tmp/release-notes.md
- name: Create GitHub Release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG_NAME: ${{ github.ref_name }}
run: |
gh release create "$TAG_NAME" \
--title "$TAG_NAME" \
--notes-file /tmp/release-notes.md
# The deploy is Arcane Git Sync from the CI-owned branch deploy/production
# (deploy/README.md § Production): Arcane redeploys when that branch's
# commit changes. This job writes the release tag into the compose of the
# workflow's own checkout — the tag on push, the dispatched branch on
# dispatch — and force-pushes that as deploy/production, the way
# bump-staging-tag handles deploy/staging. main and develop stay PR-only.
#
# On dispatch the builds are skipped and the job pins an existing release:
# rollback is a dispatch of the previous tag. A release that carries a
# migration needs no manual step: every new task applies pending migrations
# before it serves (src/update/migrateOnStart.mjs, #599).
pin-production:
name: Pin Production
needs: [merge-app, merge-migrate]
if: ${{ !cancelled() && (github.event_name == 'workflow_dispatch' || (needs.merge-app.result == 'success' && needs.merge-migrate.result == 'success')) }}
# One pin at a time across tag pushes and dispatches: the workflow's
# concurrency group is per ref, so a release pin and a rollback could race.
concurrency:
group: pin-production
cancel-in-progress: false
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
contents: write
env:
# Through env, never interpolated into the script: the input is free text.
TAG: ${{ inputs.tag || github.ref_name }}
steps:
- name: Both release images exist
run: |
[[ "$TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]] || { echo "::error::$TAG is not vX.Y.Z"; exit 1; }
for image in helldiversbot helldiversbot-migrate; do
docker manifest inspect "ghcr.io/elfensky/$image:$TAG" > /dev/null || { echo "::error::ghcr.io/elfensky/$image:$TAG does not exist"; exit 1; }
done
- name: Checkout code
uses: actions/checkout@v7.0.1
- name: Pin the tag and push deploy/production
run: |
! grep -n '<FILL>' deploy/production/compose.yaml || { echo "::error::deploy/production/compose.yaml still holds <FILL> values"; exit 1; }
sed -i -E "s#^([[:space:]]*image: ghcr\.io/elfensky/helldiversbot:).*#\1${TAG}#" deploy/production/compose.yaml
grep -qF "image: ghcr.io/elfensky/helldiversbot:${TAG}" deploy/production/compose.yaml || { echo "::error::deploy/production/compose.yaml does not pin ${TAG}"; exit 1; }
git config user.name github-actions[bot]
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
git commit -qm "chore(deploy): production → ${TAG} [skip ci]" deploy/production/compose.yaml || echo "compose already pins ${TAG}"
git push --force origin HEAD:refs/heads/deploy/production