-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathci_post_clone.sh
More file actions
executable file
·72 lines (65 loc) · 3.56 KB
/
Copy pathci_post_clone.sh
File metadata and controls
executable file
·72 lines (65 loc) · 3.56 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
#!/bin/sh
#
# Xcode Cloud post-clone hook for a Flutter app.
#
# THE PROBLEM: Xcode Cloud clones your repo and runs `xcodebuild` on
# Runner.xcworkspace — but it knows nothing about Flutter. The Flutter SDK,
# Generated.xcconfig, the Flutter/App frameworks, the plugin registrant, and the
# CocoaPods the Runner target depends on are all absent, so the build fails.
#
# THE FIX: this script installs Flutter and generates those artifacts before
# Xcode Cloud's build step runs. Xcode Cloud automatically executes any
# `ci_scripts/ci_post_clone.sh` located next to the Xcode project.
#
# Place this at: <flutter-project>/ios/ci_scripts/ci_post_clone.sh (chmod +x)
#
# Configure via Xcode Cloud Environment Variables:
# FLUTTER_VERSION required — pin it (see GOTCHA #2)
# FLUTTER_PROJECT_PATH path to the Flutter project within the repo
# (default ".", e.g. "mobile" for a monorepo)
# GOOGLE_SERVICE_INFO_PLIST_B64 optional — base64 of GoogleService-Info.plist
# to enable FCM push (see GOTCHA #6)
# plus any --dart-define values your app needs.
set -e
# --- 1. Install a PINNED Flutter -----------------------------------------------
# Pin to the exact version that generated your committed Package.resolved.
# Xcode Cloud disables automatic SwiftPM resolution, so the regenerated plugin
# package graph must match the lockfile byte-for-byte. A floating "stable" pulls
# newer plugin versions and breaks resolution ("dependencies were added: ...").
# Bump this in lockstep with Package.resolved. See docs/GOTCHAS.md #2.
FLUTTER_VERSION="${FLUTTER_VERSION:?set FLUTTER_VERSION in Xcode Cloud env (e.g. 3.44.1)}"
echo "=== Installing Flutter ($FLUTTER_VERSION) ==="
git clone https://github.com/flutter/flutter.git --depth 1 -b "$FLUTTER_VERSION" "$HOME/flutter"
export PATH="$HOME/flutter/bin:$PATH"
flutter --version
# --- 2. Generate the Flutter iOS artifacts -------------------------------------
echo "=== Preparing the Flutter iOS build ==="
cd "$CI_PRIMARY_REPOSITORY_PATH/${FLUTTER_PROJECT_PATH:-.}"
flutter precache --ios
flutter pub get
# `flutter build ios --no-codesign` generates ios/Flutter/Generated.xcconfig,
# the App.framework / Flutter.framework, the plugin registrant, and runs
# `pod install` — everything Xcode Cloud's subsequent xcodebuild needs.
# Pass your own --dart-define values here (example below).
flutter build ios --release --no-codesign \
${API_BASE_URL:+--dart-define=API_BASE_URL="$API_BASE_URL"}
# --- 3. (Optional) Wire FCM push from a secret ---------------------------------
# GoogleService-Info.plist is environment-specific and usually gitignored. Supply
# it to CI as the base64 Xcode Cloud secret GOOGLE_SERVICE_INFO_PLIST_B64; this
# materializes it, sets the production APNs entitlement (distribution build), and
# adds it to the Runner target. Without the secret, the app builds with push
# disabled. Runs AFTER `flutter build` so Flutter's regen can't clobber it.
# See docs/GOTCHAS.md #6.
if [ -n "$GOOGLE_SERVICE_INFO_PLIST_B64" ]; then
echo "=== Wiring FCM push (GoogleService-Info.plist provided) ==="
echo "$GOOGLE_SERVICE_INFO_PLIST_B64" | base64 --decode > ios/Runner/GoogleService-Info.plist
/usr/libexec/PlistBuddy -c "Set :aps-environment production" ios/Runner/Runner.entitlements
export GEM_HOME="$HOME/.gem"
export PATH="$GEM_HOME/bin:$PATH"
gem install xcodeproj --no-document
ruby ios/ci_scripts/wire_firebase.rb
else
echo "=== GOOGLE_SERVICE_INFO_PLIST_B64 not set — building with push disabled ==="
fi
echo "=== Flutter setup complete ==="
exit 0