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

release.yml

377 lines11.9 KB

1name: Release Desktop
2​
3on:
4 push:
5 tags:
6 - "v*.*.*"
7 workflow_dispatch:
8 inputs:
9 version:
10 description: "Release version (for example 1.2.3 or v1.2.3)"
11 required: true
12 type: string
13​
14permissions:
15 contents: write
16 id-token: write
17​
18jobs:
19 preflight:
20 name: Preflight
21 runs-on: ubuntu-24.04
22 outputs:
23 version: ${{ steps.release_meta.outputs.version }}
24 tag: ${{ steps.release_meta.outputs.tag }}
25 is_prerelease: ${{ steps.release_meta.outputs.is_prerelease }}
26 make_latest: ${{ steps.release_meta.outputs.make_latest }}
27 ref: ${{ github.sha }}
28 steps:
29 - name: Checkout
30 uses: actions/checkout@v4
31​
32 - id: release_meta
33 name: Resolve release version
34 shell: bash
35 run: |
36 if [[ "${GITHUB_EVENT_NAME}" == "workflow_dispatch" ]]; then
37 raw="${{ github.event.inputs.version }}"
38 else
39 raw="${GITHUB_REF_NAME}"
40 fi
41​
42 version="${raw#v}"
43 if [[ ! "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+([.-][0-9A-Za-z.-]+)?$ ]]; then
44 echo "Invalid release version: $raw" >&2
45 exit 1
46 fi
47​
48 echo "version=$version" >> "$GITHUB_OUTPUT"
49 echo "tag=v$version" >> "$GITHUB_OUTPUT"
50 if [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
51 echo "is_prerelease=false" >> "$GITHUB_OUTPUT"
52 echo "make_latest=true" >> "$GITHUB_OUTPUT"
53 else
54 echo "is_prerelease=true" >> "$GITHUB_OUTPUT"
55 echo "make_latest=false" >> "$GITHUB_OUTPUT"
56 fi
57​
58 - name: Setup Bun
59 uses: oven-sh/setup-bun@v2
60 with:
61 bun-version-file: package.json
62​
63 - name: Setup Node
64 uses: actions/setup-node@v4
65 with:
66 node-version-file: package.json
67​
68 - name: Install dependencies
69 run: bun install --frozen-lockfile
70​
71 - name: Lint
72 run: bun run lint
73​
74 - name: Typecheck
75 run: bun run typecheck
76​
77 - name: Test
78 run: bun run test
79​
80 build:
81 name: Build ${{ matrix.label }}
82 needs: preflight
83 runs-on: ${{ matrix.runner }}
84 strategy:
85 fail-fast: false
86 matrix:
87 include:
88 - label: macOS arm64
89 runner: macos-14
90 platform: mac
91 target: dmg
92 arch: arm64
93 - label: macOS x64
94 runner: macos-15-intel
95 platform: mac
96 target: dmg
97 arch: x64
98 - label: Linux x64
99 runner: ubuntu-24.04
100 platform: linux
101 target: AppImage
102 arch: x64
103 - label: Windows x64
104 runner: windows-2022
105 platform: win
106 target: nsis
107 arch: x64
108 steps:
109 - name: Checkout
110 uses: actions/checkout@v4
111 with:
112 ref: ${{ needs.preflight.outputs.ref }}
113 fetch-depth: 0
114​
115 - name: Setup Bun
116 uses: oven-sh/setup-bun@v2
117 with:
118 bun-version-file: package.json
119​
120 - name: Setup Node
121 uses: actions/setup-node@v4
122 with:
123 node-version-file: package.json
124​
125 - name: Install dependencies
126 run: bun install --frozen-lockfile
127​
128 - name: Build desktop artifact
129 shell: bash
130 env:
131 CSC_LINK: ${{ secrets.CSC_LINK }}
132 CSC_KEY_PASSWORD: ${{ secrets.CSC_KEY_PASSWORD }}
133 APPLE_API_KEY: ${{ secrets.APPLE_API_KEY }}
134 APPLE_API_KEY_ID: ${{ secrets.APPLE_API_KEY_ID }}
135 APPLE_API_ISSUER: ${{ secrets.APPLE_API_ISSUER }}
136 AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
137 AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
138 AZURE_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}
139 AZURE_TRUSTED_SIGNING_ENDPOINT: ${{ secrets.AZURE_TRUSTED_SIGNING_ENDPOINT }}
140 AZURE_TRUSTED_SIGNING_ACCOUNT_NAME: ${{ secrets.AZURE_TRUSTED_SIGNING_ACCOUNT_NAME }}
141 AZURE_TRUSTED_SIGNING_CERTIFICATE_PROFILE_NAME: ${{ secrets.AZURE_TRUSTED_SIGNING_CERTIFICATE_PROFILE_NAME }}
142 AZURE_TRUSTED_SIGNING_PUBLISHER_NAME: ${{ secrets.AZURE_TRUSTED_SIGNING_PUBLISHER_NAME }}
143 run: |
144 args=(
145 --platform "${{ matrix.platform }}"
146 --target "${{ matrix.target }}"
147 --arch "${{ matrix.arch }}"
148 --build-version "${{ needs.preflight.outputs.version }}"
149 --verbose
150 )
151​
152 has_all() {
153 for value in "$@"; do
154 if [[ -z "$value" ]]; then
155 return 1
156 fi
157 done
158 return 0
159 }
160​
161 if [[ "${{ matrix.platform }}" == "mac" ]]; then
162 if has_all "$CSC_LINK" "$CSC_KEY_PASSWORD" "$APPLE_API_KEY" "$APPLE_API_KEY_ID" "$APPLE_API_ISSUER"; then
163 key_path="$RUNNER_TEMP/AuthKey_${APPLE_API_KEY_ID}.p8"
164 printf '%s' "$APPLE_API_KEY" > "$key_path"
165 export APPLE_API_KEY="$key_path"
166 echo "macOS signing enabled."
167 args+=(--signed)
168 else
169 echo "macOS signing disabled (missing one or more Apple signing secrets)."
170 fi
171 elif [[ "${{ matrix.platform }}" == "win" ]]; then
172 if has_all \
173 "$AZURE_TENANT_ID" \
174 "$AZURE_CLIENT_ID" \
175 "$AZURE_CLIENT_SECRET" \
176 "$AZURE_TRUSTED_SIGNING_ENDPOINT" \
177 "$AZURE_TRUSTED_SIGNING_ACCOUNT_NAME" \
178 "$AZURE_TRUSTED_SIGNING_CERTIFICATE_PROFILE_NAME" \
179 "$AZURE_TRUSTED_SIGNING_PUBLISHER_NAME"; then
180 echo "Windows signing enabled (Azure Trusted Signing)."
181 args+=(--signed)
182 else
183 echo "Windows signing disabled (missing one or more Azure Trusted Signing secrets)."
184 fi
185 else
186 echo "Signing disabled for ${{ matrix.platform }}."
187 fi
188​
189 bun run dist:desktop:artifact -- "${args[@]}"
190​
191 - name: Collect release assets
192 shell: bash
193 run: |
194 set -euo pipefail
195 mkdir -p release-publish
196​
197 shopt -s nullglob
198 for pattern in \
199 "release/*.dmg" \
200 "release/*.zip" \
201 "release/*.AppImage" \
202 "release/*.exe" \
203 "release/*.blockmap" \
204 "release/latest*.yml"; do
205 for file in $pattern; do
206 cp "$file" release-publish/
207 done
208 done
209​
210 if [[ "${{ matrix.platform }}" == "mac" && "${{ matrix.arch }}" != "arm64" ]]; then
211 if [[ -f release-publish/latest-mac.yml ]]; then
212 mv release-publish/latest-mac.yml "release-publish/latest-mac-${{ matrix.arch }}.yml"
213 fi
214 fi
215​
216 - name: Upload build artifacts
217 uses: actions/upload-artifact@v4
218 with:
219 name: desktop-${{ matrix.platform }}-${{ matrix.arch }}
220 path: release-publish/*
221 if-no-files-found: error
222​
223 publish_cli:
224 name: Publish CLI to npm
225 needs: [preflight, build]
226 runs-on: ubuntu-24.04
227 steps:
228 - name: Checkout
229 uses: actions/checkout@v4
230 with:
231 ref: ${{ needs.preflight.outputs.ref }}
232​
233 - name: Setup Bun
234 uses: oven-sh/setup-bun@v2
235 with:
236 bun-version-file: package.json
237​
238 - name: Setup Node
239 uses: actions/setup-node@v4
240 with:
241 node-version-file: package.json
242 registry-url: https://registry.npmjs.org
243​
244 - name: Install dependencies
245 run: bun install --frozen-lockfile
246​
247 - name: Build CLI package
248 run: bun run build --filter=@t3tools/web --filter=t3
249​
250 - name: Publish CLI package
251 run: node apps/server/scripts/cli.ts publish --tag latest --app-version "${{ needs.preflight.outputs.version }}" --verbose
252​
253 release:
254 name: Publish GitHub Release
255 needs: [preflight, build, publish_cli]
256 runs-on: ubuntu-24.04
257 steps:
258 - name: Checkout
259 uses: actions/checkout@v4
260 with:
261 ref: ${{ needs.preflight.outputs.ref }}
262​
263 - name: Setup Node
264 uses: actions/setup-node@v4
265 with:
266 node-version-file: package.json
267​
268 - name: Download all desktop artifacts
269 uses: actions/download-artifact@v4
270 with:
271 pattern: desktop-*
272 merge-multiple: true
273 path: release-assets
274​
275 - name: Merge macOS updater manifests
276 run: |
277 node scripts/merge-mac-update-manifests.ts \
278 release-assets/latest-mac.yml \
279 release-assets/latest-mac-x64.yml
280 rm -f release-assets/latest-mac-x64.yml
281​
282 - name: Publish release
283 uses: softprops/action-gh-release@v2
284 with:
285 tag_name: ${{ needs.preflight.outputs.tag }}
286 target_commitish: ${{ needs.preflight.outputs.ref }}
287 name: T3 Code v${{ needs.preflight.outputs.version }}
288 generate_release_notes: true
289 prerelease: ${{ needs.preflight.outputs.is_prerelease }}
290 make_latest: ${{ needs.preflight.outputs.make_latest }}
291 files: |
292 release-assets/*.dmg
293 release-assets/*.zip
294 release-assets/*.AppImage
295 release-assets/*.exe
296 release-assets/*.blockmap
297 release-assets/latest*.yml
298 fail_on_unmatched_files: true
299​
300 finalize:
301 name: Finalize release
302 needs: [preflight, release]
303 runs-on: ubuntu-24.04
304 steps:
305 - name: Checkout
306 uses: actions/checkout@v4
307 with:
308 ref: main
309 fetch-depth: 0
310​
311 - name: Setup Bun
312 uses: oven-sh/setup-bun@v2
313 with:
314 bun-version-file: package.json
315​
316 - name: Setup Node
317 uses: actions/setup-node@v4
318 with:
319 node-version-file: package.json
320​
321 - id: update_versions
322 name: Update version strings
323 env:
324 RELEASE_VERSION: ${{ needs.preflight.outputs.version }}
325 run: |
326 node --input-type=module -e '
327 import { appendFileSync, readFileSync, writeFileSync } from "node:fs";
328​
329 const files = [
330 "apps/server/package.json",
331 "apps/desktop/package.json",
332 "apps/web/package.json",
333 "packages/contracts/package.json",
334 ];
335​
336 let changed = false;
337 for (const file of files) {
338 const packageJson = JSON.parse(readFileSync(file, "utf8"));
339 if (packageJson.version !== process.env.RELEASE_VERSION) {
340 packageJson.version = process.env.RELEASE_VERSION;
341 writeFileSync(file, `${JSON.stringify(packageJson, null, 2)}\n`);
342 changed = true;
343 }
344 }
345​
346 if (!changed) {
347 console.log("All package.json versions already match release version.");
348 }
349​
350 appendFileSync(process.env.GITHUB_OUTPUT, `changed=${changed}\n`);
351 '
352​
353 - name: Format package.json files
354 if: steps.update_versions.outputs.changed == 'true'
355 run: bunx oxfmt apps/server/package.json apps/desktop/package.json apps/web/package.json packages/contracts/package.json
356​
357 - name: Refresh lockfile
358 if: steps.update_versions.outputs.changed == 'true'
359 run: bun install
360​
361 - name: Commit and push version bump
362 if: steps.update_versions.outputs.changed == 'true'
363 shell: bash
364 env:
365 RELEASE_TAG: ${{ needs.preflight.outputs.tag }}
366 run: |
367 if git diff --quiet -- apps/server/package.json apps/desktop/package.json apps/web/package.json packages/contracts/package.json bun.lock; then
368 echo "No version changes to commit."
369 exit 0
370 fi
371​
372 git config user.name "github-actions[bot]"
373 git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
374​
375 git add apps/server/package.json apps/desktop/package.json apps/web/package.json packages/contracts/package.json bun.lock
376 git commit -m "chore(release): prepare $RELEASE_TAG"
377 git push origin HEAD:main