-
Notifications
You must be signed in to change notification settings - Fork 7
346 lines (322 loc) · 13.3 KB
/
Copy pathrelease.yml
File metadata and controls
346 lines (322 loc) · 13.3 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
name: Release ChatMux Server
on:
workflow_dispatch:
permissions:
contents: read
jobs:
release-policy:
name: Validate protected release ref
runs-on: ubuntu-22.04
timeout-minutes: 5
steps:
- name: Require main branch
env:
RELEASE_REF: ${{ github.ref }}
run: |
if [ "$RELEASE_REF" != "refs/heads/main" ]; then
echo "Releases may only be dispatched from refs/heads/main." >&2
exit 1
fi
build:
name: Build Node 22 Linux x64 server artifact
needs: release-policy
timeout-minutes: 30
runs-on: ubuntu-22.04
permissions:
contents: read
outputs:
artifact_name: ${{ steps.metadata.outputs.artifact_name }}
release_tag: ${{ steps.metadata.outputs.release_tag }}
steps:
- name: Checkout
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
with:
persist-credentials: false
- name: Install tmux
run: |
sudo apt-get update
sudo apt-get install --yes tmux
tmux -V
- name: Set up Node.js
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6
with:
node-version: 22
architecture: x64
cache: npm
- name: Set up Bun
uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2
with:
bun-version: 1.3.14
- name: Define canonical release asset
id: metadata
run: |
set -euo pipefail
case "$(node --version)" in
v22.*) ;;
*) echo "Node 22 is required." >&2; exit 1 ;;
esac
case "$(getconf GNU_LIBC_VERSION)" in
"glibc 2.35") ;;
*) echo "The release artifact must be built on glibc 2.35." >&2; exit 1 ;;
esac
VERSION="$(node -p "require('./package.json').version")"
ASSET_NAME="chatmux-server-${VERSION}-linux-x64-node22.tar.gz"
{
echo "artifact_name=$ASSET_NAME"
echo "release_tag=v$VERSION"
} >> "$GITHUB_OUTPUT"
- name: Install dependencies
run: npm ci
- name: Verify source
run: npm run verify
- name: Build server artifact
run: npm run server:bundle
- name: Require updater worker and exact release metadata
run: |
set -euo pipefail
test -f dist-server/server/release-update-worker.js
test -f packaging/release/update-compatibility.json
node --input-type=module <<'EOF'
import fs from 'node:fs/promises';
const version = JSON.parse(await fs.readFile('package.json', 'utf8')).version;
const declaration = JSON.parse(await fs.readFile('packaging/release/update-compatibility.json', 'utf8'));
const values = declaration?.schema === 1 && declaration?.releases?.[version]?.database?.rollbackCompatibleFrom;
if (!Array.isArray(values) || values.some((value) => !/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/u.test(value)) || new Set(values).size !== values.length) {
throw new Error(`No exact compatibility declaration exists for ${version}.`);
}
EOF
test ! -e release/server/image.png
- name: Stage and verify canonical release assets
env:
ASSET_NAME: ${{ steps.metadata.outputs.artifact_name }}
run: |
set -euo pipefail
shopt -s nullglob
archives=(release/server/*.tar.gz)
if [ "${#archives[@]}" -ne 1 ]; then
echo "Expected exactly one generated server archive." >&2
exit 1
fi
source_archive="${archives[0]}"
if [ "$(basename "$source_archive")" != "$ASSET_NAME" ]; then
echo "Generated archive name does not match canonical release asset: $source_archive" >&2
exit 1
fi
source_checksum="${source_archive}.sha256"
test -f "$source_checksum"
(
cd "$(dirname "$source_archive")"
sha256sum --check "$(basename "$source_checksum")"
)
mkdir release-assets
cp "$source_archive" "release-assets/$ASSET_NAME"
(
cd release-assets
sha256sum "$ASSET_NAME" > "$ASSET_NAME.sha256"
sha256sum --check "$ASSET_NAME.sha256"
)
assets=(release-assets/*)
if [ "${#assets[@]}" -ne 2 ] ||
[ ! -f "release-assets/$ASSET_NAME" ] ||
[ ! -f "release-assets/$ASSET_NAME.sha256" ] ||
[ -e release-assets/image.png ]; then
echo "Release staging must contain only the canonical archive and checksum, never image.png." >&2
exit 1
fi
tar -tzf "release-assets/$ASSET_NAME" | node --input-type=module -e "
import fs from 'node:fs';
const entries = fs.readFileSync(0, 'utf8').trim().split('\n').filter(Boolean);
const required = ['./dist-server/server/release-update-worker.js', './release-update-metadata.json'];
if (entries.some((entry) => entry.includes('image.png') || entry.startsWith('/') || entry.split('/').includes('..') || !entry.startsWith('./')) || required.some((entry) => !entries.includes(entry))) {
throw new Error('Archive updater layout is unsafe or incomplete.');
}
"
- name: Smoke extracted server artifact
env:
ASSET_NAME: ${{ steps.metadata.outputs.artifact_name }}
run: |
set -euo pipefail
mkdir extracted
tar -xzf "release-assets/$ASSET_NAME" -C extracted
test -f extracted/package.json
expected_version="${ASSET_NAME#chatmux-server-}"
expected_version="${expected_version%-linux-x64-node22.tar.gz}"
actual_version="$(node -p "require('./extracted/package.json').version")"
test "$actual_version" = "$expected_version"
node extracted/scripts/chatmux-runtime.mjs --help
- name: Upload canonical server release assets
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6
with:
name: chatmux-server-release
path: release-assets/*
if-no-files-found: error
ubuntu-24-compatibility:
name: Smoke server artifact on Ubuntu 24.04
needs: build
runs-on: ubuntu-24.04
permissions:
contents: read
steps:
- name: Set up Node.js
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6
with:
node-version: 22
architecture: x64
- name: Download canonical server release assets
uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6
with:
name: chatmux-server-release
path: release-assets
- name: Verify checksum and smoke extracted artifact
env:
ASSET_NAME: ${{ needs.build.outputs.artifact_name }}
run: |
set -euo pipefail
shopt -s nullglob
assets=(release-assets/*)
if [ "${#assets[@]}" -ne 2 ] ||
[ ! -f "release-assets/$ASSET_NAME" ] ||
[ ! -f "release-assets/$ASSET_NAME.sha256" ] ||
[ -e release-assets/image.png ]; then
echo "Compatibility job received non-canonical release assets." >&2
exit 1
fi
(
cd release-assets
sha256sum --check "$ASSET_NAME.sha256"
)
mkdir extracted
tar -xzf "release-assets/$ASSET_NAME" -C extracted
test -f extracted/package.json
expected_version="${ASSET_NAME#chatmux-server-}"
expected_version="${expected_version%-linux-x64-node22.tar.gz}"
actual_version="$(node -p "require('./extracted/package.json').version")"
test "$actual_version" = "$expected_version"
node extracted/scripts/chatmux-runtime.mjs --help
(
cd extracted
node -e "const Database=require('better-sqlite3'); const bcrypt=require('bcrypt'); const pty=require('node-pty'); const db=new Database(':memory:'); db.exec('select 1'); db.close(); const hash=bcrypt.hashSync('smoke',4); if(!bcrypt.compareSync('smoke',hash)) process.exit(1); const child=pty.spawn(process.execPath,['-e','process.exit(0)']); child.onExit(() => process.exit(0)); setTimeout(() => process.exit(1),5000)"
node -e "const {spawnSync}=require('node:child_process'); const rg=require('@vscode/ripgrep').rgPath; const result=spawnSync(rg,['--version'],{stdio:'inherit'}); process.exit(result.status ?? 1)"
)
export HOME="$RUNNER_TEMP/chatmux-home"
mkdir -p "$HOME"
SERVER_PORT=39001 HOST=127.0.0.1 node extracted/scripts/chatmux-runtime.mjs start >"$RUNNER_TEMP/chatmux-server.log" 2>&1 &
server_pid=$!
trap 'kill "$server_pid" 2>/dev/null || true' EXIT
for _ in {1..30}; do
if curl --fail --silent http://127.0.0.1:39001/health >/dev/null; then
break
fi
sleep 1
done
curl --fail --silent http://127.0.0.1:39001/health
kill "$server_pid"
wait "$server_pid" || true
trap - EXIT
rollback-compatibility:
name: Prove declared database rollback compatibility
needs: build
runs-on: ubuntu-22.04
timeout-minutes: 20
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
with:
persist-credentials: false
- name: Set up Node.js
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6
with:
node-version: 22
architecture: x64
- name: Download just-built canonical server release assets
uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6
with:
name: chatmux-server-release
path: target-assets
- name: Prove target migration and exact old-runtime rollback
env:
ASSET_NAME: ${{ needs.build.outputs.artifact_name }}
GH_TOKEN: ${{ github.token }}
CHATMUX_UPDATE_COMPATIBILITY_DECLARATION: packaging/release/update-compatibility.json
CHATMUX_RELEASE_REPOSITORY: ${{ github.repository }}
CHATMUX_COMPATIBILITY_EVIDENCE_DIR: rollback-compatibility-evidence
run: |
set -euo pipefail
target_version="${ASSET_NAME#chatmux-server-}"
target_version="${target_version%-linux-x64-node22.tar.gz}"
CHATMUX_TARGET_VERSION="$target_version" \
CHATMUX_TARGET_ARCHIVE="target-assets/$ASSET_NAME" \
CHATMUX_TARGET_CHECKSUM="target-assets/$ASSET_NAME.sha256" \
node scripts/release/verify-db-rollback-compatibility.mjs
- name: Upload rollback compatibility evidence
if: always()
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6
with:
name: rollback-compatibility-evidence
path: rollback-compatibility-evidence
if-no-files-found: warn
publish:
name: Publish GitHub Release
needs:
- build
- ubuntu-24-compatibility
- rollback-compatibility
runs-on: ubuntu-22.04
environment: release
timeout-minutes: 15
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
with:
persist-credentials: false
- name: Download canonical server release assets
uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6
with:
name: chatmux-server-release
path: release-assets
- name: Verify publish inputs
env:
ASSET_NAME: ${{ needs.build.outputs.artifact_name }}
run: |
set -euo pipefail
shopt -s nullglob
assets=(release-assets/*)
if [ "${#assets[@]}" -ne 2 ] ||
[ ! -f "release-assets/$ASSET_NAME" ] ||
[ ! -f "release-assets/$ASSET_NAME.sha256" ] ||
[ -e release-assets/image.png ]; then
echo "Refusing to publish non-canonical release assets or image.png." >&2
exit 1
fi
if [ ! -f install.sh ]; then
echo "Refusing to publish without the one-line bootstrap install.sh." >&2
exit 1
fi
(
cd release-assets
sha256sum --check "$ASSET_NAME.sha256"
)
tar -tzf "release-assets/$ASSET_NAME" | node --input-type=module -e "
import fs from 'node:fs';
const entries = fs.readFileSync(0, 'utf8').trim().split('\n').filter(Boolean);
if (entries.some((entry) => entry.includes('image.png'))) throw new Error('image.png is forbidden from release publication.');
"
- name: Create GitHub Release
env:
GH_TOKEN: ${{ github.token }}
ASSET_NAME: ${{ needs.build.outputs.artifact_name }}
RELEASE_TAG: ${{ needs.build.outputs.release_tag }}
run: |
set -euo pipefail
gh release create "$RELEASE_TAG" \
"release-assets/$ASSET_NAME" \
"release-assets/$ASSET_NAME.sha256" \
install.sh \
--repo "$GITHUB_REPOSITORY" \
--target "$GITHUB_SHA" \
--title "ChatMux $RELEASE_TAG" \
--generate-notes