scripts/release-ios.sh
63 lines · 2642 bytes · executable
1#!/bin/sh
2# Archives the iOS app (with its widgets and the watch app) and uploads it to App Store Connect,
3# signed automatically with the team's distribution certificate through the Apple ID signed in
4# to Xcode. The version is MARKETING_VERSION in App/project.yml; the build number is the commit
5# count on main, so every upload can be traced to a commit. The upload then shows in TestFlight
6# and can be picked for an App Store submission.
7# Usage: scripts/release-ios.sh
8# MOONRISE_PUBLISH 0 archives and exports the .ipa to .build/ios-release without uploading
9set -eu
10
11cd "$(dirname "$0")/.."
12publish="${MOONRISE_PUBLISH:-1}"
13team=ZCNAX3VL9D
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' App/project.yml | 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
24command -v xcodegen >/dev/null || { echo "Install XcodeGen: brew install xcodegen" >&2; exit 1; }
25(cd App && xcodegen generate --quiet)
26
27out=.build/ios-release
28rm -rf "${out:?}"
29mkdir -p "$out"
30archive="$out/moonrise.xcarchive"
31xcodebuild archive -project App/Moonrise.xcodeproj -scheme Moonrise -configuration Release \
32 -destination 'generic/platform=iOS' -archivePath "$archive" -allowProvisioningUpdates -quiet \
33 MARKETING_VERSION="$version" 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 Moonrise $version ($build) to App Store Connect; it shows in TestFlight once processed"
63fi