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