Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

fix(release): notarize the DMG before stapling its ticket

vastsa97e68cbbbf21
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 27aaab4fd..2e6670aee 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -254,9 +254,13 @@ jobs:
-c.mac.forceCodeSigning=true \
-c.mac.notarize=true
- - name: Staple macOS installer ticket
+ - name: Notarize and staple the macOS DMG
if: matrix.platform == 'macos' && env.MACOS_SIGN_RELEASE == 'true'
- run: scripts/staple-macos-release-dmg.sh apps/desktop/release
+ env:
+ APPLE_ID: ${{ secrets.APPLE_ID }}
+ APPLE_APP_SPECIFIC_PASSWORD: ${{ secrets.APPLE_APP_SPECIFIC_PASSWORD }}
+ APPLE_TEAM_ID: ${{ secrets.APPLE_TEAM_ID }}
+ run: scripts/notarize-and-staple-macos-release-dmg.sh apps/desktop/release
- name: Verify signed and notarized macOS installer
if: matrix.platform == 'macos' && env.MACOS_SIGN_RELEASE == 'true'
diff --git a/apps/desktop/test/ci-workflow.test.mjs b/apps/desktop/test/ci-workflow.test.mjs
index e4b2024c2..ad0ec3e47 100644
--- a/apps/desktop/test/ci-workflow.test.mjs
+++ b/apps/desktop/test/ci-workflow.test.mjs
@@ -255,10 +255,32 @@ test("macOS release signing is required on tag pushes", () => {
assert.doesNotMatch(signedBlock, /-c\.mac\.identity=/);
assert.doesNotMatch(signedBlock, /CSC_NAME: "Developer ID Application:/);
assert.match(signedBlock, /-c\.mac\.notarize=true/);
+ // electron-builder notarizes only the .app; the DMG needs its own
+ // submission before the ticket can be stapled (error 65 otherwise).
+ const dmgBlock = releaseWorkflowSource.match(
+ /- name: Notarize and staple the macOS DMG[\s\S]*?(?=\n - name:)/,
+ )?.[0];
+ assert.ok(dmgBlock, "DMG notarization step is missing");
+ assert.match(dmgBlock, /env\.MACOS_SIGN_RELEASE == 'true'/);
+ for (const secret of [
+ "APPLE_ID",
+ "APPLE_APP_SPECIFIC_PASSWORD",
+ "APPLE_TEAM_ID",
+ ]) {
+ assert.match(
+ dmgBlock,
+ new RegExp(`${secret}:\\s*\\$\\{\\{\\s*secrets\\.${secret}\\s*\\}\\}`),
+ );
+ }
+ assert.match(
+ dmgBlock,
+ /run: scripts\/notarize-and-staple-macos-release-dmg\.sh apps\/desktop\/release/,
+ );
assert.match(
releaseWorkflowSource,
- /Staple macOS installer ticket[\s\S]*?if: matrix\.platform == 'macos' && env\.MACOS_SIGN_RELEASE == 'true'[\s\S]*?Verify signed and notarized macOS installer/,
+ /Notarize and staple the macOS DMG[\s\S]*?if: matrix\.platform == 'macos' && env\.MACOS_SIGN_RELEASE == 'true'[\s\S]*?Verify signed and notarized macOS installer/,
);
+ assert.doesNotMatch(releaseWorkflowSource, /scripts\/staple-macos-release-dmg\.sh/);
});
test("the signed local macOS lane selects the native runner architecture", () => {
diff --git a/apps/desktop/test/macos-release-verification.test.mjs b/apps/desktop/test/macos-release-verification.test.mjs
index 6fe68da31..1b5b706b2 100644
--- a/apps/desktop/test/macos-release-verification.test.mjs
+++ b/apps/desktop/test/macos-release-verification.test.mjs
@@ -9,13 +9,19 @@ const verifyScript = new URL(
"../../../scripts/verify-macos-release.sh",
import.meta.url,
);
-const stapleScript = new URL(
- "../../../scripts/staple-macos-release-dmg.sh",
+const notarizeScript = new URL(
+ "../../../scripts/notarize-and-staple-macos-release-dmg.sh",
import.meta.url,
);
const SIGNING_IDENTITY = "Developer ID Application: XingYu Liu (DUV63RKYTW)";
const SIGNING_IDENTITY_NAME = "XingYu Liu (DUV63RKYTW)";
+const SUBMISSION_ID = "11111111-2222-3333-4444-555555555555";
+const NOTARY_ENV = {
+ APPLE_ID: "[email protected]",
+ APPLE_APP_SPECIFIC_PASSWORD: "app-specific-password",
+ APPLE_TEAM_ID: "DUV63RKYTW",
+};
async function writeSignedAppFixture(release) {
const app = join(release, "mac-arm64", "PI-Desktop.app");
@@ -27,32 +33,184 @@ async function writeSignedAppFixture(release) {
return { app, dmg };
}
-test("macOS release finalization staples the generated DMG", async (t) => {
- const root = await mkdtemp(join(tmpdir(), "pi-desktop-macos-staple-"));
+async function writeDmgFixture(release) {
+ const dmg = join(release, "PI-Desktop-0.15.1-beta.3-arm64.dmg");
+ await mkdir(release, { recursive: true });
+ await writeFile(dmg, "fixture");
+ return dmg;
+}
+
+/**
+ * Fake `xcrun` that records every notarytool/stapler call. `status` is the
+ * notarytool result and `stapleFailures` makes the first N staple attempts fail
+ * so the bounded retry is covered.
+ */
+async function writeXcrunNotaryFixture(
+ bin,
+ { status = "Accepted", submitExit = 0, stapleFailures = 0 } = {},
+) {
+ await mkdir(bin, { recursive: true });
+ const xcrun = `#!/usr/bin/env bash
+printf '%s\\n' "$*" >> "$NOTARY_LOG"
+case "$1 $2" in
+ "notarytool submit")
+ echo "Conducting pre-submission checks for the artifact"
+ echo "Submission ID received"
+ echo " id: ${SUBMISSION_ID}"
+ echo "Waiting for processing to complete."
+ echo " id: ${SUBMISSION_ID}"
+ echo " status: ${status}"
+ exit ${submitExit}
+ ;;
+ "notarytool log") exit 0 ;;
+ "stapler staple")
+ count_file="$NOTARY_LOG.staples"
+ count=0
+ if [[ -f "$count_file" ]]; then count="$(cat "$count_file")"; fi
+ count=$((count + 1))
+ echo "$count" > "$count_file"
+ if (( count <= ${stapleFailures} )); then
+ echo 'CloudKit query failed due to "Record not found"' >&2
+ echo 'Could not find base64 encoded ticket' >&2
+ exit 65
+ fi
+ exit 0
+ ;;
+esac
+exit 0
+`;
+ await writeFile(join(bin, "xcrun"), xcrun);
+ await chmod(join(bin, "xcrun"), 0o755);
+}
+
+function runNotarize(release, bin, log, extraEnv = {}) {
+ return spawnSync("bash", [notarizeScript.pathname, release], {
+ encoding: "utf8",
+ env: {
+ ...process.env,
+ ...NOTARY_ENV,
+ PATH: `${bin}:${process.env.PATH}`,
+ NOTARY_LOG: log,
+ STAPLE_DELAY_SECONDS: "1",
+ ...extraEnv,
+ },
+ });
+}
+
+test("the DMG is submitted to Apple before it is stapled", async (t) => {
+ const root = await mkdtemp(join(tmpdir(), "pi-desktop-macos-dmg-notary-"));
t.after(() => rm(root, { recursive: true, force: true }));
const release = join(root, "release");
const bin = join(root, "bin");
const log = join(root, "xcrun.log");
- const dmg = join(release, "PI-Desktop-0.14.2-arm64.dmg");
- await mkdir(release, { recursive: true });
- await mkdir(bin, { recursive: true });
- await writeFile(dmg, "fixture");
- await writeFile(
- join(bin, "xcrun"),
- "#!/usr/bin/env bash\nprintf '%s\\n' \"$*\" >> \"$STAPLE_LOG\"\n[[ \"$1 $2\" == 'stapler staple' ]]\n",
+ const dmg = await writeDmgFixture(release);
+ await writeXcrunNotaryFixture(bin);
+
+ const result = runNotarize(release, bin, log);
+
+ assert.equal(result.status, 0, `${result.stdout}\n${result.stderr}`);
+ const calls = (await readFile(log, "utf8")).trim().split("\n");
+ assert.match(calls[0], /^notarytool submit .*--wait$/);
+ assert.ok(calls[0].includes(dmg), "the submitted artifact is the DMG");
+ assert.ok(calls[0].includes("--apple-id [email protected]"));
+ assert.equal(calls[1], `stapler staple ${dmg}`);
+ assert.equal(calls[2], `stapler validate ${dmg}`);
+ assert.match(result.stdout, /status.*Accepted/);
+});
+
+test("stapling retries only after Apple accepts the DMG", async (t) => {
+ const root = await mkdtemp(join(tmpdir(), "pi-desktop-macos-dmg-retry-"));
+ t.after(() => rm(root, { recursive: true, force: true }));
+
+ const release = join(root, "release");
+ const bin = join(root, "bin");
+ const log = join(root, "xcrun.log");
+ await writeDmgFixture(release);
+ await writeXcrunNotaryFixture(bin, { stapleFailures: 2 });
+
+ const result = runNotarize(release, bin, log);
+
+ assert.equal(result.status, 0, `${result.stdout}\n${result.stderr}`);
+ const calls = (await readFile(log, "utf8")).split("\n");
+ assert.equal(
+ calls.filter((line) => line.startsWith("stapler staple")).length,
+ 3,
+ "two failures then a successful staple",
);
- await chmod(join(bin, "xcrun"), 0o755);
+});
+
+test("a rejected DMG is never stapled and the Apple log is fetched", async (t) => {
+ const root = await mkdtemp(join(tmpdir(), "pi-desktop-macos-dmg-rejected-"));
+ t.after(() => rm(root, { recursive: true, force: true }));
+
+ const release = join(root, "release");
+ const bin = join(root, "bin");
+ const log = join(root, "xcrun.log");
+ await writeDmgFixture(release);
+ await writeXcrunNotaryFixture(bin, { status: "Invalid" });
+
+ const result = runNotarize(release, bin, log);
+
+ assert.equal(result.status, 1);
+ assert.match(result.stderr, /Apple did not accept/);
+ const calls = await readFile(log, "utf8");
+ assert.doesNotMatch(calls, /stapler staple/);
+ assert.match(calls, new RegExp(`notarytool log ${SUBMISSION_ID}`));
+});
+
+test("a failed submission fails the run and dumps the Apple log", async (t) => {
+ const root = await mkdtemp(join(tmpdir(), "pi-desktop-macos-dmg-submitfail-"));
+ t.after(() => rm(root, { recursive: true, force: true }));
+
+ const release = join(root, "release");
+ const bin = join(root, "bin");
+ const log = join(root, "xcrun.log");
+ await writeDmgFixture(release);
+ await writeXcrunNotaryFixture(bin, { submitExit: 1 });
+
+ const result = runNotarize(release, bin, log);
+
+ assert.equal(result.status, 1);
+ assert.match(result.stderr, /notarytool submit failed/);
+ const calls = await readFile(log, "utf8");
+ assert.match(calls, new RegExp(`notarytool log ${SUBMISSION_ID}`));
+ assert.doesNotMatch(calls, /stapler staple/);
+});
+
+test("the notarization step fails closed without team-scoped credentials", async (t) => {
+ const root = await mkdtemp(join(tmpdir(), "pi-desktop-macos-dmg-nocreds-"));
+ t.after(() => rm(root, { recursive: true, force: true }));
- const result = spawnSync("bash", [stapleScript.pathname, release], {
+ const release = join(root, "release");
+ const bin = join(root, "bin");
+ const log = join(root, "xcrun.log");
+ await writeDmgFixture(release);
+ await writeXcrunNotaryFixture(bin);
+
+ const missing = { ...process.env, ...NOTARY_ENV, NOTARY_LOG: log };
+ delete missing.APPLE_ID;
+ delete missing.APPLE_APP_SPECIFIC_PASSWORD;
+ const missingResult = spawnSync("bash", [notarizeScript.pathname, release], {
encoding: "utf8",
- env: { ...process.env, PATH: `${bin}:${process.env.PATH}`, STAPLE_LOG: log },
+ env: missing,
});
+ assert.equal(missingResult.status, 1);
+ assert.match(
+ missingResult.stderr,
+ /APPLE_ID \/ APPLE_APP_SPECIFIC_PASSWORD \/ APPLE_TEAM_ID/,
+ );
+
+ const wrongTeam = runNotarize(release, bin, log, {
+ APPLE_TEAM_ID: "WRONGTEAMID",
+ });
+ assert.equal(wrongTeam.status, 1);
+ assert.match(wrongTeam.stderr, /APPLE_TEAM_ID must be DUV63RKYTW/);
- assert.equal(result.status, 0, `${result.stdout}\n${result.stderr}`);
assert.equal(
- await readFile(log, "utf8"),
- `stapler staple ${dmg}\n`,
+ await readFile(log, "utf8").catch(() => ""),
+ "",
+ "no notarytool call may happen without valid credentials",
);
});
diff --git a/docs/adr/0289-signed-macos-github-releases.md b/docs/adr/0289-signed-macos-github-releases.md
index af86b0dba..9f1664b7b 100644
--- a/docs/adr/0289-signed-macos-github-releases.md
+++ b/docs/adr/0289-signed-macos-github-releases.md
@@ -22,11 +22,15 @@ for the official `vastsa/PI-Desktop` release lane.
## Decision
-1. Every GitHub tag release (`vX.Y.Z`) Developer ID-signs, notarizes with
- `xcrun notarytool` through electron-builder 26 (`-c.mac.notarize=true`),
- staples the DMG, and verifies the app as `Notarized Developer ID` before
- upload. Missing signing or notarization secrets fail the job; unsigned
- macOS artifacts must not be published from a tag.
+1. Every GitHub tag release (`vX.Y.Z`) Developer ID-signs the app through
+ electron-builder 26 and notarizes it with `xcrun notarytool`
+ (`-c.mac.notarize=true`). Because electron-builder notarizes only the app,
+ the final DMG is submitted separately (`xcrun notarytool submit --wait`) and
+ must return `status: Accepted` before `xcrun stapler staple` may run; the
+ run then verifies the app as `Notarized Developer ID` and both stapled
+ tickets before upload. Stapler retries are bounded and only allowed after
+ Apple accepts. Missing signing or notarization secrets fail the job;
+ unsigned macOS artifacts must not be published from a tag.
2. The signing certificate is
`Developer ID Application: XingYu Liu (DUV63RKYTW)`; Apple team id
`DUV63RKYTW`. CI pins it with `CSC_NAME=XingYu Liu (DUV63RKYTW)`. The name
diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.md
index 818aa589f..42899fe0d 100644
--- a/docs/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/spec/06-delivery/04-e2e-test-plan.md
@@ -323,13 +323,17 @@ identify the platform validation still needed.
`codesign --verify --deep --strict --verbose=2`,
`spctl --assess --type execute --verbose=4`, and `xcrun stapler validate`
against the app, including `Contents/Resources/bin/pi-desktop-host-core`.
- 4) Run `xcrun stapler validate` against the matching DMG. 5) Download the
- DMG on a clean macOS profile, move the app to `/Applications`, and open it
- without clearing `com.apple.quarantine`.
+ 4) Confirm the workflow's DMG step reported an Apple notary status of
+ `Accepted` and then run `xcrun stapler validate` against the matching DMG.
+ 5) Download the DMG on a clean macOS profile, move the app to
+ `/Applications`, and open it without clearing `com.apple.quarantine`.
- **Expected**: Each macOS app passes signature integrity, Gatekeeper reports
`source=Notarized Developer ID`, and both app and DMG contain valid stapled
- tickets. The app opens normally; no `xattr` quarantine-removal command or
- Security & Privacy override is required. Missing secrets fail the job.
+ tickets. The DMG has its own submission: a DMG that was never submitted has
+ no ticket and fails `stapler staple` with error 65, so a tag build must never
+ reach that state. The app opens normally; no `xattr` quarantine-removal
+ command or Security & Privacy override is required. Missing secrets, a
+ rejected submission, or an exhausted staple retry fail the job.
- **Specs linked**: `06-delivery/06-release-runbook.md`,
`05-security/01-security.md`, ADR 0289
- **Acceptance**: Quality, Security
diff --git a/docs/spec/06-delivery/06-release-runbook.md b/docs/spec/06-delivery/06-release-runbook.md
index 3a00a1df3..59edd7f95 100644
--- a/docs/spec/06-delivery/06-release-runbook.md
+++ b/docs/spec/06-delivery/06-release-runbook.md
@@ -229,10 +229,14 @@ runner. Tag builds and `sign_macos: true` (the dispatch default) receive
`APPLE_TEAM_ID` only from GitHub Actions secrets, pin the certificate through
`CSC_NAME=XingYu Liu (DUV63RKYTW)` (bare common name — electron-builder rejects
the `Developer ID Application:` prefix), force code signing and
-`notarytool` notarization, verify that identity, code-signing integrity
-(including `pi-desktop-host-core`), Gatekeeper `Notarized Developer ID`, and
-the stapled app ticket, and staple and validate the DMG before any artifact
-upload. The per-architecture `latest-mac.yml` files are renamed before upload;
+`notarytool` notarization of `PI-Desktop.app`. The DMG is then submitted to the
+same service on its own (`scripts/notarize-and-staple-macos-release-dmg.sh`),
+and only an `Accepted` status allows the ticket to be stapled. Verification
+then checks the identity, code-signing integrity (including
+`pi-desktop-host-core`), Gatekeeper `Notarized Developer ID`, and both stapled
+tickets before any artifact upload. The per-architecture `latest-mac.yml` files
+are renamed before upload; the publish job merges them into one feed after
+downloading both artifacts.
the publish job merges them into one feed after downloading both artifacts.
The shared electron-builder configuration applies the architecture-labelled
@@ -329,8 +333,20 @@ enter git: `*.p12`, `*.cer`, `*.p8`, `*.mobileprovision`.
## 5. Verification gates
Unsigned debug artifacts (`workflow_dispatch` with `sign_macos: false`) are
-not Gatekeeper-qualified. Tag releases must pass the signature and staple
-checks below or the workflow fails.
+not Gatekeeper-qualified. Tag releases must pass the signature, notarization,
+and staple checks below or the workflow fails.
+
+Two separate notarization submissions exist, because Apple notarizes one
+artifact per submission and electron-builder only covers the app:
+
+| Artifact | Submitted by | Ticket |
+|---|---|---|
+| `PI-Desktop.app` (inside the ZIP) | electron-builder `-c.mac.notarize=true` | stapled by electron-builder |
+| `PI-Desktop-<version>-<arch>.dmg` | `scripts/notarize-and-staple-macos-release-dmg.sh` (`notarytool submit --wait`) | stapled by the same script after `status: Accepted` |
+
+A DMG that was never submitted has no ticket, so stapling it fails with
+`Could not find base64 encoded ticket ... Error 65`. Stapler retries are only
+allowed after Apple returns `Accepted`.
Run after every signed release build:
@@ -344,6 +360,16 @@ done
xcrun stapler validate apps/desktop/release/*.dmg
```
+To read the Apple notarization log for a submission (the Release workflow does
+this automatically when a submission is not accepted):
+
+```bash
+xcrun notarytool log <submission-id> \
+ --apple-id "$APPLE_ID" \
+ --password "$APPLE_APP_SPECIFIC_PASSWORD" \
+ --team-id "$APPLE_TEAM_ID"
+```
+
### 5.1 Package footprint gate
Inspect every native-runner package before publication and record all
diff --git a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
index 1e3492b42..6050ad411 100644
--- a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
@@ -3506,8 +3506,8 @@ IPC 请求无法关闭。
#### E2E-196c:macOS 标签工件通过 Gatekeeper 且无需移除隔离属性
- **先决条件**:推送与 `apps/desktop/package.json` 匹配的 `vX.Y.Z` 标签,或手动运行 Release 工作流并保持 `sign_macos: true`(默认);GitHub Actions 已配置 `CSC_LINK`、`CSC_KEY_PASSWORD`、`APPLE_ID`、`APPLE_APP_SPECIFIC_PASSWORD` 和 `APPLE_TEAM_ID` 密钥;两个本机 macOS 运行器均可用。
-- **步骤**:1) 运行标签工作流。2) 对每个 macOS 架构检查解压后的应用,使用 `codesign -dv --verbose=4` 确认权限为 `Developer ID Application: XingYu Liu (DUV63RKYTW)`。3) 对应用运行 `codesign --verify --deep --strict --verbose=2`、`spctl --assess --type execute --verbose=4` 和 `xcrun stapler validate`,并检查 `Contents/Resources/bin/pi-desktop-host-core`。4) 对对应的 DMG 运行 `xcrun stapler validate`。5) 在干净的 macOS 配置文件中下载 DMG,将应用移到 `/Applications` 后不清除 `com.apple.quarantine` 直接打开。
-- **预期**:每个 macOS 应用通过签名完整性检查,Gatekeeper 报告 `source=Notarized Developer ID`,应用和 DMG 都包含有效的装订票据。应用可正常打开,无需 `xattr` 命令或“安全性与隐私”覆盖。缺少密钥则整个作业失败。
+- **步骤**:1) 运行标签工作流。2) 对每个 macOS 架构检查解压后的应用,使用 `codesign -dv --verbose=4` 确认权限为 `Developer ID Application: XingYu Liu (DUV63RKYTW)`。3) 对应用运行 `codesign --verify --deep --strict --verbose=2`、`spctl --assess --type execute --verbose=4` 和 `xcrun stapler validate`,并检查 `Contents/Resources/bin/pi-desktop-host-core`。4) 确认工作流的 DMG 步骤报告 Apple 公证状态为 `Accepted`,然后对对应的 DMG 运行 `xcrun stapler validate`。5) 在干净的 macOS 配置文件中下载 DMG,将应用移到 `/Applications` 后不清除 `com.apple.quarantine` 直接打开。
+- **预期**:每个 macOS 应用通过签名完整性检查,Gatekeeper 报告 `source=Notarized Developer ID`,应用和 DMG 都包含有效的装订票据。DMG 有自己的提交:从未提交过的 DMG 没有票据,装订会以 error 65 失败,因此标签构建绝不能走到该状态。应用可正常打开,无需 `xattr` 命令或“安全性与隐私”覆盖。缺少密钥、提交被拒或装订重试耗尽都会让作业失败。
- **关联规格**:`06-delivery/06-release-runbook.md`、`05-security/01-security.md`、ADR 0289
- **验收**:质量、安全
- **里程碑**:M6+
diff --git a/docs/zh-CN/spec/06-delivery/06-release-runbook.md b/docs/zh-CN/spec/06-delivery/06-release-runbook.md
index f15c58c26..55f1cdc63 100644
--- a/docs/zh-CN/spec/06-delivery/06-release-runbook.md
+++ b/docs/zh-CN/spec/06-delivery/06-release-runbook.md
@@ -224,7 +224,7 @@ xattr -r -d com.apple.quarantine /Applications/PI-Desktop.app
该助手仅适用于可信来源的未签名工件在 macOS 上提示应用已损坏的场景;已签名并公证
的版本无需执行它。
-标签构建和 `sign_macos: true`(手动运行的默认值)仅从 GitHub Actions 密钥接收 `CSC_LINK`、`CSC_KEY_PASSWORD`、`APPLE_ID`、`APPLE_APP_SPECIFIC_PASSWORD` 和 `APPLE_TEAM_ID`,通过 `CSC_NAME=XingYu Liu (DUV63RKYTW)`(裸通用名——electron-builder 拒绝 `Developer ID Application:` 前缀)固定证书,强制代码签名与 `notarytool` 公证,然后验证该身份、代码签名完整性(含 `pi-desktop-host-core`)、Gatekeeper `Notarized Developer ID` 以及已装订的应用票据。生成的 DMG 也会在任何工件上传前显式装订并验证。
+标签构建和 `sign_macos: true`(手动运行的默认值)仅从 GitHub Actions 密钥接收 `CSC_LINK`、`CSC_KEY_PASSWORD`、`APPLE_ID`、`APPLE_APP_SPECIFIC_PASSWORD` 和 `APPLE_TEAM_ID`,通过 `CSC_NAME=XingYu Liu (DUV63RKYTW)`(裸通用名——electron-builder 拒绝 `Developer ID Application:` 前缀)固定证书,强制代码签名与 `notarytool` 公证 `PI-Desktop.app`。随后 DMG 会由 `scripts/notarize-and-staple-macos-release-dmg.sh` 单独提交到同一个服务,只有返回 `Accepted` 才允许装订票据。之后验证身份、代码签名完整性(含 `pi-desktop-host-core`)、Gatekeeper `Notarized Developer ID` 以及两份已装订票据,再进行任何工件上传。
DMG、ZIP、NSIS、AppImage、deb、rpm、块图和更新程序提要输出已
压缩或压缩不敏感。因此,工作流程会上传它们的
@@ -275,7 +275,16 @@ Linux 使用 `base64 -w0 developer-id-application.p12`。绝不能进入 git 的
## 5. 验证门
-未签名调试产物(`workflow_dispatch` 且 `sign_macos: false`)不视为通过 Gatekeeper。标签发布必须通过以下签名和装订检查,否则工作流失败。
+未签名调试产物(`workflow_dispatch` 且 `sign_macos: false`)不视为通过 Gatekeeper。标签发布必须通过以下签名、公证和装订检查,否则工作流失败。
+
+存在两次独立的公证提交,因为 Apple 每次公证一个工件,而 electron-builder 只覆盖应用:
+
+| 工件 | 提交方 | 票据 |
+|---|---|---|
+| `PI-Desktop.app`(ZIP 内) | electron-builder `-c.mac.notarize=true` | 由 electron-builder 装订 |
+| `PI-Desktop-<version>-<arch>.dmg` | `scripts/notarize-and-staple-macos-release-dmg.sh`(`notarytool submit --wait`) | 同一脚本在 `status: Accepted` 后装订 |
+
+从未提交过的 DMG 没有票据,因此装订会失败并报 `Could not find base64 encoded ticket ... Error 65`。只有在 Apple 返回 `Accepted` 之后才允许重试装订。
每次已签名发布后运行:
@@ -287,6 +296,15 @@ for APP in apps/desktop/release/mac-*/PI-Desktop.app; do
xcrun stapler validate "$APP"
done
xcrun stapler validate apps/desktop/release/*.dmg
+
+当提交未被接受时,Release 工作流会自动打印 Apple 公证日志;手动查看方式:
+
+```bash
+xcrun notarytool log <submission-id> \
+ --apple-id "$APPLE_ID" \
+ --password "$APPLE_APP_SPECIFIC_PASSWORD" \
+ --team-id "$APPLE_TEAM_ID"
+```
```
### 5.1 安装包体积门禁
diff --git a/scripts/README.md b/scripts/README.md
index 9d2fb958f..17f2d1952 100644
--- a/scripts/README.md
+++ b/scripts/README.md
@@ -22,7 +22,7 @@ disagrees, so a green `check:release-docs` is a precondition, not a substitute.
| Script | Alias | Purpose |
|---|---|---|
-| `release-macos.sh` | `scripts/release-macos.sh` | Signed and notarized local native macOS release lane. Requires `MAC_SIGNING_IDENTITY` and Apple notarization credentials; local package and distribution lanes remain unsigned when no signing identity is configured. |
+| `notarize-and-staple-macos-release-dmg.sh` | `scripts/notarize-and-staple-macos-release-dmg.sh [release-dir]` | Submit the single DMG a native macOS job produced to Apple's notary service (`xcrun notarytool submit --wait`), require `status: Accepted`, then attach and validate the ticket (`xcrun stapler staple` / `validate`); run by the Release workflow when `sign_macos` is set. electron-builder only notarizes the `.app`, so the DMG needs this separate submission |
| `staple-macos-release-dmg.sh` | `scripts/staple-macos-release-dmg.sh [release-dir]` | Attach Apple's notarization ticket (`xcrun stapler staple`) to the single DMG a native macOS job produced; run by the Release workflow when `sign_macos` is set |
| `verify-macos-release.sh` | `scripts/verify-macos-release.sh [release-dir]` | Fail unless the one `PI-Desktop.app` and DMG under the release directory are Developer ID-signed, notarized, and stapled; run by the Release workflow after stapling |
| `export-linux-asar.mjs` | `node scripts/export-linux-asar.mjs` | Copy the Linux `linux-unpacked/resources/app.asar` into the versioned release asset used for system-Electron repackaging |
diff --git a/scripts/notarize-and-staple-macos-release-dmg.sh b/scripts/notarize-and-staple-macos-release-dmg.sh
new file mode 100755
index 000000000..b5dc63d31
--- /dev/null
+++ b/scripts/notarize-and-staple-macos-release-dmg.sh
@@ -0,0 +1,127 @@
+#!/usr/bin/env bash
+# Notarize the final macOS DMG with Apple's notary service, then staple its
+# ticket. Run after electron-builder produced the DMG.
+#
+# Why this exists: electron-builder's `mac.notarize=true` notarizes the built
+# `PI-Desktop.app` (so the app and the ZIP that carries it pass Gatekeeper and
+# in-app updates work). The DMG is a separate artifact with its own signature,
+# so it needs its own notarytool submission before it can be stapled. Stapling a
+# DMG that was never submitted fails with:
+#
+# CloudKit query ... failed due to "Record not found".
+# Could not find base64 encoded ticket
+# The staple and validate action failed! Error 65.
+#
+# Required environment (never echoed, never written to the repo):
+# APPLE_ID Apple ID email in team DUV63RKYTW
+# APPLE_APP_SPECIFIC_PASSWORD app-specific password for that Apple ID
+# APPLE_TEAM_ID must be DUV63RKYTW
+#
+# Usage: scripts/notarize-and-staple-macos-release-dmg.sh [release-dir]
+
+set -euo pipefail
+
+RELEASE_DIR="${1:-apps/desktop/release}"
+EXPECTED_TEAM_ID="DUV63RKYTW"
+# The ticket can take a moment to reach the stapler after Apple accepts, but a
+# retry is only legal once the submission returned Accepted. Overridable so
+# tests do not sleep for real.
+STAPLE_ATTEMPTS="${STAPLE_ATTEMPTS:-6}"
+STAPLE_DELAY_SECONDS="${STAPLE_DELAY_SECONDS:-10}"
+
+if [[ -z "${APPLE_ID:-}" || -z "${APPLE_APP_SPECIFIC_PASSWORD:-}" || -z "${APPLE_TEAM_ID:-}" ]]; then
+ echo "error: APPLE_ID / APPLE_APP_SPECIFIC_PASSWORD / APPLE_TEAM_ID are required to notarize the DMG." >&2
+ exit 1
+fi
+
+if [[ "$APPLE_TEAM_ID" != "$EXPECTED_TEAM_ID" ]]; then
+ echo "error: APPLE_TEAM_ID must be $EXPECTED_TEAM_ID (got: $APPLE_TEAM_ID)." >&2
+ exit 1
+fi
+
+if [[ ! -d "$RELEASE_DIR" ]]; then
+ echo "error: release directory does not exist: $RELEASE_DIR" >&2
+ exit 1
+fi
+
+shopt -s nullglob
+DMGS=("$RELEASE_DIR"/*.dmg)
+
+if [[ "${#DMGS[@]}" -ne 1 ]]; then
+ echo "error: expected exactly one DMG under $RELEASE_DIR/." >&2
+ exit 1
+fi
+
+DMG="${DMGS[0]}"
+
+SUBMIT_LOG="$(mktemp -t pi-desktop-notarytool-submit)"
+trap 'rm -f "$SUBMIT_LOG"' EXIT
+
+# `notarytool log` needs the same credentials as `submit`; both are passed on
+# the command line only, so they never appear in the job log.
+notarytool_credentials=(
+ --apple-id "$APPLE_ID"
+ --password "$APPLE_APP_SPECIFIC_PASSWORD"
+ --team-id "$APPLE_TEAM_ID"
+)
+
+print_notarization_log() {
+ local submission_id="$1"
+ if [[ -z "$submission_id" ]]; then
+ echo "==> No submission id was returned, so no Apple notarization log is available." >&2
+ return 0
+ fi
+ echo "==> Apple notarization log for submission $submission_id" >&2
+ xcrun notarytool log "$submission_id" "${notarytool_credentials[@]}" >&2 \
+ || echo "warning: could not fetch the Apple notarization log for $submission_id." >&2
+}
+
+echo "==> Submitting $DMG to the Apple notary service (waiting for the result)"
+if ! xcrun notarytool submit "$DMG" "${notarytool_credentials[@]}" --wait >"$SUBMIT_LOG" 2>&1; then
+ cat "$SUBMIT_LOG" >&2
+ SUBMISSION_ID="$(sed -n 's/^[[:space:]]*id:[[:space:]]*//p' "$SUBMIT_LOG" | head -n1)"
+ echo "error: notarytool submit failed for $DMG." >&2
+ print_notarization_log "$SUBMISSION_ID"
+ exit 1
+fi
+cat "$SUBMIT_LOG"
+
+SUBMISSION_ID="$(sed -n 's/^[[:space:]]*id:[[:space:]]*//p' "$SUBMIT_LOG" | head -n1)"
+NOTARY_STATUS="$(sed -n 's/^[[:space:]]*status:[[:space:]]*//p' "$SUBMIT_LOG" | tail -n1)"
+if [[ -z "$NOTARY_STATUS" ]]; then
+ NOTARY_STATUS="$(sed -n 's/^Current status:[[:space:]]*//p' "$SUBMIT_LOG" | tail -n1)"
+fi
+NOTARY_STATUS="${NOTARY_STATUS%%[. ]*}"
+NOTARY_STATUS="${NOTARY_STATUS%"${NOTARY_STATUS##*[![:space:]]}"}"
+
+echo "==> Apple notarization status for $DMG: ${NOTARY_STATUS:-unknown} (submission ${SUBMISSION_ID:-unknown})"
+
+if [[ "$NOTARY_STATUS" != "Accepted" ]]; then
+ echo "error: Apple did not accept $DMG (status: ${NOTARY_STATUS:-unknown})." >&2
+ echo "A DMG that was never accepted cannot be stapled, so this run fails." >&2
+ print_notarization_log "$SUBMISSION_ID"
+ exit 1
+fi
+
+echo "==> Stapling the accepted notarization ticket to $DMG"
+stapled=false
+for attempt in $(seq 1 "$STAPLE_ATTEMPTS"); do
+ if xcrun stapler staple "$DMG"; then
+ stapled=true
+ break
+ fi
+ if [[ "$attempt" -lt "$STAPLE_ATTEMPTS" ]]; then
+ echo "warning: stapler attempt $attempt/$STAPLE_ATTEMPTS failed; retrying in ${STAPLE_DELAY_SECONDS}s." >&2
+ sleep "$STAPLE_DELAY_SECONDS"
+ fi
+done
+
+if [[ "$stapled" != "true" ]]; then
+ echo "error: stapler could not attach the ticket to $DMG after $STAPLE_ATTEMPTS attempts." >&2
+ exit 1
+fi
+
+echo "==> Validating the stapled ticket on $DMG"
+xcrun stapler validate "$DMG"
+
+echo "==> Staple validation passed: $DMG (status=Accepted)"
diff --git a/scripts/release-macos.sh b/scripts/release-macos.sh
index 9d5bd2f1d..590ab9539 100755
--- a/scripts/release-macos.sh
+++ b/scripts/release-macos.sh
@@ -71,8 +71,8 @@ echo "==> Building + packaging desktop (signed, $MAC_ARCH)"
pnpm --filter @pi-desktop/desktop exec electron-vite build
pnpm --filter @pi-desktop/desktop exec electron-builder --mac "--${MAC_ARCH}" \
-c.mac.identity="${MAC_SIGNING_IDENTITY}" \
- -c.mac.forceCodeSigning=true \
- -c.mac.notarize=true
+scripts/notarize-and-staple-macos-release-dmg.sh apps/desktop/release
+scripts/verify-macos-release.sh apps/desktop/release
scripts/staple-macos-release-dmg.sh apps/desktop/release
scripts/verify-macos-release.sh apps/desktop/release
diff --git a/scripts/staple-macos-release-dmg.sh b/scripts/staple-macos-release-dmg.sh
deleted file mode 100755
index 230db7f0e..000000000
--- a/scripts/staple-macos-release-dmg.sh
+++ /dev/null
@@ -1,23 +0,0 @@
-#!/usr/bin/env bash
-# Attach Apple's notarization ticket to the one DMG built by a native macOS job.
-
-set -euo pipefail
-
-RELEASE_DIR="${1:-apps/desktop/release}"
-
-if [[ ! -d "$RELEASE_DIR" ]]; then
- echo "error: release directory does not exist: $RELEASE_DIR" >&2
- exit 1
-fi
-
-shopt -s nullglob
-DMGS=("$RELEASE_DIR"/*.dmg)
-
-if [[ "${#DMGS[@]}" -ne 1 ]]; then
- echo "error: expected exactly one DMG under $RELEASE_DIR/." >&2
- exit 1
-fi
-
-DMG="${DMGS[0]}"
-echo "==> Stapling notarization ticket to $DMG"
-xcrun stapler staple "$DMG"