krz/daybyday

iOS learning games for young children: days, months, seasons, numbers, letters, animals and more. education ios kids swift https://krz.sh/apps/daybyday/

scripts/release-ios.sh

062549ad26607ce9e973ed2a9a7ef6f853885f83
daybyday/scripts/release-ios.sh history · blame · raw

62 lines · 2546 bytes · executable

 1#!/bin/sh
 2# Archives DayByDay and uploads it to App Store Connect for TestFlight, signed automatically with
 3# the team's distribution certificate through the Apple ID signed in to Xcode. The version is the
 4# project's MARKETING_VERSION; the build number is the commit count.
 5# Usage: scripts/release-ios.sh
 6#   DAYBYDAY_PUBLISH  0 archives and exports the .ipa to .build/ios-release without uploading
 7set -eu
 8
 9cd "$(dirname "$0")/.."
10publish="${DAYBYDAY_PUBLISH:-1}"
11team=ZCNAX3VL9D
12project=DayByDay.xcodeproj
13
14if [ "$publish" != 0 ]; then
15    [ -z "$(git status --porcelain)" ] || { echo "The working tree has changes." >&2; exit 1; }
16    [ "$(git branch --show-current)" = main ] || { echo "Release from main." >&2; exit 1; }
17fi
18
19version="$(sed -n 's/.*MARKETING_VERSION = \(.*\);/\1/p' "$project/project.pbxproj" | sort -u)"
20[ "$(printf '%s\n' "$version" | wc -l | tr -d ' ')" = 1 ] || { echo "The targets' MARKETING_VERSION differ: $version" >&2; exit 1; }
21build="$(git rev-list --count HEAD)"
22
23out=.build/ios-release
24rm -rf "${out:?}"
25mkdir -p "$out"
26archive="$out/DayByDay.xcarchive"
27# xcodebuild rewrites the project file in its own key order; the copy puts it back as it was.
28cp "$project/project.pbxproj" "$out/project.pbxproj"
29trap 'cp "$out/project.pbxproj" "$project/project.pbxproj"' EXIT
30xcodebuild archive -project "$project" -scheme DayByDay -configuration Release \
31    -destination 'generic/platform=iOS' -archivePath "$archive" -allowProvisioningUpdates -quiet \
32    CURRENT_PROJECT_VERSION="$build"
33
34if [ "$publish" = 0 ]; then destination=export; else destination=upload; fi
35cat > "$out/ExportOptions.plist" <<PLIST
36<?xml version="1.0" encoding="UTF-8"?>
37<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
38<plist version="1.0">
39<dict>
40    <key>method</key>
41    <string>app-store-connect</string>
42    <key>destination</key>
43    <string>$destination</string>
44    <key>teamID</key>
45    <string>$team</string>
46    <key>signingStyle</key>
47    <string>automatic</string>
48    <key>manageAppVersionAndBuildNumber</key>
49    <false/>
50    <key>uploadSymbols</key>
51    <true/>
52</dict>
53</plist>
54PLIST
55xcodebuild -exportArchive -archivePath "$archive" -exportOptionsPlist "$out/ExportOptions.plist" \
56    -exportPath "$out/export" -allowProvisioningUpdates -quiet
57
58if [ "$publish" = 0 ]; then
59    echo "Exported $(ls "$out"/export/*.ipa): $version ($build), not uploaded"
60else
61    echo "Uploaded DayByDay $version ($build) to App Store Connect; it shows in TestFlight once processed"
62fi