Repository Public
1#!/bin/zsh2# Author: Simon-Pierre Boucher — contact@spboucher.ai3# File: Scripts/ios-archive.sh4# Description: Archives and exports SP Mail for iOS / iPadOS — the app and its three extensions (widgets, share extension, notification5# service) — for App Store Connect (TestFlight) with the EXISTING App Store Connect API key (automatic signing of every target,6# -allowProvisioningUpdates). Uploading is a separate, explicit step.7#8# Usage: Scripts/ios-archive.sh archive|export|upload|all (all = archive + export; `upload` is never run implicitly)9# Prerequisites: Scripts/provision.py (bundle ids + capabilities) and, for `upload`, an App Store Connect app record for ai.spboucher.spmail.ios.10# Environment: SPMAIL_IOS_RELEASE_DD — derived data (default: $SPMAIL_DD-iOS-Release, else ~/Library/Developer/SPMail/DerivedData-iOS-Release);11# SPMAIL_IOS_APP_GROUP=1 — sign with the App Group container entitlement (see below);12# SPMAIL_IOS_ARCHIVE — archive path (default Build/SPMail-iOS.xcarchive, inside this checkout); SPMAIL_IOS_EXPORT — export folder (default dist/ios-export).13set -euo pipefail14cd "$(dirname "$0")/.."15KEY_ID="${ASC_KEY_ID:-L379BDKR69}"16ISSUER="${ASC_ISSUER_ID:-013e761f-e05c-4d93-a50b-f3d960adae4a}"17KEY="$HOME/.appstoreconnect/private_keys/AuthKey_${KEY_ID}.p8"18[[ -f "$KEY" ]] || { echo "ERROR: App Store Connect API key not found (set ASC_KEY_ID / ASC_ISSUER_ID)"; exit 1; }19AUTH=(-allowProvisioningUpdates -authenticationKeyPath "$KEY" -authenticationKeyID "$KEY_ID" -authenticationKeyIssuerID "$ISSUER")20ARCHIVE="${SPMAIL_IOS_ARCHIVE:-Build/SPMail-iOS.xcarchive}"; DD="${SPMAIL_IOS_RELEASE_DD:-${SPMAIL_DD:-$HOME/Library/Developer/SPMail/DerivedData}-iOS-Release}"; EXPORT="${SPMAIL_IOS_EXPORT:-dist/ios-export}"21# SPMAIL_IOS_APP_GROUP=1 signs with the App Group container entitlement (Config/*-iOS-AppGroup.entitlements). Only once the group22# `group.ai.spboucher.spmail` is registered and attached to the four iOS App IDs: the API key cannot do that, the archive fails otherwise.23GROUP=(); [[ "${SPMAIL_IOS_APP_GROUP:-0}" == 1 ]] && GROUP=(SPM_IOS_APP_GROUP=-AppGroup)24mkdir -p Build dist25step="${1:-all}"26if [[ "$step" == archive || "$step" == all ]]; then27 xcodegen generate --quiet28 rm -rf "$ARCHIVE"29 xcodebuild -project SPMail.xcodeproj -scheme SPMail-iOS -configuration Release -destination "generic/platform=iOS" \30 -archivePath "$ARCHIVE" -derivedDataPath "$DD" "${AUTH[@]}" "${GROUP[@]}" archive > Build/ios-archive.log 2>&1 \31 || { grep -E "error:|\*\* " Build/ios-archive.log | sort -u | head -20; exit 1; }32 APP="$ARCHIVE/Products/Applications/SP Mail.app"33 echo "archive : $(/usr/libexec/PlistBuddy -c 'Print :CFBundleShortVersionString' "$APP/Info.plist") ($(/usr/libexec/PlistBuddy -c 'Print :CFBundleVersion' "$APP/Info.plist")) $(/usr/libexec/PlistBuddy -c 'Print :CFBundleIdentifier' "$APP/Info.plist")"34 for x in "$APP"/PlugIns/*.appex; do echo "extension: $(/usr/libexec/PlistBuddy -c 'Print :CFBundleIdentifier' "$x/Info.plist") ($(/usr/libexec/PlistBuddy -c 'Print :NSExtension:NSExtensionPointIdentifier' "$x/Info.plist"))"; done35fi36if [[ "$step" == export || "$step" == all ]]; then37 rm -rf "$EXPORT"38 xcodebuild -exportArchive -archivePath "$ARCHIVE" -exportOptionsPlist Scripts/ExportOptions.plist -exportPath "$EXPORT" "${AUTH[@]}" > Build/ios-export.log 2>&1 \39 || { grep -E "error:|\*\* " Build/ios-export.log | sort -u | head -20; exit 1; }40 ls -lh "$EXPORT"/*.ipa41fi42if [[ "$step" == upload ]]; then43 xcrun altool --upload-app -f "$EXPORT/SP Mail.ipa" -t ios --apiKey "$KEY_ID" --apiIssuer "$ISSUER" 2>&1 | tee Build/ios-upload.log | tail -1244fi45