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

release.yml

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