fix(release): make packaging survive real runs
The first real notarization runs exposed five ways the script lied or stopped short. codesign's Authority output was grepped through a pipe, so under pipefail a grep -q match SIGPIPEd codesign and a good export read as "not Developer ID signed"; the dump is captured first. notarytool --wait exits 0 for an Invalid submission, so the verdict is now the status field of its JSON, with Apple's log printed on anything but Accepted. The DMG itself is signed before submission (Gatekeeper's open-assessment needs a signature for the ticket to ride), and the staple is retried because the ticket can reach the CDN after Accepted. Two checks run before anything is notarized: the exported app must not link libyaml and the bundled apex must run from the export. Both would have caught the broken bundle the first Accepted DMG carried. The identity refusal now points at developer.apple.com + a Keychain Access CSR, because Xcode 27.2's Manage Certificates refuses Developer ID creation even for the Account Holder.
This commit is contained in:
1 parent
217a87324e
commit
5f92241308
1 file changed
+39
-7
+39
-7
@@ -5,8 +5,10 @@
|
||||
# - Bumps nothing and tags nothing. Run from the commit that already carries
|
||||
# the version in MARKETING_VERSION; the git tag is the caller's job.
|
||||
# - Refuses BEFORE building when no valid "Developer ID Application" identity
|
||||
# is in the keychain (Xcode ▸ Settings ▸ Accounts ▸ Manage Certificates… ▸ +).
|
||||
# The private key lives only on the Mac that created the certificate — a
|
||||
# is in the keychain. Create it at developer.apple.com ▸ Certificates ▸ + ▸
|
||||
# Developer ID Application from a Keychain Access ▸ Certificate Assistant CSR —
|
||||
# Xcode's Manage Certificates refuses this even for the Account Holder (stale
|
||||
# role cache). The private key lives only on the Mac that made the CSR — a
|
||||
# portal-side certificate without it is not an identity.
|
||||
# - Notarizes through the `museion-notary` notarytool keychain profile, created
|
||||
# once by the Account Holder:
|
||||
@@ -31,9 +33,10 @@ cd "$(dirname "$0")/.." # repo root — PROJECT is relative (same guard as dep
|
||||
|
||||
if ! security find-identity -v -p codesigning | grep -q "\"$IDENTITY:"; then
|
||||
echo "No valid \"$IDENTITY\" identity in the keychain." >&2
|
||||
echo "Create it once: Xcode ▸ Settings ▸ Accounts ▸ Manage Certificates… ▸ + ▸ $IDENTITY" >&2
|
||||
echo "Create it once: developer.apple.com ▸ Certificates ▸ + ▸ $IDENTITY (CSR from Keychain Access ▸ Certificate Assistant)" >&2
|
||||
exit 1
|
||||
fi
|
||||
SIGNER=$(security find-identity -v -p codesigning | sed -n 's/.*"\('"$IDENTITY"':[^"]*\)".*/\1/p' | head -1)
|
||||
|
||||
VERSION=$(xcodebuild -project "$PROJECT" -scheme "$SCHEME" -configuration "$CONFIGURATION" \
|
||||
-destination "$DESTINATION" -showBuildSettings 2>/dev/null \
|
||||
@@ -80,8 +83,18 @@ if [[ ! -d "$APP" ]]; then
|
||||
exit 1
|
||||
fi
|
||||
run codesign --verify --deep --strict "$APP"
|
||||
codesign -dvv "$APP" 2>&1 | grep -q '^Authority=Developer ID Application' \
|
||||
|| { echo "Export is not Developer ID signed:" >&2; codesign -dvv "$APP" 2>&1 | grep '^Authority=' >&2; exit 1; }
|
||||
# Capture first: `codesign -dvv | grep -q` SIGPIPEs codesign under pipefail (grep
|
||||
# quits at the first Authority line while codesign still writes its Info.plist dump).
|
||||
SIGNATURE=$(codesign -dvv "$APP" 2>&1)
|
||||
grep -q '^Authority=Developer ID Application' <<<"$SIGNATURE" \
|
||||
|| { echo "Export is not Developer ID signed:" >&2; grep '^Authority=' <<<"$SIGNATURE" >&2; exit 1; }
|
||||
# The bundled renderer must run from the SHIPPED layout (rpath → Resources/libyaml.bundle), and
|
||||
# the app must not link libyaml — a bare dylib in the synced Resources folder becomes a link target
|
||||
# silently (Xcode sniffs Mach-O content), which is why the vendored copy sits in a .bundle.
|
||||
if otool -L "$APP/Contents/MacOS/$SCHEME" | grep -q libyaml; then
|
||||
echo "The app links libyaml — it must only be apex's dependency, never the app's" >&2; exit 1
|
||||
fi
|
||||
run "$APP/Contents/Resources/apex" --version
|
||||
|
||||
# A mounted leftover from an earlier run makes the create fail with a busy volume.
|
||||
hdiutil detach "/Volumes/$SCHEME $VERSION" -quiet 2>/dev/null || true
|
||||
@@ -92,10 +105,29 @@ ln -s /Applications "$STAGE/Applications"
|
||||
# diskutil image create replaces the deprecated `hdiutil create` (macOS 27).
|
||||
run diskutil image create from --format UDZO --volumeName "$SCHEME $VERSION" "$STAGE" "$DMG"
|
||||
rm -rf "$STAGE" "$DIST/export"
|
||||
# Gatekeeper's open-assessment needs the IMAGE signed too; the notary ticket is stapled onto this signature.
|
||||
run codesign --timestamp --sign "$SIGNER" "$DMG"
|
||||
|
||||
if [[ "${NOTARIZE:-1}" == "1" ]]; then
|
||||
run xcrun notarytool submit "$DMG" --keychain-profile "$NOTARY_PROFILE" --wait
|
||||
run xcrun stapler staple "$DMG"
|
||||
# `--wait` exits 0 on Invalid too — the status FIELD is the verdict. (JSON goes to
|
||||
# stdout only; notarytool has no output-path option.)
|
||||
echo "→ xcrun notarytool submit $DMG --keychain-profile $NOTARY_PROFILE --wait"
|
||||
if ! xcrun notarytool submit "$DMG" --keychain-profile "$NOTARY_PROFILE" --wait --output-format json >"$DIST/notary.json" 2>"$log"; then
|
||||
echo "Failed: notarytool submit" >&2; cat "$log" >&2; exit 1
|
||||
fi
|
||||
if ! grep -Eq '"status" *: *"Accepted"' "$DIST/notary.json"; then
|
||||
echo "Notarization not accepted — Apple's log:" >&2
|
||||
xcrun notarytool log --keychain-profile "$NOTARY_PROFILE" \
|
||||
"$(awk -F'"' '/"id" *:/ {print $4; exit}' "$DIST/notary.json")" >&2
|
||||
exit 1
|
||||
fi
|
||||
# The ticket can reach the CDN a few seconds after "Accepted"; stapler 404s in that window.
|
||||
for attempt in 1 2 3 4 5 6; do
|
||||
xcrun stapler staple "$DMG" && break
|
||||
[[ "$attempt" == 6 ]] && { echo "Stapling failed after 6 attempts; retry: xcrun stapler staple $DMG" >&2; exit 1; }
|
||||
echo " ticket not on the CDN yet, retrying in 10 s ($attempt/6)…"
|
||||
sleep 10
|
||||
done
|
||||
# The Gatekeeper verdict a downloader's Mac will reach.
|
||||
spctl -a -t open --context context:primary-signature -v "$DMG"
|
||||
fi
|
||||
|
||||
Reference in new issue
Block a user