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

release.yml

309 lines9.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: ${{ steps.release_ref.outputs.value }}
26 steps:
27 - name: Checkout
28 uses: actions/checkout@v4
29 with:
30 fetch-depth: 0
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​
51 - name: Setup Bun
52 uses: oven-sh/setup-bun@v2
53 with:
54 bun-version-file: package.json
55​
56 - name: Setup Node
57 uses: actions/setup-node@v4
58 with:
59 node-version-file: package.json
60​
61 - name: Update version strings
62 if: github.event_name == 'workflow_dispatch'
63 env:
64 RELEASE_VERSION: ${{ steps.release_meta.outputs.version }}
65 run: |
66 node --input-type=module -e '
67 import { readFileSync, writeFileSync } from "node:fs";
68​
69 const files = [
70 "apps/server/package.json",
71 "apps/desktop/package.json",
72 "apps/web/package.json",
73 "packages/contracts/package.json",
74 ];
75​
76 for (const file of files) {
77 const packageJson = JSON.parse(readFileSync(file, "utf8"));
78 packageJson.version = process.env.RELEASE_VERSION;
79 writeFileSync(file, `${JSON.stringify(packageJson, null, 2)}\n`);
80 }
81 '
82​
83 - name: Refresh lockfile
84 if: github.event_name == 'workflow_dispatch'
85 run: bun install
86​
87 - name: Install dependencies
88 run: bun install --frozen-lockfile
89​
90 - name: Lint
91 run: bun run lint
92​
93 - name: Typecheck
94 run: bun run typecheck
95​
96 - name: Test
97 run: bun run test
98​
99 - name: Commit and push release version + tag
100 if: github.event_name == 'workflow_dispatch'
101 shell: bash
102 env:
103 RELEASE_TAG: ${{ steps.release_meta.outputs.tag }}
104 run: |
105 if git ls-remote --exit-code --tags origin "$RELEASE_TAG" >/dev/null 2>&1; then
106 echo "Tag $RELEASE_TAG already exists on origin." >&2
107 exit 1
108 fi
109​
110 git config user.name "github-actions[bot]"
111 git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
112​
113 if ! git diff --quiet -- apps/server/package.json apps/desktop/package.json apps/web/package.json packages/contracts/package.json bun.lock; then
114 git add apps/server/package.json apps/desktop/package.json apps/web/package.json packages/contracts/package.json bun.lock
115 git commit -m "chore(release): prepare $RELEASE_TAG" -m "Co-authored-by: codex <codex@users.noreply.github.com>"
116 fi
117​
118 git tag "$RELEASE_TAG"
119 git push origin "HEAD:${GITHUB_REF_NAME}"
120 git push origin "refs/tags/$RELEASE_TAG"
121​
122 - id: release_ref
123 name: Resolve source ref
124 shell: bash
125 run: |
126 if [[ "${GITHUB_EVENT_NAME}" == "workflow_dispatch" ]]; then
127 echo "value=refs/tags/${{ steps.release_meta.outputs.tag }}" >> "$GITHUB_OUTPUT"
128 else
129 echo "value=${GITHUB_SHA}" >> "$GITHUB_OUTPUT"
130 fi
131​
132 build:
133 name: Build ${{ matrix.label }}
134 needs: preflight
135 runs-on: ${{ matrix.runner }}
136 strategy:
137 fail-fast: false
138 matrix:
139 include:
140 - label: macOS arm64
141 runner: macos-14
142 platform: mac
143 target: dmg
144 arch: arm64
145 - label: macOS x64
146 runner: macos-15-intel
147 platform: mac
148 target: dmg
149 arch: x64
150 - label: Linux x64
151 runner: ubuntu-24.04
152 platform: linux
153 target: AppImage
154 arch: x64
155 - label: Windows x64
156 runner: windows-2022
157 platform: win
158 target: nsis
159 arch: x64
160 steps:
161 - name: Checkout
162 uses: actions/checkout@v4
163 with:
164 ref: ${{ needs.preflight.outputs.ref }}
165 fetch-depth: 0
166​
167 - name: Setup Bun
168 uses: oven-sh/setup-bun@v2
169 with:
170 bun-version-file: package.json
171​
172 - name: Setup Node
173 uses: actions/setup-node@v4
174 with:
175 node-version-file: package.json
176​
177 - name: Install dependencies
178 run: bun install --frozen-lockfile
179​
180 - name: Build desktop artifact
181 shell: bash
182 env:
183 CSC_LINK: ${{ secrets.CSC_LINK }}
184 CSC_KEY_PASSWORD: ${{ secrets.CSC_KEY_PASSWORD }}
185 APPLE_API_KEY: ${{ secrets.APPLE_API_KEY }}
186 APPLE_API_KEY_ID: ${{ secrets.APPLE_API_KEY_ID }}
187 APPLE_API_ISSUER: ${{ secrets.APPLE_API_ISSUER }}
188 AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
189 AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
190 AZURE_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}
191 AZURE_TRUSTED_SIGNING_ENDPOINT: ${{ secrets.AZURE_TRUSTED_SIGNING_ENDPOINT }}
192 AZURE_TRUSTED_SIGNING_ACCOUNT_NAME: ${{ secrets.AZURE_TRUSTED_SIGNING_ACCOUNT_NAME }}
193 AZURE_TRUSTED_SIGNING_CERTIFICATE_PROFILE_NAME: ${{ secrets.AZURE_TRUSTED_SIGNING_CERTIFICATE_PROFILE_NAME }}
194 AZURE_TRUSTED_SIGNING_PUBLISHER_NAME: ${{ secrets.AZURE_TRUSTED_SIGNING_PUBLISHER_NAME }}
195 run: |
196 args=(
197 --platform "${{ matrix.platform }}"
198 --target "${{ matrix.target }}"
199 --arch "${{ matrix.arch }}"
200 --build-version "${{ needs.preflight.outputs.version }}"
201 )
202​
203 has_all() {
204 for value in "$@"; do
205 if [[ -z "$value" ]]; then
206 return 1
207 fi
208 done
209 return 0
210 }
211​
212 if [[ "${{ matrix.platform }}" == "mac" ]]; then
213 if has_all "$CSC_LINK" "$CSC_KEY_PASSWORD" "$APPLE_API_KEY" "$APPLE_API_KEY_ID" "$APPLE_API_ISSUER"; then
214 key_path="$RUNNER_TEMP/AuthKey_${APPLE_API_KEY_ID}.p8"
215 printf '%s' "$APPLE_API_KEY" > "$key_path"
216 export APPLE_API_KEY="$key_path"
217 echo "macOS signing enabled."
218 args+=(--signed)
219 else
220 echo "macOS signing disabled (missing one or more Apple signing secrets)."
221 fi
222 elif [[ "${{ matrix.platform }}" == "win" ]]; then
223 if has_all \
224 "$AZURE_TENANT_ID" \
225 "$AZURE_CLIENT_ID" \
226 "$AZURE_CLIENT_SECRET" \
227 "$AZURE_TRUSTED_SIGNING_ENDPOINT" \
228 "$AZURE_TRUSTED_SIGNING_ACCOUNT_NAME" \
229 "$AZURE_TRUSTED_SIGNING_CERTIFICATE_PROFILE_NAME" \
230 "$AZURE_TRUSTED_SIGNING_PUBLISHER_NAME"; then
231 echo "Windows signing enabled (Azure Trusted Signing)."
232 args+=(--signed)
233 else
234 echo "Windows signing disabled (missing one or more Azure Trusted Signing secrets)."
235 fi
236 else
237 echo "Signing disabled for ${{ matrix.platform }}."
238 fi
239​
240 bun run dist:desktop:artifact -- "${args[@]}"
241​
242 - name: Upload build artifacts
243 uses: actions/upload-artifact@v4
244 with:
245 name: desktop-${{ matrix.platform }}-${{ matrix.arch }}
246 path: release/*
247 if-no-files-found: error
248​
249 # publish_cli:
250 # name: Publish CLI to npm
251 # needs: [preflight, build]
252 # runs-on: ubuntu-24.04
253 # steps:
254 # - name: Checkout
255 # uses: actions/checkout@v4
256​
257 # - name: Setup Bun
258 # uses: oven-sh/setup-bun@v2
259 # with:
260 # bun-version-file: package.json
261​
262 # - name: Setup Node
263 # uses: actions/setup-node@v4
264 # with:
265 # node-version-file: package.json
266 # registry-url: https://registry.npmjs.org
267​
268 # - name: Install dependencies
269 # run: bun install --frozen-lockfile
270​
271 # - name: Set CLI package version from release tag
272 # env:
273 # RELEASE_VERSION: ${{ needs.preflight.outputs.version }}
274 # run: |
275 # node --input-type=module -e '
276 # import { readFileSync, writeFileSync } from "node:fs";
277 # const packagePath = "apps/server/package.json";
278 # const packageJson = JSON.parse(readFileSync(packagePath, "utf8"));
279 # packageJson.version = process.env.RELEASE_VERSION;
280 # writeFileSync(packagePath, `${JSON.stringify(packageJson, null, 2)}\n`);
281 # '
282​
283 # - name: Build CLI package
284 # run: bun run build --filter=@t3tools/web --filter=t3
285​
286 # - name: Publish CLI package
287 # run: bun --cwd apps/server publish --access public
288​
289 release:
290 name: Publish GitHub Release
291 needs: [preflight, build]
292 # needs: [preflight, build, publish_cli]
293 runs-on: ubuntu-24.04
294 steps:
295 - name: Download all desktop artifacts
296 uses: actions/download-artifact@v4
297 with:
298 pattern: desktop-*
299 merge-multiple: true
300 path: release-assets
301​
302 - name: Publish release
303 uses: softprops/action-gh-release@v2
304 with:
305 tag_name: ${{ needs.preflight.outputs.tag }}
306 name: T3 Code v${{ needs.preflight.outputs.version }}
307 generate_release_notes: true
308 files: release-assets/*
309 fail_on_unmatched_files: true