Skip to content

Commit 495319f

Browse files
7418claude
andcommitted
fix: macOS 热更新 code signature 校验失败
根因:CI 上没有 Apple Developer 证书,electron-builder 跳过签名, 生成完全未签名的 .app。electron-updater 的 ShipIt 进程在应用更新时 校验 code signature,未签名的 app 被拒绝: "Code signature did not pass validation: 代码未能满足指定的代码要求" 修复: 1. scripts/after-pack.js — 在所有文件修改(better-sqlite3 替换) 完成后,对 macOS .app 执行 ad-hoc 签名(codesign --force --deep -s -)。 Ad-hoc 签名不需要证书,但能通过 ShipIt 的基本校验。 如果将来配置了真实证书,electron-builder 的签名步骤会覆盖 ad-hoc。 2. .github/workflows/build.yml — macOS 构建添加 CSC_IDENTITY_AUTO_DISCOVERY=false,防止 electron-builder 尝试查找不存在的证书时产生不可预期的行为。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent cd4d718 commit 495319f

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ jobs:
6363
- name: Package for macOS (x64 + arm64)
6464
env:
6565
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
66+
CSC_IDENTITY_AUTO_DISCOVERY: "false"
6667
run: npx electron-builder --mac --config electron-builder.yml --publish always
6768

6869
build-linux:

scripts/after-pack.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,33 @@ module.exports = async function afterPack(context) {
118118
}
119119
}
120120
}
121+
122+
// Step 4: Ad-hoc code sign on macOS for auto-update compatibility.
123+
// electron-updater's ShipIt process validates code signatures when applying
124+
// updates. Without at least an ad-hoc signature, the update fails with:
125+
// "Code signature did not pass validation: 代码未能满足指定的代码要求"
126+
// Ad-hoc signing (codesign -s -) creates a valid local signature without
127+
// requiring an Apple Developer certificate.
128+
// This runs AFTER all file modifications (better-sqlite3 replacement above)
129+
// so the signature covers the final app state. If a real certificate is
130+
// available, electron-builder's signing step will override this.
131+
if (platform === 'mac') {
132+
const appName = context.packager.appInfo.productFilename;
133+
const appPath = path.join(appOutDir, `${appName}.app`);
134+
135+
if (fs.existsSync(appPath)) {
136+
console.log(`[afterPack] Ad-hoc signing ${appPath} for auto-update compatibility...`);
137+
try {
138+
execSync(`codesign --force --deep -s - "${appPath}"`, {
139+
stdio: 'inherit',
140+
timeout: 120000,
141+
});
142+
console.log('[afterPack] Ad-hoc signing completed successfully');
143+
} catch (err) {
144+
console.warn('[afterPack] Ad-hoc signing failed (non-fatal):', err.message);
145+
}
146+
} else {
147+
console.warn(`[afterPack] macOS app not found at ${appPath}, skipping ad-hoc signing`);
148+
}
149+
}
121150
};

0 commit comments

Comments
 (0)