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

release.yml

586 lines20.9 KB

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