Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions packaging/macos/ci-sign.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,25 @@ while [ "$#" -gt 0 ]; do
*) echo "用法:$0 [--cleanup] [--app <path.app>] [--also <path.app>]... [--installer <path.app>] [--uninstaller <path.app>] [--sign-only] [--dmg <path.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
Expand Down Expand Up @@ -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}"
Expand All @@ -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}"
Expand Down
17 changes: 15 additions & 2 deletions packaging/macos/tests/test-ci-sign.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand All @@ -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)],
Expand Down
2 changes: 1 addition & 1 deletion packaging/macos/tests/test-dmg-updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ 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)

Expand Down
Loading