Repository Public
1#!/bin/bash2# Release build of the macOS app: Developer ID signature (Hardened Runtime, App Sandbox, provisioning profile for3# the restricted entitlements), disk image, notarization, stapling, checksum.4# Scripts/release.sh archive + sign + dmg + notarize + staple + verify5# Scripts/release.sh --no-notarize stop after the signed dmg (dry run of the packaging)6# Output: dist/macos/MacLustr-Command-Center-<version>-<build>.dmg (+ .sha256, + notarization results).7# Nothing is installed in /Applications and the app is never launched by this script.8set -euo pipefail9cd "$(dirname "$0")/.."10ROOT="$PWD"11REPO="$(cd "$ROOT/../.." && pwd)"12IDENTITY="Developer ID Application: Simon-Pierre Boucher (3YM54G49SN)"13PROFILE_NAME="MCC macOS Developer ID"14DD="${MCC_DERIVED_DATA:-/tmp/mcc-swift/DerivedData-release}"15PROJ="$DD.project"16DIST="$REPO/dist/macos"17NOTARIZE=1; [ "${1:-}" = "--no-notarize" ] && NOTARIZE=01819security find-identity -v -p codesigning | grep -q "$IDENTITY" || { echo "signing identity not found in the keychain: $IDENTITY" >&2; exit 1; }2021# The Developer ID profile authorises Associated Domains, the keychain access group and push (restricted entitlements).22PROFILE=""23for f in "$HOME/Library/Developer/Xcode/UserData/Provisioning Profiles"/*.provisionprofile "$HOME/Library/MobileDevice/Provisioning Profiles"/*.provisionprofile \24 "$REPO/infra/apple/profiles"/*.provisionprofile; do25 [ -f "$f" ] || continue26 if security cms -D -i "$f" 2>/dev/null | plutil -extract Name raw - 2>/dev/null | grep -qx "$PROFILE_NAME"; then PROFILE="$f"; break; fi27done28if [ -z "$PROFILE" ]; then29 cat >&2 <<MSG30provisioning profile "$PROFILE_NAME" not found.31Create it first (registers the bundle ids, enables Associated Domains + Push, downloads and installs the profiles):32 ASC_KEY_ID=L379BDKR69 ASC_ISSUER_ID=<issuer uuid> python3 infra/apple/provision.py33MSG34 exit 135fi36echo "profile: $PROFILE"3738mkdir -p "$PROJ" "$DIST"39xcodegen generate --quiet --spec project.yml --project "$PROJ" --project-root .40ARCHIVE="$DD/MCC.xcarchive"41[ -d "$ARCHIVE" ] && mv "$ARCHIVE" "$ARCHIVE.previous.$$"42xcodebuild -project "$PROJ/MCC.xcodeproj" -scheme MCC -configuration Release -derivedDataPath "$DD" -destination 'generic/platform=macOS' \43 -archivePath "$ARCHIVE" -skipPackagePluginValidation -skipMacroValidation MCC_ROOT="$ROOT" archive > "$DD.archive.log" 2>&1 \44 || { grep -E "error:|ARCHIVE FAILED" "$DD.archive.log" | sort -u | head -40; exit 1; }45APP="$ARCHIVE/Products/Applications/MacLustr Command Center.app"46[ -d "$APP" ] || { echo "archive did not produce the app" >&2; exit 1; }4748VERSION="$(/usr/libexec/PlistBuddy -c 'Print :CFBundleShortVersionString' "$APP/Contents/Info.plist")"49BUILD="$(/usr/libexec/PlistBuddy -c 'Print :CFBundleVersion' "$APP/Contents/Info.plist")"50NAME="MacLustr-Command-Center-$VERSION-$BUILD"51STAGE="$(mktemp -d /tmp/mcc-swift-release.XXXXXX)"52ditto "$APP" "$STAGE/MacLustr Command Center.app"53APP="$STAGE/MacLustr Command Center.app"54codesign --verify --deep --strict "$APP"5556if [ $NOTARIZE -eq 1 ]; then57 # 1) notarize and staple the app itself, so that it validates offline once copied out of the disk image58 ZIP="$(mktemp -d /tmp/mcc-swift-zip.XXXXXX)/app.zip"59 ditto -c -k --keepParent "$APP" "$ZIP"60 "$ROOT/Scripts/notarize.sh" "$ZIP" "$DIST/$NAME.app.notarization.json"61 xcrun stapler staple "$APP"62fi6364ln -s /Applications "$STAGE/Applications"65# -ov replaces a previous image of the same version66hdiutil create -quiet -volname "MacLustr Command Center" -srcfolder "$STAGE" -ov -format UDZO "$DIST/$NAME.dmg"67codesign --sign "$IDENTITY" --timestamp "$DIST/$NAME.dmg"6869if [ $NOTARIZE -eq 1 ]; then70 # 2) notarize and staple the disk image71 "$ROOT/Scripts/notarize.sh" "$DIST/$NAME.dmg" "$DIST/$NAME.dmg.notarization.json"72 xcrun stapler staple "$DIST/$NAME.dmg"73fi74(cd "$DIST" && shasum -a 256 "$NAME.dmg" > "$NAME.dmg.sha256" && cat "$NAME.dmg.sha256")75if [ $NOTARIZE -eq 1 ]; then "$ROOT/Scripts/verify-release.sh" "$DIST/$NAME.dmg"; fi76echo "$DIST/$NAME.dmg"77echo "(temporary staging left in $STAGE)"78