-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathbuild-ios.sh
More file actions
executable file
·150 lines (121 loc) · 4.24 KB
/
build-ios.sh
File metadata and controls
executable file
·150 lines (121 loc) · 4.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/usr/bin/env bash
set -euo pipefail
# Builds both outputs with one command:
# 1) unsigned IPA for local/user signing workflows
# 2) signed App Store IPA for Transporter/App Store Connect upload
# Optional local overrides can be placed in build-ios.private.env.
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
APP_NAME="Moonfin"
ARCHIVE_DIR="$REPO_ROOT/build/ios/archive"
IPA_DIR="$REPO_ROOT/build/ios/ipa"
ROOT_IPA_OUTPUT=""
ROOT_UNSIGNED_IPA_OUTPUT=""
# Optional local overrides for private values.
PRIVATE_ENV_FILE="$REPO_ROOT/build-ios.private.env"
if [ -f "$PRIVATE_ENV_FILE" ]; then
# shellcheck disable=SC1090
source "$PRIVATE_ENV_FILE"
fi
resolve_flutter() {
if [ -n "${FLUTTER_BIN:-}" ] && [ -x "$FLUTTER_BIN" ]; then
printf '%s\n' "$FLUTTER_BIN"
return 0
fi
if command -v flutter >/dev/null 2>&1; then
command -v flutter
return 0
fi
local candidates=(
"$HOME/flutter/bin/flutter"
"$HOME/Documents/flutter/bin/flutter"
"$HOME/snap/flutter/common/flutter/bin/flutter"
)
local candidate
for candidate in "${candidates[@]}"; do
if [ -x "$candidate" ]; then
printf '%s\n' "$candidate"
return 0
fi
done
echo "Error: Flutter not found. Add flutter to PATH or set FLUTTER_BIN to the full flutter executable path." >&2
exit 1
}
FLUTTER="$(resolve_flutter)"
IOS_EXPORT_METHOD="${IOS_EXPORT_METHOD:-app-store}"
IOS_EXPORT_OPTIONS_PLIST="${IOS_EXPORT_OPTIONS_PLIST:-}"
if [ "$#" -gt 0 ]; then
echo "Error: this script no longer accepts positional arguments." >&2
echo "Run: ./build-ios.sh" >&2
exit 1
fi
if [ -n "$IOS_EXPORT_OPTIONS_PLIST" ] && [[ "$IOS_EXPORT_OPTIONS_PLIST" != /* ]]; then
IOS_EXPORT_OPTIONS_PLIST="$REPO_ROOT/$IOS_EXPORT_OPTIONS_PLIST"
fi
for cmd in xcodebuild zip; do
if ! command -v "$cmd" >/dev/null 2>&1; then
echo "Error: required command not found: $cmd" >&2
exit 1
fi
done
APP_VERSION=$(grep '^version:' "$REPO_ROOT/pubspec.yaml" | sed 's/version:[[:space:]]*//' | cut -d'+' -f1 | tr -d '[:space:]')
if [ -z "$APP_VERSION" ]; then
echo "Error: could not read version from pubspec.yaml" >&2
exit 1
fi
ROOT_IPA_OUTPUT="$REPO_ROOT/${APP_NAME}_iOS_v${APP_VERSION}.ipa"
ROOT_UNSIGNED_IPA_OUTPUT="$REPO_ROOT/${APP_NAME}_iOS_v${APP_VERSION}_unsigned.ipa"
echo "${APP_NAME} version: ${APP_VERSION}"
cd "$REPO_ROOT"
echo "Cleaning previous Flutter outputs..."
"$FLUTTER" clean
echo "Resolving packages..."
"$FLUTTER" pub get
rm -f "$ROOT_IPA_OUTPUT"
rm -f "$ROOT_UNSIGNED_IPA_OUTPUT"
rm -f "$IPA_DIR"/*.ipa 2>/dev/null || true
echo "Building unsigned iOS archive..."
"$FLUTTER" build ipa --release --no-codesign
if [ ! -d "$ARCHIVE_DIR" ]; then
echo "Error: expected archive directory not found: $ARCHIVE_DIR" >&2
exit 1
fi
APP_IN_ARCHIVE="$(find "$ARCHIVE_DIR" -type d -path '*/Products/Applications/*.app' | head -n 1)"
if [ -z "$APP_IN_ARCHIVE" ]; then
echo "Error: .app not found in archive at $ARCHIVE_DIR" >&2
exit 1
fi
mkdir -p "$IPA_DIR"
UNSIGNED_IPA_SOURCE="$IPA_DIR/${APP_NAME}-unsigned.ipa"
rm -f "$UNSIGNED_IPA_SOURCE"
TMP_DIR="$(mktemp -d)"
trap 'rm -rf "$TMP_DIR"' EXIT
mkdir -p "$TMP_DIR/Payload"
cp -R "$APP_IN_ARCHIVE" "$TMP_DIR/Payload/"
(
cd "$TMP_DIR"
zip -qry "$UNSIGNED_IPA_SOURCE" Payload
)
cp "$UNSIGNED_IPA_SOURCE" "$ROOT_UNSIGNED_IPA_OUTPUT"
echo "Unsigned iOS archive created in: $ARCHIVE_DIR"
echo "Unsigned IPA created: $UNSIGNED_IPA_SOURCE"
echo "Unsigned IPA copied to root: $ROOT_UNSIGNED_IPA_OUTPUT"
if [ -n "$IOS_EXPORT_OPTIONS_PLIST" ]; then
if [ ! -f "$IOS_EXPORT_OPTIONS_PLIST" ]; then
echo "Error: export options plist not found: $IOS_EXPORT_OPTIONS_PLIST" >&2
exit 1
fi
echo "Building signed App Store IPA with export options plist..."
"$FLUTTER" build ipa --release --export-options-plist="$IOS_EXPORT_OPTIONS_PLIST"
else
echo "Building signed App Store IPA with export method: $IOS_EXPORT_METHOD"
"$FLUTTER" build ipa --release --export-method="$IOS_EXPORT_METHOD"
fi
IPA_SOURCE="$(find "$IPA_DIR" -maxdepth 1 -type f -name '*.ipa' ! -name '*-unsigned.ipa' | head -n 1)"
if [ -z "$IPA_SOURCE" ]; then
echo "Error: IPA not found in $IPA_DIR" >&2
exit 1
fi
cp "$IPA_SOURCE" "$ROOT_IPA_OUTPUT"
echo "IPA created: $IPA_SOURCE"
echo "IPA copied to root: $ROOT_IPA_OUTPUT"
echo "Export method: $IOS_EXPORT_METHOD"