#!/usr/bin/env bash # Release packaging: archive → Developer ID export → DMG → notarize → staple. # # Contract: # - 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. 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: # xcrun notarytool store-credentials museion-notary \ # --apple-id --team-id --password # NOTARIZE=0 skips notarize+staple (a Developer-ID-signed DMG Gatekeeper still warns on). # - Output: dist/Museion-.dmg (gitignored). The version is # read from build settings, never from the pbxproj text. Apple Silicon only — # the deployment target is macOS 27, which does not run on Intel. set -euo pipefail PROJECT="Museion.xcodeproj" SCHEME="Museion" APP_NAME="Museion.app" CONFIGURATION="Release" IDENTITY="Developer ID Application" NOTARY_PROFILE="museion-notary" DIST="dist" DESTINATION='platform=macOS,arch=arm64' cd "$(dirname "$0")/.." # repo root — PROJECT is relative (same guard as deploy.sh) if ! security find-identity -v -p codesigning | grep -q "\"$IDENTITY:"; then echo "No valid \"$IDENTITY\" identity in the keychain." >&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 \ | awk -F'= ' '/MARKETING_VERSION = / {print $2; exit}') if [[ -z "$VERSION" ]]; then echo "MARKETING_VERSION not found in build settings" >&2 exit 1 fi TEAM=$(xcodebuild -project "$PROJECT" -scheme "$SCHEME" -configuration "$CONFIGURATION" \ -destination "$DESTINATION" -showBuildSettings 2>/dev/null \ | awk -F'= ' '/DEVELOPMENT_TEAM = / {print $2; exit}') DMG="$DIST/Museion-$VERSION.dmg" echo "Packaging $SCHEME $VERSION" # xcodebuild -quiet prints nothing on success; keep the log to show on failure. log=$(mktemp -t museion-release) trap 'rm -f "$log"' EXIT run() { echo "→ $*"; if ! "$@" >"$log" 2>&1; then echo "Failed: $*" >&2; cat "$log" >&2; exit 1; fi; } rm -rf "$DIST" mkdir -p "$DIST" run xcodebuild -project "$PROJECT" -scheme "$SCHEME" -configuration "$CONFIGURATION" \ -destination "$DESTINATION" -archivePath "$DIST/Museion.xcarchive" -quiet archive cat >"$DIST/export-options.plist" < methoddeveloper-id signingStyleautomatic teamID$TEAM destinationexport EOF run xcodebuild -exportArchive -archivePath "$DIST/Museion.xcarchive" \ -exportOptionsPlist "$DIST/export-options.plist" -exportPath "$DIST/export" \ -allowProvisioningUpdates -quiet APP="$DIST/export/$APP_NAME" if [[ ! -d "$APP" ]]; then echo "Export did not produce $APP" >&2 exit 1 fi run codesign --verify --deep --strict "$APP" # 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 STAGE="$DIST/stage" mkdir -p "$STAGE" ditto "$APP" "$STAGE/$APP_NAME" # ditto preserves the bundle's signature and xattrs 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 # `--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 echo "Built: $DMG"