Repository Public
1#!/usr/bin/env bash2# Author: Simon-Pierre Boucher — contact@spboucher.ai3# File: Scripts/release.sh4# Description: Builds the universal Release archive of SP Mail for macOS, signed with the EXISTING Developer ID Application identity and the5# Developer ID provisioning profiles — one for the app (Associated Domains for passkeys, push) and one for each embedded extension (widgets,6# share extension, notification service: shared keychain group) — and exports dist/SP Mail.app. The DMG is made by Scripts/notarize.sh.7#8# Usage: Scripts/release.sh9# Environment: SPMAIL_RELEASE_DD — derived data of the Release build (default: $SPMAIL_DD-Release, else ~/Library/Developer/SPMail/DerivedData-Release);10# SPMAIL_ARCHIVE — archive path (default Build/SPMail.xcarchive, inside this checkout).11# Nothing secret is printed. No certificate is created: the script fails if no Developer ID Application identity exists.12set -euo pipefail13cd "$(dirname "$0")/.."14ROOT="$PWD"; LOG="$ROOT/Build/release-build.log"; APPNAME="SP Mail"15DD="${SPMAIL_RELEASE_DD:-${SPMAIL_DD:-$HOME/Library/Developer/SPMail/DerivedData}-Release}"16PROFILES=(SPMail SPMailWidgets SPMailShare SPMailNotifications) # the app, then one per extension17mkdir -p Build dist1819IDENTITY="$(security find-identity -v -p codesigning | sed -n 's/.*"\(Developer ID Application: [^"]*\)".*/\1/p' | head -1)"20[[ -n "$IDENTITY" ]] || { echo "ERROR: no 'Developer ID Application' identity in the keychain." >&2; exit 1; }21TEAM="$(sed -n 's/.*(\([A-Z0-9]\{10\}\)).*/\1/p' <<<"$IDENTITY")"22echo "Signing identity : $IDENTITY"2324# the provisioning profiles carry the restricted entitlements (associated domains, push, keychain access groups); one per signed bundle25for p in "${PROFILES[@]}"; do26 SRC="$ROOT/Build/profiles/$p.provisionprofile"27 [[ -f "$SRC" ]] || { echo "ERROR: $SRC missing (create it with Scripts/provision.py)." >&2; exit 1; }28 PLIST="$(mktemp)"; security cms -D -i "$SRC" > "$PLIST" 2>/dev/null29 UUID="$(/usr/libexec/PlistBuddy -c 'Print :UUID' "$PLIST")"; PNAME="$(/usr/libexec/PlistBuddy -c 'Print :Name' "$PLIST")"30 EXPIRES="$(/usr/libexec/PlistBuddy -c 'Print :ExpirationDate' "$PLIST")"; rm -f "$PLIST"31 for d in "$HOME/Library/Developer/Xcode/UserData/Provisioning Profiles" "$HOME/Library/MobileDevice/Provisioning Profiles"; do mkdir -p "$d"; cp "$SRC" "$d/$UUID.provisionprofile"; done32 echo "Profile : $PNAME ($UUID), expires $EXPIRES"33done3435xcodegen generate --quiet36ARCHIVE="${SPMAIL_ARCHIVE:-$ROOT/Build/SPMail.xcarchive}"37rm -rf "$ARCHIVE" "$ROOT/dist/$APPNAME.app"38echo "Archiving (log: Build/release-build.log)…"39if ! xcodebuild -project SPMail.xcodeproj -scheme SPMail -configuration Release -derivedDataPath "$DD" \40 -destination 'generic/platform=macOS' -archivePath "$ARCHIVE" archive DEVELOPMENT_TEAM="$TEAM" >"$LOG" 2>&1; then41 grep -E "error:|ARCHIVE FAILED" "$LOG" | sort -u | head -30 >&242 echo "ERROR: archive failed, see $LOG (a transient 'timestamp service is not available' only needs a retry)" >&2; exit 143fi44ditto "$ARCHIVE/Products/Applications/$APPNAME.app" "$ROOT/dist/$APPNAME.app"45APP="dist/$APPNAME.app"46VERSION="$(/usr/libexec/PlistBuddy -c 'Print :CFBundleShortVersionString' "$APP/Contents/Info.plist")"; BUILD="$(/usr/libexec/PlistBuddy -c 'Print :CFBundleVersion' "$APP/Contents/Info.plist")"47echo "Built $APP version $VERSION ($BUILD) archs: $(lipo -archs "$APP/Contents/MacOS/$APPNAME")"48codesign --verify --deep --strict --verbose=2 "$APP" 2>&1 | tail -249for x in "$APP"/Contents/PlugIns/*.appex; do50 codesign --verify --strict "$x" 2>/dev/null && echo "Extension : $(basename "$x") — $(codesign -dvv "$x" 2>&1 | sed -n 's/^Identifier=//p') signed" || { echo "ERROR: $(basename "$x") is not correctly signed" >&2; exit 1; }51done52echo "Next: Scripts/verify-release.sh, then Scripts/notarize.sh"53