#!/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 (Xcode ▸ Settings ▸ Accounts ▸ Manage Certificates… ▸ +). # The private key lives only on the Mac that created the certificate — 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: Xcode ▸ Settings ▸ Accounts ▸ Manage Certificates… ▸ + ▸ $IDENTITY" >&2 exit 1 fi 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" 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; } # 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" if [[ "${NOTARIZE:-1}" == "1" ]]; then run xcrun notarytool submit "$DMG" --keychain-profile "$NOTARY_PROFILE" --wait run xcrun stapler staple "$DMG" # The Gatekeeper verdict a downloader's Mac will reach. spctl -a -t open --context context:primary-signature -v "$DMG" fi echo "Built: $DMG"