Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

release.yml

462 lines15.5 KB

1name: Release
2​
3on:
4 push:
5 tags:
6 - "v*.*.*"
7 schedule:
8 - cron: "0 9 * * *"
9 workflow_dispatch:
10 inputs:
11 channel:
12 description: "Release channel"
13 required: false
14 default: stable
15 type: choice
16 options:
17 - stable
18 - nightly
19 version:
20 description: "Release version (for example 1.2.3 or v1.2.3)"
21 required: false
22 type: string
23​
24permissions:
25 contents: write
26 id-token: write
27​
28jobs:
29 preflight:
30 name: Preflight
31 runs-on: ubuntu-24.04
32 timeout-minutes: 10
33 outputs:
34 release_channel: ${{ steps.release_meta.outputs.release_channel }}
35 version: ${{ steps.release_meta.outputs.version }}
36 tag: ${{ steps.release_meta.outputs.tag }}
37 release_name: ${{ steps.release_meta.outputs.name }}
38 short_sha: ${{ steps.release_meta.outputs.short_sha }}
39 previous_tag: ${{ steps.previous_tag.outputs.previous_tag }}
40 cli_dist_tag: ${{ steps.release_meta.outputs.cli_dist_tag }}
41 is_prerelease: ${{ steps.release_meta.outputs.is_prerelease }}
42 make_latest: ${{ steps.release_meta.outputs.make_latest }}
43 ref: ${{ github.sha }}
44 steps:
45 - name: Checkout
46 uses: actions/checkout@v6
47 with:
48 fetch-depth: 0
49​
50 - name: Setup Bun
51 uses: oven-sh/setup-bun@v2
52 with:
53 bun-version-file: package.json
54​
55 - name: Setup Node
56 uses: actions/setup-node@v6
57 with:
58 node-version-file: package.json
59​
60 - name: Install dependencies
61 run: bun install --frozen-lockfile
62​
63 - id: release_meta
64 name: Resolve release version
65 shell: bash
66 env:
67 DISPATCH_CHANNEL: ${{ github.event.inputs.channel }}
68 DISPATCH_VERSION: ${{ github.event.inputs.version }}
69 NIGHTLY_DATE: ${{ github.run_started_at }}
70 NIGHTLY_SHA: ${{ github.sha }}
71 NIGHTLY_RUN_NUMBER: ${{ github.run_number }}
72 run: |
73 if [[ "${GITHUB_EVENT_NAME}" == "schedule" || ( "${GITHUB_EVENT_NAME}" == "workflow_dispatch" && "${DISPATCH_CHANNEL:-stable}" == "nightly" ) ]]; then
74 nightly_date="$(date -u -d "$NIGHTLY_DATE" +%Y%m%d)"
75​
76 node scripts/resolve-nightly-release.ts \
77 --date "$nightly_date" \
78 --run-number "$NIGHTLY_RUN_NUMBER" \
79 --sha "$NIGHTLY_SHA" \
80 --github-output
81​
82 echo "release_channel=nightly" >> "$GITHUB_OUTPUT"
83 echo "cli_dist_tag=nightly" >> "$GITHUB_OUTPUT"
84 echo "is_prerelease=true" >> "$GITHUB_OUTPUT"
85 echo "make_latest=false" >> "$GITHUB_OUTPUT"
86 else
87 if [[ "${GITHUB_EVENT_NAME}" == "workflow_dispatch" ]]; then
88 raw="${DISPATCH_VERSION}"
89 if [[ -z "$raw" ]]; then
90 echo "workflow_dispatch stable releases require the version input." >&2
91 exit 1
92 fi
93 else
94 raw="${GITHUB_REF_NAME}"
95 fi
96​
97 version="${raw#v}"
98 if [[ ! "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+([.-][0-9A-Za-z.-]+)?$ ]]; then
99 echo "Invalid release version: $raw" >&2
100 exit 1
101 fi
102​
103 echo "release_channel=stable" >> "$GITHUB_OUTPUT"
104 echo "version=$version" >> "$GITHUB_OUTPUT"
105 echo "tag=v$version" >> "$GITHUB_OUTPUT"
106 echo "name=T3 Code v$version" >> "$GITHUB_OUTPUT"
107 echo "cli_dist_tag=latest" >> "$GITHUB_OUTPUT"
108 if [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
109 echo "is_prerelease=false" >> "$GITHUB_OUTPUT"
110 echo "make_latest=true" >> "$GITHUB_OUTPUT"
111 else
112 echo "is_prerelease=true" >> "$GITHUB_OUTPUT"
113 echo "make_latest=false" >> "$GITHUB_OUTPUT"
114 fi
115 fi
116​
117 - name: Lint
118 run: bun run lint
119​
120 - name: Typecheck
121 run: bun run typecheck
122​
123 - name: Test
124 run: bun run test
125​
126 - id: previous_tag
127 name: Resolve previous release tag
128 run: |
129 node scripts/resolve-previous-release-tag.ts \
130 --channel "${{ steps.release_meta.outputs.release_channel }}" \
131 --current-tag "${{ steps.release_meta.outputs.tag }}" \
132 --github-output
133​
134 build:
135 name: Build ${{ matrix.label }}
136 needs: preflight
137 runs-on: ${{ matrix.runner }}
138 timeout-minutes: 30
139 strategy:
140 fail-fast: false
141 matrix:
142 include:
143 - label: macOS arm64
144 runner: macos-14
145 platform: mac
146 target: dmg
147 arch: arm64
148 - label: macOS x64
149 runner: macos-15-intel
150 platform: mac
151 target: dmg
152 arch: x64
153 - label: Linux x64
154 runner: ubuntu-24.04
155 platform: linux
156 target: AppImage
157 arch: x64
158 - label: Windows x64
159 runner: windows-2022
160 platform: win
161 target: nsis
162 arch: x64
163 steps:
164 - name: Checkout
165 uses: actions/checkout@v6
166 with:
167 ref: ${{ needs.preflight.outputs.ref }}
168 fetch-depth: 0
169​
170 - name: Setup Bun
171 uses: oven-sh/setup-bun@v2
172 with:
173 bun-version-file: package.json
174​
175 - name: Setup Node
176 uses: actions/setup-node@v6
177 with:
178 node-version-file: package.json
179​
180 - name: Install dependencies
181 run: bun install --frozen-lockfile
182​
183 - name: Align package versions to release version
184 run: node scripts/update-release-package-versions.ts "${{ needs.preflight.outputs.version }}"
185​
186 - name: Build desktop artifact
187 shell: bash
188 env:
189 CSC_LINK: ${{ secrets.CSC_LINK }}
190 CSC_KEY_PASSWORD: ${{ secrets.CSC_KEY_PASSWORD }}
191 APPLE_API_KEY: ${{ secrets.APPLE_API_KEY }}
192 APPLE_API_KEY_ID: ${{ secrets.APPLE_API_KEY_ID }}
193 APPLE_API_ISSUER: ${{ secrets.APPLE_API_ISSUER }}
194 AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
195 AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
196 AZURE_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}
197 AZURE_TRUSTED_SIGNING_ENDPOINT: ${{ secrets.AZURE_TRUSTED_SIGNING_ENDPOINT }}
198 AZURE_TRUSTED_SIGNING_ACCOUNT_NAME: ${{ secrets.AZURE_TRUSTED_SIGNING_ACCOUNT_NAME }}
199 AZURE_TRUSTED_SIGNING_CERTIFICATE_PROFILE_NAME: ${{ secrets.AZURE_TRUSTED_SIGNING_CERTIFICATE_PROFILE_NAME }}
200 AZURE_TRUSTED_SIGNING_PUBLISHER_NAME: ${{ secrets.AZURE_TRUSTED_SIGNING_PUBLISHER_NAME }}
201 run: |
202 args=(
203 --platform "${{ matrix.platform }}"
204 --target "${{ matrix.target }}"
205 --arch "${{ matrix.arch }}"
206 --build-version "${{ needs.preflight.outputs.version }}"
207 --verbose
208 )
209​
210 has_all() {
211 for value in "$@"; do
212 if [[ -z "$value" ]]; then
213 return 1
214 fi
215 done
216 return 0
217 }
218​
219 if [[ "${{ matrix.platform }}" == "mac" ]]; then
220 if has_all "$CSC_LINK" "$CSC_KEY_PASSWORD" "$APPLE_API_KEY" "$APPLE_API_KEY_ID" "$APPLE_API_ISSUER"; then
221 key_path="$RUNNER_TEMP/AuthKey_${APPLE_API_KEY_ID}.p8"
222 printf '%s' "$APPLE_API_KEY" > "$key_path"
223 export APPLE_API_KEY="$key_path"
224 echo "macOS signing enabled."
225 args+=(--signed)
226 else
227 echo "macOS signing disabled (missing one or more Apple signing secrets)."
228 fi
229 elif [[ "${{ matrix.platform }}" == "win" ]]; then
230 if has_all \
231 "$AZURE_TENANT_ID" \
232 "$AZURE_CLIENT_ID" \
233 "$AZURE_CLIENT_SECRET" \
234 "$AZURE_TRUSTED_SIGNING_ENDPOINT" \
235 "$AZURE_TRUSTED_SIGNING_ACCOUNT_NAME" \
236 "$AZURE_TRUSTED_SIGNING_CERTIFICATE_PROFILE_NAME" \
237 "$AZURE_TRUSTED_SIGNING_PUBLISHER_NAME"; then
238 echo "Windows signing enabled (Azure Trusted Signing)."
239 args+=(--signed)
240 else
241 echo "Windows signing disabled (missing one or more Azure Trusted Signing secrets)."
242 fi
243 else
244 echo "Signing disabled for ${{ matrix.platform }}."
245 fi
246​
247 bun run dist:desktop:artifact -- "${args[@]}"
248​
249 - name: Collect release assets
250 shell: bash
251 run: |
252 set -euo pipefail
253 mkdir -p release-publish
254​
255 shopt -s nullglob
256 for pattern in \
257 "release/*.dmg" \
258 "release/*.zip" \
259 "release/*.AppImage" \
260 "release/*.exe" \
261 "release/*.blockmap" \
262 "release/*.yml"; do
263 for file in $pattern; do
264 cp "$file" release-publish/
265 done
266 done
267​
268 if [[ "${{ matrix.platform }}" == "mac" && "${{ matrix.arch }}" != "arm64" ]]; then
269 shopt -s nullglob
270 for manifest in release-publish/*-mac.yml; do
271 mv "$manifest" "${manifest%.yml}-${{ matrix.arch }}.yml"
272 done
273 fi
274​
275 - name: Upload build artifacts
276 uses: actions/upload-artifact@v7
277 with:
278 name: desktop-${{ matrix.platform }}-${{ matrix.arch }}
279 path: release-publish/*
280 if-no-files-found: error
281​
282 publish_cli:
283 name: Publish CLI to npm
284 needs: [preflight, build]
285 runs-on: ubuntu-24.04
286 timeout-minutes: 10
287 steps:
288 - name: Checkout
289 uses: actions/checkout@v6
290 with:
291 ref: ${{ needs.preflight.outputs.ref }}
292​
293 - name: Setup Bun
294 uses: oven-sh/setup-bun@v2
295 with:
296 bun-version-file: package.json
297​
298 - name: Setup Node
299 uses: actions/setup-node@v6
300 with:
301 node-version-file: package.json
302 registry-url: https://registry.npmjs.org
303​
304 - name: Install dependencies
305 run: bun install --frozen-lockfile
306​
307 - name: Align package versions to release version
308 run: node scripts/update-release-package-versions.ts "${{ needs.preflight.outputs.version }}"
309​
310 - name: Build CLI package
311 run: bun run build --filter=@t3tools/web --filter=t3
312​
313 - name: Publish CLI package
314 run: node apps/server/scripts/cli.ts publish --tag "${{ needs.preflight.outputs.cli_dist_tag }}" --app-version "${{ needs.preflight.outputs.version }}" --verbose
315​
316 release:
317 name: Publish GitHub Release
318 needs: [preflight, build, publish_cli]
319 runs-on: ubuntu-24.04
320 timeout-minutes: 10
321 steps:
322 - name: Checkout
323 uses: actions/checkout@v6
324 with:
325 ref: ${{ needs.preflight.outputs.ref }}
326​
327 - name: Setup Node
328 uses: actions/setup-node@v6
329 with:
330 node-version-file: package.json
331​
332 - name: Download all desktop artifacts
333 uses: actions/download-artifact@v8
334 with:
335 pattern: desktop-*
336 merge-multiple: true
337 path: release-assets
338​
339 - name: Merge macOS updater manifests
340 run: |
341 shopt -s nullglob
342 for x64_manifest in release-assets/*-mac-x64.yml; do
343 arm64_manifest="${x64_manifest%-x64.yml}.yml"
344 if [[ -f "$arm64_manifest" ]]; then
345 node scripts/merge-mac-update-manifests.ts "$arm64_manifest" "$x64_manifest"
346 rm -f "$x64_manifest"
347 fi
348 done
349​
350 - name: Publish release
351 if: needs.preflight.outputs.previous_tag != ''
352 uses: softprops/action-gh-release@v2
353 with:
354 tag_name: ${{ needs.preflight.outputs.tag }}
355 target_commitish: ${{ needs.preflight.outputs.ref }}
356 name: ${{ needs.preflight.outputs.release_name }}
357 generate_release_notes: true
358 previous_tag: ${{ needs.preflight.outputs.previous_tag }}
359 prerelease: ${{ needs.preflight.outputs.is_prerelease }}
360 make_latest: ${{ needs.preflight.outputs.make_latest }}
361 files: |
362 release-assets/*.dmg
363 release-assets/*.zip
364 release-assets/*.AppImage
365 release-assets/*.exe
366 release-assets/*.blockmap
367 release-assets/*.yml
368 fail_on_unmatched_files: true
369​
370 - name: Publish first release
371 if: needs.preflight.outputs.previous_tag == ''
372 uses: softprops/action-gh-release@v2
373 with:
374 tag_name: ${{ needs.preflight.outputs.tag }}
375 target_commitish: ${{ needs.preflight.outputs.ref }}
376 name: ${{ needs.preflight.outputs.release_name }}
377 generate_release_notes: true
378 prerelease: ${{ needs.preflight.outputs.is_prerelease }}
379 make_latest: ${{ needs.preflight.outputs.make_latest }}
380 files: |
381 release-assets/*.dmg
382 release-assets/*.zip
383 release-assets/*.AppImage
384 release-assets/*.exe
385 release-assets/*.blockmap
386 release-assets/*.yml
387 fail_on_unmatched_files: true
388​
389 finalize:
390 name: Finalize release
391 if: needs.preflight.outputs.release_channel == 'stable'
392 needs: [preflight, release]
393 runs-on: ubuntu-24.04
394 timeout-minutes: 10
395 steps:
396 - id: app_token
397 name: Mint release app token
398 uses: actions/create-github-app-token@v2
399 with:
400 app-id: ${{ secrets.RELEASE_APP_ID }}
401 private-key: ${{ secrets.RELEASE_APP_PRIVATE_KEY }}
402 owner: ${{ github.repository_owner }}
403​
404 - name: Checkout
405 uses: actions/checkout@v6
406 with:
407 ref: main
408 fetch-depth: 0
409 token: ${{ steps.app_token.outputs.token }}
410 persist-credentials: true
411​
412 - id: app_bot
413 name: Resolve GitHub App bot identity
414 env:
415 GH_TOKEN: ${{ steps.app_token.outputs.token }}
416 APP_SLUG: ${{ steps.app_token.outputs.app-slug }}
417 run: |
418 user_id="$(gh api "/users/${APP_SLUG}[bot]" --jq .id)"
419 echo "name=${APP_SLUG}[bot]" >> "$GITHUB_OUTPUT"
420 echo "email=${user_id}+${APP_SLUG}[bot]@users.noreply.github.com" >> "$GITHUB_OUTPUT"
421​
422 - name: Setup Bun
423 uses: oven-sh/setup-bun@v2
424 with:
425 bun-version-file: package.json
426​
427 - name: Setup Node
428 uses: actions/setup-node@v6
429 with:
430 node-version-file: package.json
431​
432 - id: update_versions
433 name: Update version strings
434 env:
435 RELEASE_VERSION: ${{ needs.preflight.outputs.version }}
436 run: node scripts/update-release-package-versions.ts "$RELEASE_VERSION" --github-output
437​
438 - name: Format package.json files
439 if: steps.update_versions.outputs.changed == 'true'
440 run: bunx oxfmt apps/server/package.json apps/desktop/package.json apps/web/package.json packages/contracts/package.json
441​
442 - name: Refresh lockfile
443 if: steps.update_versions.outputs.changed == 'true'
444 run: bun install --lockfile-only --ignore-scripts
445​
446 - name: Commit and push version bump
447 if: steps.update_versions.outputs.changed == 'true'
448 shell: bash
449 env:
450 RELEASE_TAG: ${{ needs.preflight.outputs.tag }}
451 run: |
452 if git diff --quiet -- apps/server/package.json apps/desktop/package.json apps/web/package.json packages/contracts/package.json bun.lock; then
453 echo "No version changes to commit."
454 exit 0
455 fi
456​
457 git config user.name "${{ steps.app_bot.outputs.name }}"
458 git config user.email "${{ steps.app_bot.outputs.email }}"
459​
460 git add apps/server/package.json apps/desktop/package.json apps/web/package.json packages/contracts/package.json bun.lock
461 git commit -m "chore(release): prepare $RELEASE_TAG"
462 git push origin HEAD:main