Branchwell

Graphley / app · graphley.ai / scripts / release-ios.sh

Raw 5.6 KB on 089159c793cd9cbff9078de2ee49995b60c6b768
1#!/bin/zsh
2# Upload may automatically distribute to existing Apple-side groups. Never upload
3# before verifying all current groups, assignments, internal users and auto-distribution.
4if [[ "${GRAPHLEY_OWNER_TESTFLIGHT_VERIFIED:-}" != "1" ]]; then
5 echo "Owner-only audience has not been verified. Review App Store Connect TestFlight before uploading." >&2
6 exit 1
7fi
8
9# Build Graphley for iPhone and upload it to TestFlight.
10#
11# scripts/release-ios.sh [--build N]
12#
13# Uses the version in project.yml. The build number defaults to one more than the newest
14# build App Store Connect has for that version. See RELEASING.md for what it expects.
15set -euo pipefail
16
17build=""
18while (( $# )); do
19 case "$1" in
20 --build) build="$2"; shift 2 ;;
21 *) sed -n '2,7p' "$0" | sed 's/^# \{0,1\}//'; exit 2 ;;
22 esac
23done
24
25root="${0:A:h:h}"
26team="22HV69L32T"
27bundle_id="com.protomota.graphley"
28app_id="6838869929" # Graphley: App & Site Analytics in App Store Connect
29profile_name="Graphley App Store"
30version="$(sed -n 's/^ MARKETING_VERSION: "\(.*\)"$/\1/p' "$root/project.yml" | head -1)"
31
32work="${GRAPHLEY_RELEASE_DIR:-/Volumes/Expand/Projects/Graphley/release}"
33if [[ -z "${GRAPHLEY_RELEASE_DIR:-}" && ! -d /Volumes/Expand ]]; then
34 echo "The Expand drive is not mounted. Mount it or set GRAPHLEY_RELEASE_DIR." >&2; exit 1
35fi
36secrets="$(mktemp -d)"; chmod 700 "$secrets"
37trap 'rm -rf "$secrets"' EXIT
38step() { print -P "\n%B== $1%b"; }
39
40# --- Credentials: the team's App Store Connect upload key, from the environment or Bitwarden Secrets
41# Manager. The default prefix is the same upload credential Jotley's release script uses.
42bws_value() {
43 local token="${BWS_ACCESS_TOKEN:-$(launchctl getenv BWS_ACCESS_TOKEN 2>/dev/null || true)}"
44 [[ -n "$token" ]] || return 1
45 BWS_ACCESS_TOKEN="$token" bws secret list --output json 2>/dev/null |
46 /usr/bin/python3 -c 'import json,sys; print(next(s["value"] for s in json.load(sys.stdin) if s["key"]==sys.argv[1]).replace("\\n", "\n"), end="")' "$1"
47}
48if [[ -z "${APPLE_API_KEY_ID:-}" ]]; then
49 prefix="${GRAPHLEY_ASC_SECRET_PREFIX:-INKSPRING_ASC_UPLOAD}"
50 APPLE_API_KEY_ID="$(bws_value "${prefix}_KEY_ID")"
51 APPLE_API_ISSUER="$(bws_value "${prefix}_ISSUER_ID")"
52 ( umask 077; bws_value "${prefix}_PRIVATE_KEY" > "$secrets/AuthKey_$APPLE_API_KEY_ID.p8"; echo >> "$secrets/AuthKey_$APPLE_API_KEY_ID.p8" )
53else
54 ( umask 077; cp "$APPLE_API_KEY_PATH" "$secrets/AuthKey_$APPLE_API_KEY_ID.p8" )
55fi
56export APPLE_API_KEY_ID APPLE_API_ISSUER
57export APPLE_API_KEY_FILE="$secrets/AuthKey_$APPLE_API_KEY_ID.p8"
58api() { /usr/bin/python3 "$root/scripts/asc.py" "$@"; }
59
60if [[ -z "$build" ]]; then
61 build=$(( $(api latest-build "$app_id" "$version") + 1 ))
62fi
63out="$work/ios-$version-$build"
64mkdir -p "$out"
65
66# --- Signing: the App Store profile, installed from signing/ when it is missing.
67profile_dir="$HOME/Library/Developer/Xcode/UserData/Provisioning Profiles"
68if [[ -f "$root/signing/Graphley_App_Store.mobileprovision" ]]; then
69 mkdir -p "$profile_dir"
70 cp "$root/signing/Graphley_App_Store.mobileprovision" "$profile_dir/Graphley_App_Store.mobileprovision"
71fi
72
73if [[ -f "$out/export/Graphley.ipa" ]]; then
74 echo "Using the build already exported in $out."
75 ipa="$out/export/Graphley.ipa"
76else
77 step "Generate the Xcode project"
78 ( cd "$root" && xcodegen generate --quiet )
79
80 step "Archive Graphley $version ($build) for iPhone"
81 archive="$out/Graphley.xcarchive"
82 xcodebuild archive -project "$root/Graphley.xcodeproj" -scheme GraphleyPhone -configuration Release \
83 -destination 'generic/platform=iOS' -archivePath "$archive" -derivedDataPath "$work/derived-ios-release" \
84 CODE_SIGN_STYLE=Manual "CODE_SIGN_IDENTITY=Apple Distribution" "DEVELOPMENT_TEAM=$team" \
85 "GRAPHLEY_IOS_RELEASE_PROFILE=$profile_name" \
86 MARKETING_VERSION="$version" CURRENT_PROJECT_VERSION="$build" > "$out/archive.log" 2>&1 ||
87 { grep -E "error:" "$out/archive.log" | tail -20 >&2; exit 1; }
88
89 step "Export for App Store Connect"
90 cat > "$out/ExportOptions.plist" <<PLIST
91<?xml version="1.0" encoding="UTF-8"?>
92<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
93<plist version="1.0"><dict>
94 <key>method</key><string>app-store-connect</string>
95 <key>destination</key><string>export</string>
96 <key>teamID</key><string>$team</string>
97 <key>signingStyle</key><string>manual</string>
98 <key>signingCertificate</key><string>Apple Distribution</string>
99 <key>provisioningProfiles</key><dict><key>$bundle_id</key><string>$profile_name</string></dict>
100 <key>manageAppVersionAndBuildNumber</key><false/>
101</dict></plist>
102PLIST
103 xcodebuild -exportArchive -archivePath "$archive" -exportPath "$out/export" \
104 -exportOptionsPlist "$out/ExportOptions.plist" > "$out/export.log" 2>&1 ||
105 { grep -v IDEDistribution "$out/export.log" | tail -20 >&2; exit 1; }
106 ipa="$(print -l "$out"/export/*.ipa | head -1)"
107 [[ -f "$ipa" ]] || { echo "No IPA was exported." >&2; exit 1; }
108fi
109
110step "Upload to App Store Connect"
111API_PRIVATE_KEYS_DIR="$secrets" xcrun altool --upload-app -f "$ipa" -t ios \
112 --apiKey "$APPLE_API_KEY_ID" --apiIssuer "$APPLE_API_ISSUER" > "$out/upload.log" 2>&1 ||
113 { tail -20 "$out/upload.log" >&2; exit 1; }
114tail -3 "$out/upload.log"
115
116step "Wait for Apple to process the build"
117api wait-build "$app_id" "$version" "$build"
118
119echo "\nGraphley $version ($build) is processed. No group was assigned by this script."
120echo "Manually assign it only to the already-verified owner-only internal TestFlight group."