Repository navigation
408 lines (403 loc) · 21 KB
/
Copy pathdebug.yml
File metadata and controls
408 lines (403 loc) · 21 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
name: Debug build
on:
workflow_dispatch:
inputs:
target:
description: 构建平台
type: choice
default: windowsX64
options: [windowsX64, windowsArm64, macArm64, macX64, linuxX64, linuxArm64, androidArm64, all]
ref:
description: 代码分支、标签或提交;签名构建要求与所选工作流版本为同一提交
type: string
version:
description: 包版本号(如 2.0.1),留空使用标签或项目配置
type: string
generatePatch:
description: 基于上一版本生成增量更新,尚无基线时生成首版完整包
type: boolean
default: false
androidRelease:
description: Android 发布模式(R8 与资源裁剪,关闭调试,使用默认签名)
type: boolean
default: false
workflow_call:
inputs:
target:
type: string
default: all
ref:
type: string
default: ""
version:
type: string
default: ""
generatePatch:
type: boolean
default: false
androidRelease:
type: boolean
default: false
secrets:
MACOS_CERTIFICATE_BASE64:
description: 包含 Developer ID Application 证书及对应私钥的 P12 Base64
required: false
MACOS_CERTIFICATE_PASSWORD:
description: P12 导出密码
required: false
MACOS_INSTALLER_CERTIFICATE_BASE64:
description: 包含 Developer ID Installer 证书及对应私钥的 P12 Base64
required: false
MACOS_INSTALLER_CERTIFICATE_PASSWORD:
description: Installer P12 导出密码
required: false
MACOS_NOTARIZATION_KEY_ID:
description: App Store Connect 团队 API Key ID
required: false
MACOS_NOTARIZATION_ISSUER_ID:
description: App Store Connect 团队 API Issuer ID
required: false
MACOS_NOTARIZATION_KEY_BASE64:
description: 对应 API 密钥的 P8 私钥文件 Base64
required: false
outputs:
version:
description: 实际构建的包版本号
value: ${{ jobs.prepare.outputs.version }}
commit:
description: 实际构建的提交
value: ${{ jobs.prepare.outputs.commit }}
permissions:
contents: read
defaults:
run:
shell: bash
jobs:
prepare:
name: 确定版本与平台
runs-on: ubuntu-24.04
outputs:
version: ${{ steps.config.outputs.version }}
matrix: ${{ steps.config.outputs.matrix }}
commit: ${{ steps.checkout.outputs.commit }}
steps:
- uses: actions/checkout@v7
id: checkout
with:
ref: ${{ inputs.ref || github.sha }}
persist-credentials: false
- uses: oven-sh/setup-bun@v2
with:
bun-version-file: package.json
- name: 校验构建参数
id: config
env:
buildTarget: ${{ inputs.target }}
buildRef: ${{ inputs.ref || github.ref_name }}
buildVersion: ${{ inputs.version }}
run: |
bun -e '
import { appendFileSync } from "node:fs";
import config from "./electrobun.config.ts";
const targets = [
{ target: "windowsX64", os: "windows-2025", platform: "win32", arch: "x64", releaseFolder: "build/desktop/releases" },
{ target: "windowsArm64", os: "windows-11-arm", platform: "win32", arch: "arm64", releaseFolder: "build/desktop/releases/windowsArm64" },
{ target: "macArm64", os: "macos-15", platform: "darwin", arch: "arm64", releaseFolder: "build/desktop/releases/macArm64" },
{ target: "macX64", os: "macos-15-intel", platform: "darwin", arch: "x64", releaseFolder: "build/desktop/releases/macX64" },
{ target: "linuxX64", os: "ubuntu-24.04", platform: "linux", arch: "x64", releaseFolder: "build/desktop/releases/linuxX64" },
{ target: "linuxArm64", os: "ubuntu-24.04-arm", platform: "linux", arch: "arm64", releaseFolder: "build/desktop/releases/linuxArm64" },
{ target: "androidArm64", os: "windows-2025", platform: "win32", arch: "x64", releaseFolder: "build/mobile/releases" },
];
const selected = process.env.buildTarget || "all";
const include = targets.filter(item => selected === "all" || item.target === selected);
if (!include.length) throw new Error(`不支持的构建平台:${selected}`);
const refVersion = /^v\d+\.\d+\.\d+$/.test(process.env.buildRef ?? "") ? process.env.buildRef : "";
const version = (process.env.buildVersion?.trim() || refVersion || config.app.version).replace(/^v/, "");
if (!/^\d+\.\d+\.\d+$/.test(version)) throw new Error("版本号必须为 X.Y.Z");
appendFileSync(process.env.GITHUB_OUTPUT, `version=${version}\nmatrix=${JSON.stringify({ include })}\n`);
'
build:
name: 构建 ${{ matrix.target }}
needs: prepare
if: github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v'))
runs-on: ${{ matrix.os }}
timeout-minutes: 90
strategy:
fail-fast: false
matrix: ${{ fromJSON(needs.prepare.outputs.matrix) }}
env:
appVersion: ${{ needs.prepare.outputs.version }}
releaseMode: ${{ inputs.generatePatch && '--auto' || '--initial' }}
macCodesign: ${{ matrix.platform == 'darwin' && '1' || '0' }}
steps:
- uses: actions/checkout@v7
with:
# ACT: 签名只使用触发工作流的代码,避免额外 ref 引入未审查的 PR 代码。
ref: ${{ matrix.platform == 'darwin' && github.sha || needs.prepare.outputs.commit }}
persist-credentials: false
- name: 校验签名来源
if: matrix.platform == 'darwin'
env:
buildCommit: ${{ needs.prepare.outputs.commit }}
run: |
if [[ "$(git rev-parse HEAD)" != "$buildCommit" ]]; then
echo '::error::签名构建不能使用其他提交。请选择对应的工作流分支或标签,并将 ref 留空。'
exit 1
fi
- uses: oven-sh/setup-bun@v2
with:
bun-version-file: package.json
- name: 确认运行器系统与架构
env:
expectedPlatform: ${{ matrix.platform }}
expectedArch: ${{ matrix.arch }}
run: bun -e 'if (process.platform !== process.env.expectedPlatform || process.arch !== process.env.expectedArch) throw new Error("运行器系统或架构与目标不一致");'
- name: 准备 Android JDK 与 SDK 目录
if: matrix.target == 'androidArm64'
shell: pwsh
run: |
if (!(Test-Path -LiteralPath "$env:JAVA_HOME_17_X64/bin/javac.exe")) { throw '找不到运行器 JDK 17' }
if (!$env:ANDROID_HOME -or !(Test-Path -LiteralPath $env:ANDROID_HOME -PathType Container)) { throw '找不到运行器 Android SDK 目录' }
"JAVA_HOME=$env:JAVA_HOME_17_X64" >> $env:GITHUB_ENV
$env:JAVA_HOME = $env:JAVA_HOME_17_X64
- name: 安装依赖
run: bun install --frozen-lockfile
- name: 准备 Linux 桌面与打包依赖
if: matrix.platform == 'linux'
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends \
libgtk-3-0t64 libwebkit2gtk-4.1-0 libayatana-appindicator3-1 librsvg2-2 \
zenity ffmpeg dpkg
- name: 准备 Electrobun SDK
if: matrix.target != 'androidArm64'
run: bun apps/desktop/node_modules/electrobun/bin/electrobun.cjs prepare
- name: 编译 macOS 原生启动库
if: runner.os == 'macOS'
run: bun packages/startup/scripts/buildMac.ts
- name: 准备 NSIS
if: matrix.platform == 'win32' && matrix.target != 'androidArm64'
shell: pwsh
run: |
$nsisPath = 'C:/Program Files (x86)/NSIS/makensis.exe'
if (!(Test-Path -LiteralPath $nsisPath)) {
choco install nsis --yes --no-progress
if ($LASTEXITCODE -ne 0) { throw 'NSIS 安装失败' }
}
if (!(Test-Path -LiteralPath $nsisPath)) { throw '找不到 makensis.exe' }
"NSIS_PATH=$nsisPath" >> $env:GITHUB_ENV
- name: 构建 Windows 安装包及更新文件
if: matrix.platform == 'win32' && matrix.target != 'androidArm64'
# ACT: 使用原生环境,避免 Git Bash 的 GNU tar 将 Windows 盘符识别为远程主机。
shell: pwsh
run: |
& "$env:SystemRoot/System32/tar.exe" --version
bun run release:desktop "$env:appVersion" "$env:releaseMode"
exit $LASTEXITCODE
- name: 准备 Android Bun、GeckoView 与构建依赖
if: matrix.target == 'androidArm64'
shell: pwsh
run: bun run --cwd apps/mobile setup
- name: 构建 Android APK
if: matrix.target == 'androidArm64'
shell: pwsh
env:
androidRelease: ${{ inputs.androidRelease && '1' || '0' }}
run: bun run --cwd apps/mobile build
- name: 准备 macOS 签名与公证凭据
if: matrix.platform == 'darwin'
id: signing
env:
certificateBase64: ${{ secrets.MACOS_CERTIFICATE_BASE64 }}
certificatePassword: ${{ secrets.MACOS_CERTIFICATE_PASSWORD }}
installerCertificateBase64: ${{ secrets.MACOS_INSTALLER_CERTIFICATE_BASE64 }}
installerCertificatePassword: ${{ secrets.MACOS_INSTALLER_CERTIFICATE_PASSWORD }}
notarizationKeyId: ${{ secrets.MACOS_NOTARIZATION_KEY_ID }}
notarizationIssuerId: ${{ secrets.MACOS_NOTARIZATION_ISSUER_ID }}
notarizationKeyBase64: ${{ secrets.MACOS_NOTARIZATION_KEY_BASE64 }}
run: |
set +x
: "${certificateBase64:?请配置 MACOS_CERTIFICATE_BASE64 Secret}"
: "${certificatePassword:?请配置 MACOS_CERTIFICATE_PASSWORD Secret}"
: "${installerCertificateBase64:?请配置 MACOS_INSTALLER_CERTIFICATE_BASE64 Secret}"
: "${installerCertificatePassword:?请配置 MACOS_INSTALLER_CERTIFICATE_PASSWORD Secret}"
: "${notarizationKeyId:?请配置 MACOS_NOTARIZATION_KEY_ID Secret}"
: "${notarizationIssuerId:?请配置 MACOS_NOTARIZATION_ISSUER_ID Secret}"
: "${notarizationKeyBase64:?请配置 MACOS_NOTARIZATION_KEY_BASE64 Secret}"
umask 077
certificatePath="$RUNNER_TEMP/toonflowSigning.p12"
installerCertificatePath="$RUNNER_TEMP/toonflowInstallerSigning.p12"
installerIssuerPath="$RUNNER_TEMP/developerIdG2.cer"
keychainPath="$RUNNER_TEMP/toonflowSigning.keychain-db"
notarizationKeyPath="$RUNNER_TEMP/toonflowNotarization.p8"
trap 'rm -f "$certificatePath" "$installerCertificatePath" "$installerIssuerPath"' EXIT
printf '%s' "$notarizationKeyBase64" | base64 --decode > "$notarizationKeyPath"
openssl pkey -in "$notarizationKeyPath" -passin pass: -check -noout > /dev/null
keychainPassword="$(openssl rand -hex 32)"
echo "::add-mask::$keychainPassword"
printf '%s' "$certificateBase64" | base64 --decode > "$certificatePath"
printf '%s' "$installerCertificateBase64" | base64 --decode > "$installerCertificatePath"
security create-keychain -p "$keychainPassword" "$keychainPath"
security set-keychain-settings -lut 7200 "$keychainPath"
security unlock-keychain -p "$keychainPassword" "$keychainPath"
security default-keychain -d user -s "$keychainPath"
# ACT: 两种证书可能共用私钥,首次导入就需授权全部实际使用的 Apple 签名工具。
security import "$certificatePath" -P "$certificatePassword" -k "$keychainPath" -T /usr/bin/codesign -T /usr/bin/productbuild -T /usr/bin/productsign > /dev/null
security import "$installerCertificatePath" -P "$installerCertificatePassword" -k "$keychainPath" -T /usr/bin/codesign -T /usr/bin/productbuild -T /usr/bin/productsign > /dev/null
curl --fail --silent --show-error --location --proto '=https' --max-time 60 \
https://www.apple.com/certificateauthority/DeveloperIDG2CA.cer -o "$installerIssuerPath"
security import "$installerIssuerPath" -k "$keychainPath" > /dev/null
security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k "$keychainPassword" "$keychainPath" > /dev/null
security list-keychains -d user -s "$keychainPath"
identity="$(security find-identity -v -p codesigning "$keychainPath" | awk '/"Developer ID Application: / { print $2 }')"
if [[ ! "$identity" =~ ^[[:xdigit:]]{40}$ ]]; then
echo '::error::未找到唯一有效的 Developer ID Application 身份。请检查下方证书类型、有效期及系统信任诊断;不会输出私钥或密码。'
# ACT: 身份列表保留系统错误码、隐藏证书姓名。
security find-identity -p codesigning "$keychainPath" | sed -E 's/"[^"]*"/"<certificate name hidden>"/g'
security find-certificate -a -p "$keychainPath" | bun -e '
import { X509Certificate } from "node:crypto";
const pem = await Bun.stdin.text();
const certificates = pem.match(/-----BEGIN CERTIFICATE-----[\s\S]*?-----END CERTIFICATE-----/g) ?? [];
console.log(`导入证书数量:${certificates.length}`);
for (const entry of certificates) {
const certificate = new X509Certificate(entry);
const type = certificate.subject.match(/^CN=(Developer ID Application|Developer ID Installer|Apple Development|Apple Distribution|Mac Developer|3rd Party Mac Developer Application|3rd Party Mac Developer Installer|iPhone Developer|iPhone Distribution):/m)?.[1] ?? "其他或 CA 证书";
console.log(JSON.stringify({ type, validFrom: certificate.validFrom, validTo: certificate.validTo }));
}
'
exit 1
fi
installerIdentity="$(security find-identity -v "$keychainPath" | awk -F '"' '/"Developer ID Installer: / { print $2 }')"
if [[ -z "$installerIdentity" || "$installerIdentity" == *$'\n'* ]]; then
echo '::error::未找到唯一有效的 Developer ID Installer 身份,请确认 P12 包含对应私钥。'
security find-identity "$keychainPath" | sed -E 's/"[^"]*"/"<certificate name hidden>"/g'
exit 1
fi
printf 'identity=%s\n' "$identity" >> "$GITHUB_OUTPUT"
printf 'installerIdentity=%s\n' "$installerIdentity" >> "$GITHUB_OUTPUT"
printf 'keychainPath=%s\n' "$keychainPath" >> "$GITHUB_OUTPUT"
printf 'notarizationKeyPath=%s\n' "$notarizationKeyPath" >> "$GITHUB_OUTPUT"
- name: 为 Apple 公证票据网络错误启用有限重试
if: matrix.platform == 'darwin'
run: |
bun -e '
import { chmodSync, mkdirSync, readFileSync, writeFileSync } from "@toonflow/file";
import { join } from "node:path";
const directory = join(process.env.RUNNER_TEMP, "toonflowMacTools");
mkdirSync(directory, { recursive: true });
const target = join(directory, "xcrun");
// ACT: 无扩展名入口保持 JavaScript 语法,并统一 LF,保证 macOS shebang 可执行。
writeFileSync(target, readFileSync("apps/desktop/scripts/macXcrun.ts", "utf8").replace(/\r\n/g, "\n"));
chmodSync(target, 0o755);
writeFileSync(process.env.GITHUB_PATH, `${directory}\n`, { flag: "a" });
'
- name: 构建 macOS 安装包及更新文件(自动签名与公证)
if: runner.os == 'macOS'
env:
TOONFLOW_EXTERNAL_RUNTIME: "1"
ELECTROBUN_DEVELOPER_ID: ${{ steps.signing.outputs.identity }}
ELECTROBUN_INSTALLER_ID: ${{ steps.signing.outputs.installerIdentity }}
ELECTROBUN_INSTALLER_KEYCHAIN: ${{ steps.signing.outputs.keychainPath }}
ELECTROBUN_APPLEAPIKEY: ${{ secrets.MACOS_NOTARIZATION_KEY_ID }}
ELECTROBUN_APPLEAPIISSUER: ${{ secrets.MACOS_NOTARIZATION_ISSUER_ID }}
ELECTROBUN_APPLEAPIKEYPATH: ${{ steps.signing.outputs.notarizationKeyPath }}
run: bun run release:desktop "$appVersion" "$releaseMode"
- name: 清理 macOS 签名与公证凭据
if: always() && matrix.platform == 'darwin'
run: |
rm -f "$RUNNER_TEMP/toonflowSigning.p12" "$RUNNER_TEMP/toonflowInstallerSigning.p12" "$RUNNER_TEMP/developerIdG2.cer" "$RUNNER_TEMP/toonflowNotarization.p8"
keychainPath="$RUNNER_TEMP/toonflowSigning.keychain-db"
if [[ -f "$keychainPath" ]]; then
security delete-keychain "$keychainPath"
fi
- name: 验证 macOS 更新包与 PKG 安装向导
if: runner.os == 'macOS'
env:
releaseDirectory: ${{ matrix.releaseFolder }}/${{ needs.prepare.outputs.version }}
signingIdentity: ${{ steps.signing.outputs.identity }}
packageArchitecture: ${{ matrix.arch }}
run: |
verifyMacArtifact() {
if [[ "$macCodesign" == '1' ]]; then
codesign --verify --deep --strict --verbose=2 \
--test-requirement "=anchor apple generic and certificate leaf[field.1.2.840.113635.100.6.1.13] exists and certificate leaf = H\"$signingIdentity\"" "$1"
fi
}
inspectionDirectory="$RUNNER_TEMP/toonflowPackageCheck"
mkdir -p "$inspectionDirectory"
export inspectionDirectory
bun -e '
import { readdirSync } from "@toonflow/file";
import { file, write } from "@toonflow/file/bun";
import { join } from "node:path";
const directory = process.env.releaseDirectory;
const archives = readdirSync(directory).filter(name => name.endsWith(".tar.zst"));
if (archives.length !== 1) throw new Error("更新包数量不正确");
await write(join(process.env.inspectionDirectory, "app.tar"), Bun.zstdDecompressSync(await file(join(directory, archives[0])).arrayBuffer()));
'
tar -xf "$inspectionDirectory/app.tar" -C "$inspectionDirectory"
app="$inspectionDirectory/toonflow.app"
test -s "$app/Contents/Resources/AppIcon.icns"
test -s "$app/Contents/Resources/app/bun/index.js"
test -x "$app/Contents/MacOS/bun"
verifyMacArtifact "$app"
if [[ "$macCodesign" == '1' ]]; then
xcrun stapler validate "$app"
fi
pkgPath="$releaseDirectory/toonflow-$appVersion-macos-$packageArchitecture.pkg"
test -s "$pkgPath"
if [[ "$macCodesign" == '1' ]]; then
pkgutil --check-signature "$pkgPath"
xcrun stapler validate "$pkgPath"
spctl --assess --type install --verbose=2 "$pkgPath"
fi
expandedDirectory="$inspectionDirectory/pkg"
pkgutil --expand-full "$pkgPath" "$expandedDirectory"
packagedApps=()
while IFS= read -r -d '' appPath; do
packagedApps+=("$appPath")
done < <(find "$expandedDirectory" -type d -name '*.app' -prune -print0)
if [[ ${#packagedApps[@]} -ne 1 || "${packagedApps[0]}" != */Payload/toonflow.app ]]; then
echo '::error::PKG 必须包含且仅包含一个 toonflow.app 应用负载。'
exit 1
fi
app="${packagedApps[0]}"
test -s "$app/Contents/Resources/AppIcon.icns"
test -s "$app/Contents/Resources/app/bun/index.js"
test -x "$app/Contents/MacOS/bun"
test -x "$app/Contents/MacOS/launcher"
verifyMacArtifact "$app"
cmp "$inspectionDirectory/toonflow.app/Contents/Resources/version.json" "$app/Contents/Resources/version.json"
- name: 构建 Linux 安装包及更新文件
if: matrix.platform == 'linux'
run: bun run release:desktop "$appVersion" "$releaseMode"
- name: 命名 Android 安装包
if: matrix.target == 'androidArm64'
shell: pwsh
env:
releaseFolder: ${{ matrix.releaseFolder }}/${{ needs.prepare.outputs.version }}
debugSuffix: ${{ !inputs.androidRelease && '-debug' || '' }}
run: |
bun -e '
import { copyFile, mkdir } from "@toonflow/file";
import { join } from "node:path";
const directory = process.env.releaseFolder;
const apkName = `toonflow-${process.env.appVersion}-android-arm64${process.env.debugSuffix}.apk`;
await mkdir(directory, { recursive: true });
await copyFile("build/mobile/toonflowMobile.apk", join(directory, apkName));
'
- name: 上传构建产物
id: artifact
uses: actions/upload-artifact@v7
with:
name: toonflow-${{ needs.prepare.outputs.version }}-${{ matrix.target }}
path: ${{ matrix.releaseFolder }}/${{ needs.prepare.outputs.version }}/
if-no-files-found: error
compression-level: 0
retention-days: 7
- name: 输出下载链接
env:
artifactUrl: ${{ steps.artifact.outputs.artifact-url }}
artifactTarget: ${{ matrix.target }}
run: |
printf '[下载 Toonflow %s · %s](%s)\n' "$appVersion" "$artifactTarget" "$artifactUrl" >> "$GITHUB_STEP_SUMMARY"