Repository Public
1#!/usr/bin/env bash2# Author: Simon-Pierre Boucher — contact@spboucher.ai3# File: Scripts/release.sh4# Description: Builds the Release archive of SP Chat signed with the EXISTING Developer ID Application identity and the Developer ID provisioning profile (Associated Domains for passkeys), exports dist/SP Chat.app.5#6# Usage: Scripts/release.sh7# Nothing secret is printed. No certificate is created: the script fails if no Developer ID Application identity exists.8set -euo pipefail9cd "$(dirname "$0")/.."10ROOT="$PWD"; LOG="$ROOT/build/release-build.log"; APPNAME="SP Chat"11PROFILE_SRC="$ROOT/SPChat/Build/SPChat_Developer_ID.provisionprofile"12mkdir -p build dist1314IDENTITY="$(security find-identity -v -p codesigning | sed -n 's/.*"\(Developer ID Application: [^"]*\)".*/\1/p' | head -1)"15[[ -n "$IDENTITY" ]] || { echo "ERROR: no 'Developer ID Application' identity in the keychain." >&2; exit 1; }16TEAM="$(sed -n 's/.*(\([A-Z0-9]\{10\}\)).*/\1/p' <<<"$IDENTITY")"17echo "Signing identity : $IDENTITY"18echo "Team : $TEAM"1920# the provisioning profile carries the restricted entitlement com.apple.developer.associated-domains21[[ -f "$PROFILE_SRC" ]] || { echo "ERROR: $PROFILE_SRC missing (create it with Scripts/provision.py)." >&2; exit 1; }22PLIST="$(mktemp)"; security cms -D -i "$PROFILE_SRC" > "$PLIST" 2>/dev/null23UUID="$(/usr/libexec/PlistBuddy -c 'Print :UUID' "$PLIST")"; PNAME="$(/usr/libexec/PlistBuddy -c 'Print :Name' "$PLIST")"24EXPIRES="$(/usr/libexec/PlistBuddy -c 'Print :ExpirationDate' "$PLIST")"; rm -f "$PLIST"25for d in "$HOME/Library/Developer/Xcode/UserData/Provisioning Profiles" "$HOME/Library/MobileDevice/Provisioning Profiles"; do mkdir -p "$d"; cp "$PROFILE_SRC" "$d/$UUID.provisionprofile"; done26echo "Profile : $PNAME ($UUID), expires $EXPIRES"2728xcodegen generate --quiet29ARCHIVE="$ROOT/build/SPChat.xcarchive"30rm -rf "$ARCHIVE" "$ROOT/dist/$APPNAME.app"31echo "Archiving (log: build/release-build.log)…"32if ! xcodebuild -project SPChat.xcodeproj -scheme SPChat -configuration Release -derivedDataPath build/DerivedData-Release \33 -destination 'generic/platform=macOS' -archivePath "$ARCHIVE" archive DEVELOPMENT_TEAM="$TEAM" >"$LOG" 2>&1; then34 grep -E "error:|ARCHIVE FAILED" "$LOG" | sort -u | head -30 >&235 echo "ERROR: archive failed, see $LOG" >&2; exit 136fi37ditto "$ARCHIVE/Products/Applications/$APPNAME.app" "$ROOT/dist/$APPNAME.app"38APP="dist/$APPNAME.app"39VERSION="$(/usr/libexec/PlistBuddy -c 'Print :CFBundleShortVersionString' "$APP/Contents/Info.plist")"; BUILD="$(/usr/libexec/PlistBuddy -c 'Print :CFBundleVersion' "$APP/Contents/Info.plist")"40echo "Built $APP version $VERSION ($BUILD) archs: $(lipo -archs "$APP/Contents/MacOS/$APPNAME")"41codesign --verify --deep --strict --verbose=2 "$APP" 2>&1 | tail -242echo "Next: Scripts/verify-release.sh, then Scripts/notarize.sh"43