scripts/release-ios.sh

63 lines · 2654 bytes · executable

 1#!/bin/sh
 2# Archives the iOS app (with its extensions and the watch app) and uploads it to App Store
 3# Connect for TestFlight, signed automatically with the team's distribution certificate through
 4# the Apple ID signed in to Xcode. The version is the project's MARKETING_VERSION; the build
 5# number is the commit count, as the Mac release's is. Run after scripts/release-mac.sh.
 6# Usage: scripts/release-ios.sh
 7#   ORGSTAR_PUBLISH  0 archives and exports the .ipa to .build/ios-release without uploading
 8set -eu
 9
10cd "$(dirname "$0")/.."
11publish="${ORGSTAR_PUBLISH:-1}"
12team=ZCNAX3VL9D
13project=ios/Orgstar.xcodeproj
14
15if [ "$publish" != 0 ]; then
16    [ -z "$(git status --porcelain)" ] || { echo "The working tree has changes." >&2; exit 1; }
17    [ "$(git branch --show-current)" = main ] || { echo "Release from main." >&2; exit 1; }
18fi
19
20version="$(sed -n 's/.*MARKETING_VERSION = \(.*\);/\1/p' "$project/project.pbxproj" | sort -u)"
21[ "$(printf '%s\n' "$version" | wc -l | tr -d ' ')" = 1 ] || { echo "The targets' MARKETING_VERSION differ: $version" >&2; exit 1; }
22build="$(git rev-list --count HEAD)"
23
24out=.build/ios-release
25rm -rf "${out:?}"
26mkdir -p "$out"
27archive="$out/orgstar.xcarchive"
28# xcodebuild rewrites the project file in its own key order; the copy puts it back as it was.
29cp "$project/project.pbxproj" "$out/project.pbxproj"
30trap 'cp "$out/project.pbxproj" "$project/project.pbxproj"' EXIT
31xcodebuild archive -project "$project" -scheme "Orgstar iOS" -configuration Release \
32    -destination 'generic/platform=iOS' -archivePath "$archive" -allowProvisioningUpdates -quiet \
33    CURRENT_PROJECT_VERSION="$build"
34
35if [ "$publish" = 0 ]; then destination=export; else destination=upload; fi
36cat > "$out/ExportOptions.plist" <<PLIST
37<?xml version="1.0" encoding="UTF-8"?>
38<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
39<plist version="1.0">
40<dict>
41    <key>method</key>
42    <string>app-store-connect</string>
43    <key>destination</key>
44    <string>$destination</string>
45    <key>teamID</key>
46    <string>$team</string>
47    <key>signingStyle</key>
48    <string>automatic</string>
49    <key>manageAppVersionAndBuildNumber</key>
50    <false/>
51    <key>uploadSymbols</key>
52    <true/>
53</dict>
54</plist>
55PLIST
56xcodebuild -exportArchive -archivePath "$archive" -exportOptionsPlist "$out/ExportOptions.plist" \
57    -exportPath "$out/export" -allowProvisioningUpdates -quiet
58
59if [ "$publish" = 0 ]; then
60    echo "Exported $(ls "$out"/export/*.ipa): $version ($build), not uploaded"
61else
62    echo "Uploaded orgstar $version ($build) to App Store Connect; it shows in TestFlight once processed"
63fi