Graphley / app · graphley.ai / scripts / release-ios.sh
| 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. |
| 4 | if [[ "${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 |
| 7 | fi |
| 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. |
| 15 | set -euo pipefail |
| 16 | |
| 17 | build="" |
| 18 | while (( $# )); 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 |
| 23 | done |
| 24 | |
| 25 | root="${0:A:h:h}" |
| 26 | team="22HV69L32T" |
| 27 | bundle_id="com.protomota.graphley" |
| 28 | app_id="6838869929" # Graphley: App & Site Analytics in App Store Connect |
| 29 | profile_name="Graphley App Store" |
| 30 | version="$(sed -n 's/^ MARKETING_VERSION: "\(.*\)"$/\1/p' "$root/project.yml" | head -1)" |
| 31 | |
| 32 | work="${GRAPHLEY_RELEASE_DIR:-/Volumes/Expand/Projects/Graphley/release}" |
| 33 | if [[ -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 |
| 35 | fi |
| 36 | secrets="$(mktemp -d)"; chmod 700 "$secrets" |
| 37 | trap 'rm -rf "$secrets"' EXIT |
| 38 | step() { 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. |
| 42 | bws_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 | } |
| 48 | if [[ -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" ) |
| 53 | else |
| 54 | ( umask 077; cp "$APPLE_API_KEY_PATH" "$secrets/AuthKey_$APPLE_API_KEY_ID.p8" ) |
| 55 | fi |
| 56 | export APPLE_API_KEY_ID APPLE_API_ISSUER |
| 57 | export APPLE_API_KEY_FILE="$secrets/AuthKey_$APPLE_API_KEY_ID.p8" |
| 58 | api() { /usr/bin/python3 "$root/scripts/asc.py" "$@"; } |
| 59 | |
| 60 | if [[ -z "$build" ]]; then |
| 61 | build=$(( $(api latest-build "$app_id" "$version") + 1 )) |
| 62 | fi |
| 63 | out="$work/ios-$version-$build" |
| 64 | mkdir -p "$out" |
| 65 | |
| 66 | # --- Signing: the App Store profile, installed from signing/ when it is missing. |
| 67 | profile_dir="$HOME/Library/Developer/Xcode/UserData/Provisioning Profiles" |
| 68 | if [[ -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" |
| 71 | fi |
| 72 | |
| 73 | if [[ -f "$out/export/Graphley.ipa" ]]; then |
| 74 | echo "Using the build already exported in $out." |
| 75 | ipa="$out/export/Graphley.ipa" |
| 76 | else |
| 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> |
| 102 | PLIST |
| 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; } |
| 108 | fi |
| 109 | |
| 110 | step "Upload to App Store Connect" |
| 111 | API_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; } |
| 114 | tail -3 "$out/upload.log" |
| 115 | |
| 116 | step "Wait for Apple to process the build" |
| 117 | api wait-build "$app_id" "$version" "$build" |
| 118 | |
| 119 | echo "\nGraphley $version ($build) is processed. No group was assigned by this script." |
| 120 | echo "Manually assign it only to the already-verified owner-only internal TestFlight group." |