-
Notifications
You must be signed in to change notification settings - Fork 1.4k
420 lines (368 loc) · 15.2 KB
/
publish.yml
File metadata and controls
420 lines (368 loc) · 15.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
name: "publish"
# change this when ready to release if you want CI/CD
on:
workflow_dispatch:
inputs:
interactionId:
description: "Discord Interaction ID"
required: false
type: string
windowsTarget:
description: "Windows build target"
required: false
default: all
type: choice
options:
- all
- x64
- arm64
buildMac:
description: "Build macOS installers"
required: false
default: true
type: boolean
env:
APP_CARGO_TOML: apps/desktop/src-tauri/Cargo.toml
SENTRY_ORG: cap-s2
SENTRY_PROJECT: cap-desktop
jobs:
draft:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.read_version.outputs.value }}
needs_release: ${{ steps.create_tag.outputs.tag_existed != 'true' }}
gh_release_url: ${{ steps.create_gh_release.outputs.url }}
permissions:
contents: write
id-token: write
steps:
- uses: actions/checkout@v4
- name: Read version number
uses: SebRollen/toml-action@v1.0.2
id: read_version
with:
file: ${{ env.APP_CARGO_TOML }}
field: "package.version"
- name: Create tag
id: create_tag
uses: actions/github-script@v7
with:
script: |
const version = "${{ steps.read_version.outputs.value }}";
const tag = `cap-v${version}`;
const tagRef = `tags/${tag}`;
const appCargoToml = "${{ env.APP_CARGO_TOML }}";
const TAG_EXISTED = "tag_existed";
const TAG_NAME = "tag_name";
core.setOutput(TAG_NAME, tag);
async function main() {
let tagExisted = true;
try {
await github.rest.git.getRef({
ref: tagRef,
owner: context.repo.owner,
repo: context.repo.repo,
});
core.notice(
`Release skipped as tag '${tag}' already exists. Update the version in '${appCargoToml}' before starting another release.`,
);
} catch (error) {
if ("status" in error && error.status === 404) {
tagExisted = false;
} else {
throw error;
}
}
core.setOutput(TAG_EXISTED, tagExisted);
if (!tagExisted) {
await github.rest.git.createRef({
ref: `refs/${tagRef}`,
owner: context.repo.owner,
repo: context.repo.repo,
sha: context.sha,
});
}
}
await main();
- name: Create draft GH release
id: create_gh_release
# TODO: Change to stable version when available
uses: softprops/action-gh-release@v2
with:
name: ${{ steps.read_version.outputs.value }}
tag_name: ${{ steps.create_tag.outputs.tag_name }}
draft: true
generate_release_notes: true
- name: Update Discord interaction
if: ${{ inputs.interactionId != '' }}
uses: actions/github-script@v7
with:
script: |
async function main() {
const token = await core.getIDToken("cap-discord-bot");
const resp = await fetch(
"https://cap-discord-bot.brendonovich.workers.dev/github-workflow",
{
method: "POST",
body: JSON.stringify({
type: "release-ready",
tag: "${{ steps.create_tag.outputs.tag_name }}",
version: "${{ steps.read_version.outputs.value }}",
releaseUrl: "${{ steps.create_gh_release.outputs.url }}",
interactionId: "${{ inputs.interactionId }}",
}),
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${token}`,
},
},
);
if (resp.status !== 200) {
throw new Error(await resp.text());
}
}
await main();
build:
needs: draft
if: ${{ needs.draft.outputs.needs_release == 'true' }}
permissions:
contents: write
actions: read
strategy:
fail-fast: false
matrix:
settings:
- target: x86_64-apple-darwin
runner: macos-latest-xlarge
platform: macos
arch: x64
- target: aarch64-apple-darwin
runner: macos-latest-xlarge
platform: macos
arch: arm64
- target: x86_64-pc-windows-msvc
runner: windows-latest
platform: windows
arch: x64
- target: aarch64-pc-windows-msvc
runner: windows-latest
platform: windows
arch: arm64
env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
RUN_BUILD: ${{ (matrix.settings.platform == 'macos' && inputs.buildMac) || (matrix.settings.platform == 'windows' && (inputs.windowsTarget == 'all' || inputs.windowsTarget == matrix.settings.arch)) }}
runs-on: ${{ matrix.settings.runner }}
steps:
- name: Checkout repository
if: ${{ env.RUN_BUILD == 'true' }}
uses: actions/checkout@v4
- name: Normalize Cargo version
if: ${{ env.RUN_BUILD == 'true' }}
shell: bash
run: |
node <<'NODE'
const fs = require('node:fs');
const cargoTomlPath = 'apps/desktop/src-tauri/Cargo.toml';
const contents = fs.readFileSync(cargoTomlPath, 'utf8');
const normalized = contents.replace(
/^version\s*=\s*"cap-v([^"]+)"$/m,
'version = "$1"',
);
if (normalized !== contents) {
fs.writeFileSync(cargoTomlPath, normalized);
console.log(`Normalized ${cargoTomlPath} to semver`);
}
NODE
- name: Create API Key File
if: ${{ env.RUN_BUILD == 'true' }}
run: echo "${{ secrets.APPLE_API_KEY_FILE }}" > api.p8
- uses: apple-actions/import-codesign-certs@v2
if: ${{ env.RUN_BUILD == 'true' && matrix.settings.runner == 'macos-latest-xlarge' }}
with:
p12-file-base64: ${{ secrets.APPLE_CERTIFICATE }}
p12-password: ${{ secrets.APPLE_CERTIFICATE_PASSWORD }}
- name: Verify certificate
if: ${{ env.RUN_BUILD == 'true' && matrix.settings.runner == 'macos-latest-xlarge' }}
run: security find-identity -v -p codesigning ${{ runner.temp }}/build.keychain
- name: Rust setup
if: ${{ env.RUN_BUILD == 'true' }}
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.settings.target }}
- uses: ./.github/actions/setup-rust-cache
if: ${{ env.RUN_BUILD == 'true' }}
with:
target: ${{ matrix.settings.target }}
- uses: ./.github/actions/setup-js
if: ${{ env.RUN_BUILD == 'true' }}
- name: Create .env file in root
if: ${{ env.RUN_BUILD == 'true' }}
run: |
echo "appVersion=${{ needs.draft.outputs.version }}" >> .env
echo "VITE_ENVIRONMENT=production" >> .env
echo "CAP_DESKTOP_SENTRY_URL=https://6a3b6a09e6ae976c2ad6fff710e88748@o4506859771527168.ingest.us.sentry.io/4508330917101568" >> .env
echo "NEXT_PUBLIC_WEB_URL=${{ secrets.NEXT_PUBLIC_WEB_URL }}" >> .env
echo 'NEXTAUTH_URL=${{ secrets.NEXT_PUBLIC_WEB_URL }}' >> .env
echo 'VITE_POSTHOG_KEY=${{ secrets.VITE_POSTHOG_KEY }}' >> .env
echo 'VITE_POSTHOG_HOST=${{ secrets.VITE_POSTHOG_HOST }}' >> .env
echo 'VITE_SERVER_URL=${{ secrets.NEXT_PUBLIC_WEB_URL }}' >> .env
echo 'RUST_TARGET_TRIPLE=${{ matrix.settings.target }}' >> .env
- name: Prepare Tauri build config
if: ${{ env.RUN_BUILD == 'true' }}
shell: node {0}
env:
RAW_TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY }}
run: |
const fs = require("node:fs");
const path = require("node:path");
const workspace = process.env.GITHUB_WORKSPACE;
const sourceConfigPath = path.join(workspace, "apps/desktop/src-tauri/tauri.prod.conf.json");
const buildConfigPath = path.join(workspace, "apps/desktop/src-tauri/tauri.build.conf.json");
const config = JSON.parse(fs.readFileSync(sourceConfigPath, "utf8"));
const raw = (process.env.RAW_TAURI_SIGNING_PRIVATE_KEY || "").trim();
const candidates = raw
? new Set([raw, raw.replace(/\\n/g, "\n")])
: new Set();
if (raw && /^[A-Za-z0-9+/=\r\n]+$/.test(raw) && !raw.includes("untrusted comment:")) {
try {
const decoded = Buffer.from(raw.replace(/\s+/g, ""), "base64").toString("utf8");
candidates.add(decoded);
candidates.add(decoded.replace(/\\n/g, "\n"));
} catch {}
}
const key = [...candidates].find(
(value) =>
value.includes("untrusted comment:") &&
value.toLowerCase().includes("minisign secret key"),
);
if (key) {
fs.appendFileSync(
process.env.GITHUB_ENV,
`TAURI_SIGNING_PRIVATE_KEY<<__TAURI_KEY__\n${key}\n__TAURI_KEY__\n`,
);
} else {
config.plugins ??= {};
config.plugins.updater ??= {};
config.plugins.updater.active = false;
config.bundle ??= {};
config.bundle.createUpdaterArtifacts = false;
}
fs.writeFileSync(buildConfigPath, `${JSON.stringify(config, null, 2)}\n`);
- name: Build app
if: ${{ env.RUN_BUILD == 'true' }}
working-directory: apps/desktop
run: |
pnpm -w cap-setup
pnpm build:tauri --target ${{ matrix.settings.target }} --config src-tauri/tauri.build.conf.json
env:
# https://github.com/tauri-apps/tauri-action/issues/740
CI: false
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# codesigning
APPLE_CERTIFICATE: ${{ secrets.APPLE_CERTIFICATE }}
APPLE_CERTIFICATE_PASSWORD: ${{ secrets.APPLE_CERTIFICATE_PASSWORD }}
APPLE_SIGNING_IDENTITY: ${{ secrets.APPLE_SIGNING_IDENTITY }}
# notarization
APPLE_API_ISSUER: ${{ secrets.APPLE_API_ISSUER }}
APPLE_API_KEY: ${{ secrets.APPLE_API_KEY }}
APPLE_API_KEY_PATH: ${{ github.workspace }}/api.p8
APPLE_KEYCHAIN: ${{ runner.temp }}/build.keychain
TAURI_SIGNING_PRIVATE_KEY_PASSWORD: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY_PASSWORD }}
# - name: Upload unsigned Windows installer
# if: ${{ runner.os == 'Windows' }}
# id: upload_unsigned_windows_installer
# uses: actions/upload-artifact@v4
# with:
# name: unsigned-windows-installer
# path: target/${{ matrix.settings.target }}/release/bundle/nsis/*.exe
# if-no-files-found: error
# - name: Submit SignPath signing request
# if: ${{ runner.os == 'Windows' }}
# id: submit_signpath_signing_request
# uses: signpath/github-action-submit-signing-request@v1
# with:
# api-token: ${{ secrets.SIGNPATH_API_TOKEN }}
# organization-id: ${{ secrets.SIGNPATH_ORGANIZATION_ID }}
# project-slug: ${{ secrets.SIGNPATH_PROJECT_SLUG }}
# signing-policy-slug: ${{ secrets.SIGNPATH_SIGNING_POLICY_SLUG }}
# github-artifact-id: ${{ steps.upload_unsigned_windows_installer.outputs.artifact-id }}
# wait-for-completion: true
# output-artifact-directory: signed-windows-installer
# - name: Restore signed Windows installer
# if: ${{ runner.os == 'Windows' }}
# shell: pwsh
# run: |
# $signedDir = "signed-windows-installer"
# $bundleDir = "target/${{ matrix.settings.target }}/release/bundle/nsis"
# if (-not (Test-Path $signedDir)) {
# throw "Signed artifact directory '$signedDir' not found."
# }
# $executables = Get-ChildItem -Path $signedDir -Filter *.exe -Recurse
# if (-not $executables) {
# throw "No signed executables found in '$signedDir'."
# }
# # Copy signed executables back to the original bundle location for CrabNebula upload
# Write-Host "Copying signed executables to: $bundleDir"
# Copy-Item -Path (Join-Path $signedDir '*.exe') -Destination $bundleDir -Force
# # List the files to verify
# Write-Host "Files in bundle directory after signing:"
# Get-ChildItem -Path $bundleDir -Filter *.exe | ForEach-Object { Write-Host " - $($_.Name)" }
- name: Upload Windows ARM installer artifact
if: ${{ env.RUN_BUILD == 'true' && matrix.settings.platform == 'windows' && matrix.settings.arch == 'arm64' }}
uses: actions/upload-artifact@v4
with:
name: windows-arm-installer
path: target/${{ matrix.settings.target }}/release/bundle/nsis/*.exe
if-no-files-found: error
- uses: matbour/setup-sentry-cli@8ef22a4ff03bcd1ebbcaa3a36a81482ca8e3872e
if: ${{ env.RUN_BUILD == 'true' }}
- name: Upload debug symbols to Sentry
if: ${{ env.RUN_BUILD == 'true' && runner.os == 'macOS' }}
shell: bash
env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
run: |
sentry-cli debug-files upload -o ${{ env.SENTRY_ORG }} -p ${{ env.SENTRY_PROJECT }} target/Cap.dSYM
- name: Upload debug symbols to Sentry
if: ${{ env.RUN_BUILD == 'true' && runner.os == 'Windows' }}
shell: bash
env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
run: |
sentry-cli debug-files upload -o ${{ env.SENTRY_ORG }} -p ${{ env.SENTRY_PROJECT }} target/${{ matrix.settings.target }}/release/cap_desktop.pdb
done:
needs: [draft, build]
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
steps:
- name: Send Discord notification
if: ${{ inputs.interactionId != '' }}
uses: actions/github-script@v7
with:
script: |
async function main() {
const token = await core.getIDToken("cap-discord-bot");
const resp = await fetch(
"https://cap-discord-bot.brendonovich.workers.dev/github-workflow",
{
method: "POST",
body: JSON.stringify({
type: "release-done",
interactionId: "${{ inputs.interactionId }}",
version: "${{ needs.draft.outputs.version }}",
releaseUrl: "${{ needs.draft.outputs.gh_release_url }}",
}),
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${token}`,
},
},
);
if (resp.status !== 200) {
throw new Error(await resp.text());
}
}
await main();