Scripts/release-ios.sh
133 lines · 4956 bytes · executable
1#!/usr/bin/env bash
2#
3# Archive the app, its widget and its share extension, and upload the result to
4# App Store Connect. Signed automatically with the team's distribution
5# certificate through the Apple ID signed in to Xcode. The upload appears in
6# TestFlight once processed, and can then be chosen for a submission.
7#
8# ./Scripts/release-ios.sh # archive, export and upload
9# DOMAIN_DIG_PUBLISH=0 ./Scripts/release-ios.sh
10# # archive and export the .ipa only
11#
12# Adapted from moonrise's scripts/release-ios.sh, with two differences that
13# matter.
14#
15# The build number is CURRENT_PROJECT_VERSION as committed, not the commit
16# count. This project sets it by hand at each cut, states it in the cut's
17# commit message, and verifies it against the built product; deriving it here
18# instead would make the committed value a lie, and the two would drift apart
19# from the first upload. moonrise has no such convention, so a commit count
20# costs it nothing.
21#
22# The preflight is stricter, because this project tags every release. A publish
23# requires HEAD to be the commit that v<version> points at, so an upload cannot
24# carry code the tag does not. It also checks the bundled release notes against
25# the marketing version, which nothing else does — the unit suite asserts the
26# notes parse, not that they describe this build.
27
28set -euo pipefail
29
30cd "$(dirname "$0")/.."
31
32PROJECT="DomainDig.xcodeproj"
33SCHEME="DomainDig"
34TEAM="ZCNAX3VL9D"
35PUBLISH="${DOMAIN_DIG_PUBLISH:-1}"
36OUT=".build/ios-release"
37
38fail() {
39 echo "release-ios: $1" >&2
40 exit 1
41}
42
43# One value across all ten configurations, or the archive would disagree with
44# the tag depending on which target you read.
45single_setting() {
46 local key="$1" values
47 values="$(grep -oE "$key = [^;]+;" "$PROJECT/project.pbxproj" | sed -E "s/$key = (.*);/\1/" | sort -u)"
48 [ "$(printf '%s\n' "$values" | wc -l | tr -d ' ')" = 1 ] \
49 || fail "$key differs across configurations: $(printf '%s' "$values" | tr '\n' ' ')"
50 printf '%s' "$values"
51}
52
53version="$(single_setting MARKETING_VERSION)"
54build="$(single_setting CURRENT_PROJECT_VERSION)"
55
56notes_version="$(
57 python3 -c 'import json,sys; print(json.load(open("DomainDig/ReleaseNotes.json"))["version"])'
58)"
59[ "$notes_version" = "$version" ] \
60 || fail "ReleaseNotes.json is $notes_version but MARKETING_VERSION is $version"
61
62if [ "$PUBLISH" != 0 ]; then
63 [ -z "$(git status --porcelain --untracked-files=no)" ] || fail "the working tree has changes"
64 [ "$(git branch --show-current)" = main ] || fail "release from main"
65 git rev-parse -q --verify "refs/tags/v$version" >/dev/null \
66 || fail "no tag v$version — cut the release first"
67 [ "$(git rev-parse "v$version^{commit}")" = "$(git rev-parse HEAD)" ] \
68 || fail "v$version does not point at HEAD"
69fi
70
71echo "==> DomainDig $version ($build)"
72
73rm -rf "${OUT:?}"
74mkdir -p "$OUT"
75archive="$OUT/DomainDig.xcarchive"
76
77echo "==> Archiving"
78xcodebuild archive \
79 -project "$PROJECT" \
80 -scheme "$SCHEME" \
81 -configuration Release \
82 -destination 'generic/platform=iOS' \
83 -archivePath "$archive" \
84 -allowProvisioningUpdates \
85 -quiet
86
87# The same check the release cuts make by hand: the project file is not the
88# product, and Xcode has migrated Info.plist keys out from under this project
89# before.
90plist="$archive/Products/Applications/DomainDig.app/Info.plist"
91built_version="$(/usr/libexec/PlistBuddy -c 'Print :CFBundleShortVersionString' "$plist")"
92built_build="$(/usr/libexec/PlistBuddy -c 'Print :CFBundleVersion' "$plist")"
93[ "$built_version" = "$version" ] || fail "archive is $built_version, expected $version"
94[ "$built_build" = "$build" ] || fail "archive is build $built_build, expected $build"
95
96if [ "$PUBLISH" = 0 ]; then destination=export; else destination=upload; fi
97cat > "$OUT/ExportOptions.plist" <<PLIST
98<?xml version="1.0" encoding="UTF-8"?>
99<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
100<plist version="1.0">
101<dict>
102 <key>method</key>
103 <string>app-store-connect</string>
104 <key>destination</key>
105 <string>$destination</string>
106 <key>teamID</key>
107 <string>$TEAM</string>
108 <key>signingStyle</key>
109 <string>automatic</string>
110 <key>manageAppVersionAndBuildNumber</key>
111 <false/>
112 <key>uploadSymbols</key>
113 <true/>
114</dict>
115</plist>
116PLIST
117
118echo "==> ${destination^}ing"
119xcodebuild -exportArchive \
120 -archivePath "$archive" \
121 -exportOptionsPlist "$OUT/ExportOptions.plist" \
122 -exportPath "$OUT/export" \
123 -allowProvisioningUpdates \
124 -quiet
125
126echo
127if [ "$PUBLISH" = 0 ]; then
128 echo "==> Exported $(ls "$OUT"/export/*.ipa 2>/dev/null | head -1)"
129 echo " DomainDig $version ($build). Not uploaded."
130else
131 echo "==> Uploaded DomainDig $version ($build) to App Store Connect."
132 echo " It appears in TestFlight once processing finishes."
133fi