From a216fe371a7c0ac34a1bcd5c02aec02dbb30b918 Mon Sep 17 00:00:00 2001 From: wangzhizhou <824219521@qq.com> Date: Mon, 23 Nov 2026 09:56:23 +0800 Subject: [PATCH 1/3] fix(release): print Apple's notary diagnostics and tolerate pretty JSON The v1.4.2 notarization came back Invalid and the only visible symptom was stapler failing with error 65, so there was no way to tell why. Parse the submit result, and on rejection fetch `notarytool log` for that id and print it. Also match the pretty-printed JSON notarytool actually emits (spaces around the colon), which the first version did not. The mock xcrun now answers like the real one: Accepted, Invalid (with a log document), or a hard error. Signed-off-by: wangzhizhou <824219521@qq.com> --- packaging/macos/ci-sign.sh | 23 +++++++++++++++++++++-- packaging/macos/tests/test-ci-sign.py | 17 +++++++++++++++-- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/packaging/macos/ci-sign.sh b/packaging/macos/ci-sign.sh index d19db4d5..0b7b311f 100644 --- a/packaging/macos/ci-sign.sh +++ b/packaging/macos/ci-sign.sh @@ -32,6 +32,25 @@ while [ "$#" -gt 0 ]; do *) echo "用法:$0 [--cleanup] [--app ] [--also ]... [--installer ] [--uninstaller ] [--sign-only] [--dmg ]" >&2; exit 2 ;; esac done +# 提交公证并读回结论:Apple 判 Invalid 时打印它自己的诊断(否则只看到 stapler 报错, +# 只能靠猜——2026-11-23 的 v1.4.2 就卡在这里)。 +notarize() { + local target="$1" output status id + output="$(xcrun notarytool submit "${target}" --key "${WORK}/api-key.p8" \ + --key-id "${ASC_API_KEY_ID}" --issuer "${ASC_API_ISSUER_ID}" \ + --wait --timeout 45m --output-format json)" || return 1 + status="$(printf '%s' "${output}" | sed -n 's/.*"status"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p')" + id="$(printf '%s' "${output}" | sed -n 's/.*"id"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p')" + if [ "${status}" != "Accepted" ]; then + echo "公证未通过(status=${status:-unknown}, id=${id:-unknown})" >&2 + if [ -n "${id}" ]; then + xcrun notarytool log "${id}" --key "${WORK}/api-key.p8" \ + --key-id "${ASC_API_KEY_ID}" --issuer "${ASC_API_ISSUER_ID}" >&2 || true + fi + return 1 + fi +} + if [ -n "${DMG}" ]; then [ -f "${DMG}" ] && [ ! -L "${DMG}" ] || { echo "待签名 DMG 不存在:${DMG}" >&2; exit 1; } else @@ -93,7 +112,7 @@ sign_app() { } if [ -n "${DMG}" ]; then codesign --force --timestamp --keychain "${KEYCHAIN}" --sign "${IDENTITY_HASH}" "${DMG}" - xcrun notarytool submit "${DMG}" --key "${WORK}/api-key.p8" --key-id "${ASC_API_KEY_ID}" --issuer "${ASC_API_ISSUER_ID}" --wait --timeout 45m + notarize "${DMG}" xcrun stapler staple "${DMG}" xcrun stapler validate "${DMG}" spctl --assess --type open --context context:primary-signature --verbose=2 "${DMG}" @@ -113,7 +132,7 @@ for extra in "${EXTRA_APPS[@]+"${EXTRA_APPS[@]}"}"; do ditto "${extra}" "${NOTARIZE}/$(basename "${extra}")" done ditto -c -k --keepParent "${NOTARIZE}" "${WORK}/notarization.zip" -xcrun notarytool submit "${WORK}/notarization.zip" --key "${WORK}/api-key.p8" --key-id "${ASC_API_KEY_ID}" --issuer "${ASC_API_ISSUER_ID}" --wait --timeout 45m +notarize "${WORK}/notarization.zip" for notarized in "${APP}" "${EXTRA_APPS[@]+"${EXTRA_APPS[@]}"}"; do xcrun stapler staple "${notarized}" xcrun stapler validate "${notarized}" diff --git a/packaging/macos/tests/test-ci-sign.py b/packaging/macos/tests/test-ci-sign.py index e1fad40d..ae88ee29 100644 --- a/packaging/macos/tests/test-ci-sign.py +++ b/packaging/macos/tests/test-ci-sign.py @@ -37,7 +37,16 @@ if [ "$1" = create-keychain ]; then touch "${!#}"; fi if [ "$1" = delete-keychain ]; then rm -f "${!#}"; fi;; ditto) touch "${!#}";; -xcrun) if [ "$1" = notarytool ] && [ "${MOCK_NOTARY_FAIL:-0}" = 1 ]; then exit 77; fi;; +xcrun) + if [ "$1" = notarytool ]; then + case "$2" in + submit) + if [ "${MOCK_NOTARY_ERROR:-0}" = 1 ]; then exit 77; fi + if [ "${MOCK_NOTARY_FAIL:-0}" = 1 ]; then printf '{\n "id" : "mock",\n "status" : "Invalid"\n}\n'; + else printf '{\n "id" : "mock",\n "status" : "Accepted"\n}\n'; fi;; + log) printf '{"issues":[{"message":"fixture rejection"}]}\n';; + esac + fi;; esac ''' for name in ("security", "codesign", "ditto", "xcrun", "spctl"): @@ -51,10 +60,14 @@ MACOS_SIGNING_IDENTITY="Developer ID Application: Fixture", ASC_API_KEY_P8_BASE64=fixture, ASC_API_KEY_ID="fixture", ASC_API_ISSUER_ID="fixture", ) - for failure, expected in (("0", 0), ("1", 77)): + for failure, expected in (("0", 0), ("1", 1)): result = subprocess.run(["bash", str(SCRIPT), "--app", str(app)], env=dict(env, MOCK_NOTARY_FAIL=failure), capture_output=True, text=True) assert result.returncode == expected, result.stderr + if failure == "1": + # Apple 判 Invalid 时必须把它自己的诊断打出来,否则只剩 stapler 报错。 + assert "公证未通过" in result.stderr, result.stderr + assert "fixture rejection" in result.stderr, result.stderr assert not (root / "lampyris-signing").exists() assert (root / "search-list.log").read_text().splitlines()[-1] == "list-keychains -d user -s /fixture/login.keychain-db" result = subprocess.run(["bash", str(SCRIPT), "--app", str(app)], From d72e58de3b32bc1e108be000aa752a4c70d7acad Mon Sep 17 00:00:00 2001 From: wangzhizhou <824219521@qq.com> Date: Mon, 23 Nov 2026 10:01:14 +0800 Subject: [PATCH 2/3] test(packaging): follow the notarize() helper in the ci-sign contract ci-sign.sh now submits through notarize(); the contract test still looked for the raw notarytool invocation. Signed-off-by: wangzhizhou <824219521@qq.com> --- packaging/macos/tests/test-dmg-updater.py | 1 + 1 file changed, 1 insertion(+) diff --git a/packaging/macos/tests/test-dmg-updater.py b/packaging/macos/tests/test-dmg-updater.py index 425e8a30..60eeb08d 100644 --- a/packaging/macos/tests/test-dmg-updater.py +++ b/packaging/macos/tests/test-dmg-updater.py @@ -167,6 +167,7 @@ def test_acceptance_workflow_builds_and_notarizes_the_updater(self): signer = (ROOT / 'packaging/macos/ci-sign.sh').read_text() self.assertIn('--also', signer) self.assertIn('notarytool submit "${WORK}/notarization.zip"', signer) + self.assertIn('notarize "${WORK}/notarization.zip"', signer) for target in ('ditto "${APP}" "${NOTARIZE}', 'stapler staple "${notarized}"'): self.assertIn(target, signer) From 97fa2efab781a284115a511d8c4cbef7c9313943 Mon Sep 17 00:00:00 2001 From: wangzhizhou <824219521@qq.com> Date: Mon, 23 Nov 2026 10:01:30 +0800 Subject: [PATCH 3/3] test(packaging): drop the duplicated notarytool assertion Signed-off-by: wangzhizhou <824219521@qq.com> --- packaging/macos/tests/test-dmg-updater.py | 1 - 1 file changed, 1 deletion(-) diff --git a/packaging/macos/tests/test-dmg-updater.py b/packaging/macos/tests/test-dmg-updater.py index 60eeb08d..6b4c199f 100644 --- a/packaging/macos/tests/test-dmg-updater.py +++ b/packaging/macos/tests/test-dmg-updater.py @@ -166,7 +166,6 @@ def test_acceptance_workflow_builds_and_notarizes_the_updater(self): self.assertNotIn('ci-sign.sh --app platforms/macos/build/website-updater', workflow) signer = (ROOT / 'packaging/macos/ci-sign.sh').read_text() self.assertIn('--also', signer) - self.assertIn('notarytool submit "${WORK}/notarization.zip"', signer) self.assertIn('notarize "${WORK}/notarization.zip"', signer) for target in ('ditto "${APP}" "${NOTARIZE}', 'stapler staple "${notarized}"'): self.assertIn(target, signer)