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

release.yml

587 lines20.9 KB

1name: Release
2​
3on:
4 push:
5 tags:
6 - "v*.*.*"
7 - "!v*-nightly.*"
8 schedule:
9 - cron: "0 */3 * * *"
10 workflow_dispatch:
11 inputs:
12 channel:
13 description: "Release channel"
14 required: false
15 default: stable
16 type: choice
17 options:
18 - stable
19 - nightly
20 version:
21 description: "Release version (for example 1.2.3 or v1.2.3)"
22 required: false
23 type: string
24​
25permissions:
26 contents: write
27 id-token: write
28​
29jobs:
30 check_changes:
31 name: Check for changes since last nightly
32 if: github.event_name == 'schedule'
33 runs-on: ubuntu-24.04
34 outputs:
35 has_changes: ${{ steps.check.outputs.has_changes }}
36 steps:
37 - name: Checkout
38 uses: actions/checkout@v6
39 with:
40 fetch-depth: 0
41​
42 - id: check
43 name: Compare HEAD to last nightly tag
44 run: |
45 last_nightly_tag=$(git tag --list 'v*-nightly.*' 'nightly-v*' --sort=-creatordate | head -n 1)
46 if [[ -z "$last_nightly_tag" ]]; then
47 echo "No previous nightly tag found. Proceeding with release."
48 echo "has_changes=true" >> "$GITHUB_OUTPUT"
49 exit 0
50 fi
51​
52 last_nightly_sha=$(git rev-parse "$last_nightly_tag^{commit}")
53 head_sha=$(git rev-parse HEAD)
54​
55 if [[ "$last_nightly_sha" == "$head_sha" ]]; then
56 echo "No changes on main since last nightly release ($last_nightly_tag). Skipping."
57 echo "has_changes=false" >> "$GITHUB_OUTPUT"
58 else
59 echo "Changes detected on main since $last_nightly_tag ($last_nightly_sha → $head_sha). Proceeding."
60 echo "has_changes=true" >> "$GITHUB_OUTPUT"
61 fi
62​
63 preflight:
64 name: Preflight
65 needs: [check_changes]
66 if: |
67 !failure() && !cancelled() &&
68 (github.event_name != 'schedule' || needs.check_changes.outputs.has_changes == 'true')
69 runs-on: blacksmith-8vcpu-ubuntu-2404
70 timeout-minutes: 10
71 outputs:
72 release_channel: ${{ steps.release_meta.outputs.release_channel }}
73 version: ${{ steps.release_meta.outputs.version }}
74 tag: ${{ steps.release_meta.outputs.tag }}
75 release_name: ${{ steps.release_meta.outputs.name }}
76 short_sha: ${{ steps.release_meta.outputs.short_sha }}
77 previous_tag: ${{ steps.previous_tag.outputs.previous_tag }}
78 cli_dist_tag: ${{ steps.release_meta.outputs.cli_dist_tag }}
79 is_prerelease: ${{ steps.release_meta.outputs.is_prerelease }}
80 make_latest: ${{ steps.release_meta.outputs.make_latest }}
81 ref: ${{ github.sha }}
82 steps:
83 - name: Checkout
84 uses: actions/checkout@v6
85 with:
86 fetch-depth: 0
87​
88 - name: Setup Bun
89 uses: oven-sh/setup-bun@v2
90 with:
91 bun-version-file: package.json
92​
93 - name: Setup Node
94 uses: actions/setup-node@v6
95 with:
96 node-version-file: package.json
97​
98 - name: Install dependencies
99 run: bun install --frozen-lockfile
100​
101 - id: release_meta
102 name: Resolve release version
103 shell: bash
104 env:
105 DISPATCH_CHANNEL: ${{ github.event.inputs.channel }}
106 DISPATCH_VERSION: ${{ github.event.inputs.version }}
107 NIGHTLY_DATE: ${{ github.run_started_at }}
108 NIGHTLY_SHA: ${{ github.sha }}
109 NIGHTLY_RUN_NUMBER: ${{ github.run_number }}
110 run: |
111 if [[ "${GITHUB_EVENT_NAME}" == "schedule" || ( "${GITHUB_EVENT_NAME}" == "workflow_dispatch" && "${DISPATCH_CHANNEL:-stable}" == "nightly" ) ]]; then
112 nightly_date="$(date -u -d "$NIGHTLY_DATE" +%Y%m%d)"
113​
114 node scripts/resolve-nightly-release.ts \
115 --date "$nightly_date" \
116 --run-number "$NIGHTLY_RUN_NUMBER" \
117 --sha "$NIGHTLY_SHA" \
118 --github-output
119​
120 echo "release_channel=nightly" >> "$GITHUB_OUTPUT"
121 echo "cli_dist_tag=nightly" >> "$GITHUB_OUTPUT"
122 echo "is_prerelease=true" >> "$GITHUB_OUTPUT"
123 echo "make_latest=false" >> "$GITHUB_OUTPUT"
124 else
125 if [[ "${GITHUB_EVENT_NAME}" == "workflow_dispatch" ]]; then
126 raw="${DISPATCH_VERSION}"
127 if [[ -z "$raw" ]]; then
128 echo "workflow_dispatch stable releases require the version input." >&2
129 exit 1
130 fi
131 else
132 raw="${GITHUB_REF_NAME}"
133 fi
134​
135 version="${raw#v}"
136 if [[ ! "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+([.-][0-9A-Za-z.-]+)?$ ]]; then
137 echo "Invalid release version: $raw" >&2
138 exit 1
139 fi
140​
141 echo "release_channel=stable" >> "$GITHUB_OUTPUT"
142 echo "version=$version" >> "$GITHUB_OUTPUT"
143 echo "tag=v$version" >> "$GITHUB_OUTPUT"
144 echo "name=T3 Code v$version" >> "$GITHUB_OUTPUT"
145 echo "cli_dist_tag=latest" >> "$GITHUB_OUTPUT"
146 if [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
147 echo "is_prerelease=false" >> "$GITHUB_OUTPUT"
148 echo "make_latest=true" >> "$GITHUB_OUTPUT"
149 else
150 echo "is_prerelease=true" >> "$GITHUB_OUTPUT"
151 echo "make_latest=false" >> "$GITHUB_OUTPUT"
152 fi
153 fi
154​
155 - name: Lint
156 run: bun run lint
157​
158 - name: Typecheck
159 run: bun run typecheck
160​
161 - name: Test
162 run: bun run test
163​
164 - id: previous_tag
165 name: Resolve previous release tag
166 run: |
167 node scripts/resolve-previous-release-tag.ts \
168 --channel "${{ steps.release_meta.outputs.release_channel }}" \
169 --current-tag "${{ steps.release_meta.outputs.tag }}" \
170 --github-output
171​
172 build:
173 name: Build ${{ matrix.label }}
174 needs: preflight
175 if: ${{ !failure() && !cancelled() && needs.preflight.result == 'success' }}
176 runs-on: ${{ matrix.runner }}
177 timeout-minutes: 30
178 strategy:
179 fail-fast: false
180 matrix:
181 include:
182 - label: macOS arm64
183 runner: blacksmith-12vcpu-macos-26
184 platform: mac
185 target: dmg
186 arch: arm64
187 - label: macOS x64
188 runner: blacksmith-12vcpu-macos-26
189 platform: mac
190 target: dmg
191 arch: x64
192 - label: Linux x64
193 runner: blacksmith-32vcpu-ubuntu-2404
194 platform: linux
195 target: AppImage
196 arch: x64
197 - label: Windows x64
198 runner: blacksmith-32vcpu-windows-2025
199 platform: win
200 target: nsis
201 arch: x64
202 # - label: Windows arm64
203 # runner: windows-11-arm
204 # platform: win
205 # target: nsis
206 # arch: arm64
207 steps:
208 - name: Checkout
209 uses: actions/checkout@v6
210 with:
211 ref: ${{ needs.preflight.outputs.ref }}
212 fetch-depth: 0
213​
214 - name: Setup Bun
215 uses: oven-sh/setup-bun@v2
216 with:
217 bun-version-file: package.json
218​
219 - name: Setup Node
220 uses: actions/setup-node@v6
221 with:
222 node-version-file: package.json
223​
224 - name: Install dependencies
225 run: bun install --frozen-lockfile
226​
227 - name: Align package versions to release version
228 run: node scripts/update-release-package-versions.ts "${{ needs.preflight.outputs.version }}"
229​
230 - name: Install Spectre-mitigated MSVC libs
231 if: matrix.platform == 'win'
232 shell: pwsh
233 run: |
234 $vswhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
235 $installPath = & $vswhere -products * -latest -property installationPath
236 $setupExe = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\setup.exe"
237 $proc = Start-Process -FilePath $setupExe `
238 -ArgumentList "modify", "--installPath", "`"$installPath`"", "--add", `
239 "Microsoft.VisualStudio.Component.VC.Tools.x86.x64.Spectre", "--quiet", "--norestart" `
240 -Wait -PassThru -NoNewWindow
241 if ($null -eq $proc -or $proc.ExitCode -ne 0) {
242 $code = if ($null -ne $proc) { $proc.ExitCode } else { 1 }
243 Write-Error "Visual Studio Installer failed with exit code $code"
244 exit $code
245 }
246​
247 - name: Build desktop artifact
248 shell: bash
249 env:
250 CSC_LINK: ${{ secrets.CSC_LINK }}
251 CSC_KEY_PASSWORD: ${{ secrets.CSC_KEY_PASSWORD }}
252 APPLE_API_KEY: ${{ secrets.APPLE_API_KEY }}
253 APPLE_API_KEY_ID: ${{ secrets.APPLE_API_KEY_ID }}
254 APPLE_API_ISSUER: ${{ secrets.APPLE_API_ISSUER }}
255 AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
256 AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
257 AZURE_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}
258 AZURE_TRUSTED_SIGNING_ENDPOINT: ${{ secrets.AZURE_TRUSTED_SIGNING_ENDPOINT }}
259 AZURE_TRUSTED_SIGNING_ACCOUNT_NAME: ${{ secrets.AZURE_TRUSTED_SIGNING_ACCOUNT_NAME }}
260 AZURE_TRUSTED_SIGNING_CERTIFICATE_PROFILE_NAME: ${{ secrets.AZURE_TRUSTED_SIGNING_CERTIFICATE_PROFILE_NAME }}
261 AZURE_TRUSTED_SIGNING_PUBLISHER_NAME: ${{ secrets.AZURE_TRUSTED_SIGNING_PUBLISHER_NAME }}
262 run: |
263 args=(
264 --platform "${{ matrix.platform }}"
265 --target "${{ matrix.target }}"
266 --arch "${{ matrix.arch }}"
267 --build-version "${{ needs.preflight.outputs.version }}"
268 --verbose
269 )
270​
271 has_all() {
272 for value in "$@"; do
273 if [[ -z "$value" ]]; then
274 return 1
275 fi
276 done
277 return 0
278 }
279​
280 if [[ "${{ matrix.platform }}" == "mac" ]]; then
281 if has_all "$CSC_LINK" "$CSC_KEY_PASSWORD" "$APPLE_API_KEY" "$APPLE_API_KEY_ID" "$APPLE_API_ISSUER"; then
282 key_path="$RUNNER_TEMP/AuthKey_${APPLE_API_KEY_ID}.p8"
283 printf '%s' "$APPLE_API_KEY" > "$key_path"
284 export APPLE_API_KEY="$key_path"
285 echo "macOS signing enabled."
286 args+=(--signed)
287 else
288 echo "macOS signing disabled (missing one or more Apple signing secrets)."
289 fi
290 elif [[ "${{ matrix.platform }}" == "win" ]]; then
291 if has_all \
292 "$AZURE_TENANT_ID" \
293 "$AZURE_CLIENT_ID" \
294 "$AZURE_CLIENT_SECRET" \
295 "$AZURE_TRUSTED_SIGNING_ENDPOINT" \
296 "$AZURE_TRUSTED_SIGNING_ACCOUNT_NAME" \
297 "$AZURE_TRUSTED_SIGNING_CERTIFICATE_PROFILE_NAME" \
298 "$AZURE_TRUSTED_SIGNING_PUBLISHER_NAME"; then
299 echo "Windows signing enabled (Azure Trusted Signing)."
300 args+=(--signed)
301 else
302 echo "Windows signing disabled (missing one or more Azure Trusted Signing secrets)."
303 fi
304 else
305 echo "Signing disabled for ${{ matrix.platform }}."
306 fi
307​
308 bun run dist:desktop:artifact -- "${args[@]}"
309​
310 - name: Collect release assets
311 shell: bash
312 run: |
313 set -euo pipefail
314 mkdir -p release-publish
315​
316 shopt -s nullglob
317 for pattern in \
318 "release/*.dmg" \
319 "release/*.zip" \
320 "release/*.AppImage" \
321 "release/*.exe" \
322 "release/*.blockmap" \
323 "release/*.yml"; do
324 for file in $pattern; do
325 cp "$file" release-publish/
326 done
327 done
328​
329 if [[ "${{ matrix.platform }}" == "mac" && "${{ matrix.arch }}" != "arm64" ]]; then
330 shopt -s nullglob
331 for manifest in release-publish/*-mac.yml; do
332 mv "$manifest" "${manifest%.yml}-${{ matrix.arch }}.yml"
333 done
334 fi
335​
336 # Enable if Windows arm64 builds are enabled.
337 # Windows updater metadata is channel-specific (for example
338 # "latest.yml" or "nightly.yml"). Suffix each per-arch copy so the
339 # release job can merge matching arm64/x64 manifests back into one
340 # canonical manifest per channel.
341 # if [[ "${{ matrix.platform }}" == "win" ]]; then
342 # shopt -s nullglob
343 # for manifest in release-publish/*.yml; do
344 # mv "$manifest" "${manifest%.yml}-win-${{ matrix.arch }}.yml"
345 # done
346 # fi
347​
348 - name: Upload build artifacts
349 uses: actions/upload-artifact@v7
350 with:
351 name: desktop-${{ matrix.platform }}-${{ matrix.arch }}
352 path: release-publish/*
353 if-no-files-found: error
354​
355 publish_cli:
356 name: Publish CLI to npm
357 needs: [preflight, build]
358 if: ${{ !failure() && !cancelled() && needs.preflight.result == 'success' && needs.build.result == 'success' }}
359 runs-on: ubuntu-24.04 # blacksmith-8vcpu-ubuntu-2404
360 timeout-minutes: 10
361 steps:
362 - name: Checkout
363 uses: actions/checkout@v6
364 with:
365 ref: ${{ needs.preflight.outputs.ref }}
366​
367 - name: Setup Bun
368 uses: oven-sh/setup-bun@v2
369 with:
370 bun-version-file: package.json
371​
372 - name: Setup Node
373 uses: actions/setup-node@v6
374 with:
375 node-version-file: package.json
376 registry-url: https://registry.npmjs.org
377​
378 - name: Install dependencies
379 run: bun install --frozen-lockfile
380​
381 - name: Align package versions to release version
382 run: node scripts/update-release-package-versions.ts "${{ needs.preflight.outputs.version }}"
383​
384 - name: Build CLI package
385 run: bun run build --filter=@t3tools/web --filter=t3
386​
387 - name: Publish CLI package
388 run: node apps/server/scripts/cli.ts publish --tag "${{ needs.preflight.outputs.cli_dist_tag }}" --app-version "${{ needs.preflight.outputs.version }}" --verbose
389​
390 release:
391 name: Publish GitHub Release
392 needs: [preflight, build, publish_cli]
393 if: ${{ !failure() && !cancelled() && needs.preflight.result == 'success' && needs.build.result == 'success' && needs.publish_cli.result == 'success' }}
394 runs-on: ubuntu-24.04 # blacksmith-8vcpu-ubuntu-2404
395 timeout-minutes: 10
396 steps:
397 - id: app_token
398 name: Mint release app token
399 uses: actions/create-github-app-token@v2
400 with:
401 app-id: ${{ secrets.RELEASE_APP_ID }}
402 private-key: ${{ secrets.RELEASE_APP_PRIVATE_KEY }}
403 owner: ${{ github.repository_owner }}
404​
405 - name: Checkout
406 uses: actions/checkout@v6
407 with:
408 ref: ${{ needs.preflight.outputs.ref }}
409​
410 - name: Setup Bun
411 uses: oven-sh/setup-bun@v2
412 with:
413 bun-version-file: package.json
414​
415 - name: Setup Node
416 uses: actions/setup-node@v6
417 with:
418 node-version-file: package.json
419​
420 - name: Install dependencies
421 run: bun install --frozen-lockfile
422​
423 - name: Download all desktop artifacts
424 uses: actions/download-artifact@v8
425 with:
426 pattern: desktop-*
427 merge-multiple: true
428 path: release-assets
429​
430 - name: Merge macOS updater manifests
431 run: |
432 shopt -s nullglob
433 for x64_manifest in release-assets/*-mac-x64.yml; do
434 arm64_manifest="${x64_manifest%-x64.yml}.yml"
435 if [[ -f "$arm64_manifest" ]]; then
436 node scripts/merge-update-manifests.ts --platform mac "$arm64_manifest" "$x64_manifest"
437 rm -f "$x64_manifest"
438 fi
439 done
440​
441 # - name: Merge Windows updater manifests
442 # run: |
443 # shopt -s nullglob
444 # found_windows_manifest=false
445 # for x64_manifest in release-assets/*-win-x64.yml; do
446 # if [[ "$(basename "$x64_manifest")" == builder-debug-* ]]; then
447 # continue
448 # fi
449​
450 # arm64_manifest="${x64_manifest/-x64.yml/-arm64.yml}"
451 # output_manifest="${x64_manifest/-win-x64.yml/.yml}"
452 # if [[ ! -f "$arm64_manifest" ]]; then
453 # echo "Missing matching arm64 Windows manifest for $x64_manifest" >&2
454 # exit 1
455 # fi
456​
457 # found_windows_manifest=true
458 # node scripts/merge-update-manifests.ts --platform win \
459 # "$arm64_manifest" \
460 # "$x64_manifest" \
461 # "$output_manifest"
462 # rm -f "$arm64_manifest" "$x64_manifest"
463 # done
464​
465 # if [[ "$found_windows_manifest" != true ]]; then
466 # echo "No Windows updater manifests found to merge." >&2
467 # exit 1
468 # fi
469​
470 - name: Publish release
471 if: needs.preflight.outputs.previous_tag != ''
472 uses: softprops/action-gh-release@v2
473 with:
474 tag_name: ${{ needs.preflight.outputs.tag }}
475 target_commitish: ${{ needs.preflight.outputs.ref }}
476 name: ${{ needs.preflight.outputs.release_name }}
477 generate_release_notes: true
478 previous_tag: ${{ needs.preflight.outputs.previous_tag }}
479 prerelease: ${{ needs.preflight.outputs.is_prerelease }}
480 make_latest: ${{ needs.preflight.outputs.make_latest }}
481 files: |
482 release-assets/*.dmg
483 release-assets/*.zip
484 release-assets/*.AppImage
485 release-assets/*.exe
486 release-assets/*.blockmap
487 release-assets/*.yml
488 fail_on_unmatched_files: true
489 token: ${{ steps.app_token.outputs.token }}
490​
491 - name: Publish first release
492 if: needs.preflight.outputs.previous_tag == ''
493 uses: softprops/action-gh-release@v2
494 with:
495 tag_name: ${{ needs.preflight.outputs.tag }}
496 target_commitish: ${{ needs.preflight.outputs.ref }}
497 name: ${{ needs.preflight.outputs.release_name }}
498 generate_release_notes: true
499 prerelease: ${{ needs.preflight.outputs.is_prerelease }}
500 make_latest: ${{ needs.preflight.outputs.make_latest }}
501 files: |
502 release-assets/*.dmg
503 release-assets/*.zip
504 release-assets/*.AppImage
505 release-assets/*.exe
506 release-assets/*.blockmap
507 release-assets/*.yml
508 fail_on_unmatched_files: true
509 token: ${{ steps.app_token.outputs.token }}
510​
511 finalize:
512 name: Finalize release
513 if: ${{ !failure() && !cancelled() && needs.preflight.result == 'success' && needs.release.result == 'success' && needs.preflight.outputs.release_channel == 'stable' }}
514 needs: [preflight, release]
515 runs-on: blacksmith-8vcpu-ubuntu-2404
516 timeout-minutes: 10
517 steps:
518 - id: app_token
519 name: Mint release app token
520 uses: actions/create-github-app-token@v2
521 with:
522 app-id: ${{ secrets.RELEASE_APP_ID }}
523 private-key: ${{ secrets.RELEASE_APP_PRIVATE_KEY }}
524 owner: ${{ github.repository_owner }}
525​
526 - name: Checkout
527 uses: actions/checkout@v6
528 with:
529 ref: main
530 fetch-depth: 0
531 token: ${{ steps.app_token.outputs.token }}
532 persist-credentials: true
533​
534 - id: app_bot
535 name: Resolve GitHub App bot identity
536 env:
537 GH_TOKEN: ${{ steps.app_token.outputs.token }}
538 APP_SLUG: ${{ steps.app_token.outputs.app-slug }}
539 run: |
540 user_id="$(gh api "/users/${APP_SLUG}[bot]" --jq .id)"
541 echo "name=${APP_SLUG}[bot]" >> "$GITHUB_OUTPUT"
542 echo "email=${user_id}+${APP_SLUG}[bot]@users.noreply.github.com" >> "$GITHUB_OUTPUT"
543​
544 - name: Setup Bun
545 uses: oven-sh/setup-bun@v2
546 with:
547 bun-version-file: package.json
548​
549 - name: Setup Node
550 uses: actions/setup-node@v6
551 with:
552 node-version-file: package.json
553​
554 - name: Install dependencies
555 run: bun install --frozen-lockfile
556​
557 - id: update_versions
558 name: Update version strings
559 env:
560 RELEASE_VERSION: ${{ needs.preflight.outputs.version }}
561 run: node scripts/update-release-package-versions.ts "$RELEASE_VERSION" --github-output
562​
563 - name: Format package.json files
564 if: steps.update_versions.outputs.changed == 'true'
565 run: bunx oxfmt apps/server/package.json apps/desktop/package.json apps/web/package.json packages/contracts/package.json
566​
567 - name: Refresh lockfile
568 if: steps.update_versions.outputs.changed == 'true'
569 run: bun install --lockfile-only --ignore-scripts
570​
571 - name: Commit and push version bump
572 if: steps.update_versions.outputs.changed == 'true'
573 shell: bash
574 env:
575 RELEASE_TAG: ${{ needs.preflight.outputs.tag }}
576 run: |
577 if git diff --quiet -- apps/server/package.json apps/desktop/package.json apps/web/package.json packages/contracts/package.json bun.lock; then
578 echo "No version changes to commit."
579 exit 0
580 fi
581​
582 git config user.name "${{ steps.app_bot.outputs.name }}"
583 git config user.email "${{ steps.app_bot.outputs.email }}"
584​
585 git add apps/server/package.json apps/desktop/package.json apps/web/package.json packages/contracts/package.json bun.lock
586 git commit -m "chore(release): prepare $RELEASE_TAG"
587 git push origin HEAD:main