Skip to content

Commit 622beea

Browse files
committed
fix(cross): add & fix ios builder
1 parent 9dba2a4 commit 622beea

2 files changed

Lines changed: 120 additions & 26 deletions

File tree

cross-platform/build.sh

Lines changed: 100 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,101 @@ else
2222
exit 1
2323
fi
2424

25+
echo "🖥️ Detected OS: $OS_TYPE"
26+
27+
# --- Trigger iOS builder FIRST on Ubuntu ---
28+
if [ "$OS_TYPE" = "ubuntu" ]; then
29+
echo "🚀 Triggering iOS Flutter Builder workflow first..."
30+
31+
# Install jq if needed (for JSON parsing)
32+
if ! command -v jq &> /dev/null; then
33+
echo "Installing jq..."
34+
sudo apt-get install jq -y > /dev/null 2>&1
35+
fi
36+
37+
# Install GitHub CLI if needed
38+
if ! command -v gh &> /dev/null; then
39+
echo "Installing GitHub CLI..."
40+
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
41+
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
42+
sudo apt-get update > /dev/null 2>&1
43+
sudo apt-get install gh -y > /dev/null 2>&1
44+
fi
45+
46+
# Authenticate GitHub CLI
47+
export GH_TOKEN="${GITHUB_PAT}"
48+
49+
# Trigger iOS builder workflow
50+
echo "📱 Triggering iOS build via flutter-ios-builder..."
51+
gh api \
52+
--method POST \
53+
-H "Accept: application/vnd.github+json" \
54+
-H "X-GitHub-Api-Version: 2022-11-28" \
55+
/repos/${OWNER_NAME}/flutter-ios-builder/dispatches \
56+
-f event_type='trigger-macos-build' \
57+
-f client_payload[owner_name]="${OWNER_NAME}" \
58+
-f client_payload[repo_name]="${REPO_NAME}" \
59+
-f client_payload[branch]="${BRANCH}" \
60+
-f client_payload[custom_tag]="${ENV_TAG}" \
61+
-f client_payload[devops_owner]="${OWNER_NAME}" \
62+
-f client_payload[devops_repo]="helm" \
63+
-f client_payload[devops_branch]="${DEVOPS_BRANCH:-main}"
64+
65+
if [ $? -ne 0 ]; then
66+
echo "❌ Failed to trigger iOS builder workflow"
67+
exit 1
68+
fi
69+
70+
echo "✅ iOS builder workflow triggered successfully"
71+
72+
# Wait for workflow to complete
73+
echo "⏳ Waiting for iOS build to complete..."
74+
sleep 10
75+
76+
MAX_WAIT=1800 # 30 minutes
77+
ELAPSED=0
78+
POLL_INTERVAL=30
79+
80+
while [ $ELAPSED -lt $MAX_WAIT ]; do
81+
WORKFLOW_STATUS=$(gh run list \
82+
--repo "${OWNER_NAME}/flutter-ios-builder" \
83+
--workflow "iOS Builder (macOS)" \
84+
--branch "main" \
85+
--limit 1 \
86+
--json status,conclusion \
87+
--jq '.[0]')
88+
89+
if [ -z "$WORKFLOW_STATUS" ]; then
90+
echo "⏳ Workflow not started yet, waiting..."
91+
else
92+
STATUS=$(echo "$WORKFLOW_STATUS" | jq -r '.status')
93+
CONCLUSION=$(echo "$WORKFLOW_STATUS" | jq -r '.conclusion')
94+
95+
if [ "$STATUS" = "completed" ]; then
96+
if [ "$CONCLUSION" = "success" ]; then
97+
echo "✅ iOS build completed successfully!"
98+
break
99+
else
100+
echo "❌ iOS build failed with conclusion: $CONCLUSION"
101+
exit 1
102+
fi
103+
else
104+
echo "⏳ iOS build in progress (status: $STATUS)..."
105+
fi
106+
fi
107+
108+
sleep $POLL_INTERVAL
109+
ELAPSED=$((ELAPSED + POLL_INTERVAL))
110+
done
111+
112+
if [ $ELAPSED -ge $MAX_WAIT ]; then
113+
echo "⚠️ iOS build timed out after ${MAX_WAIT} seconds"
114+
exit 1
115+
fi
116+
117+
echo "🎯 iOS build complete. Continuing with Android build..."
118+
fi
119+
25120
# --- Ensure Node.js & npm ---
26121
if ! command -v npm &> /dev/null; then
27122
if [ "$OS_TYPE" = "ubuntu" ]; then
@@ -64,31 +159,14 @@ flutter pub run build_runner build --delete-conflicting-outputs
64159

65160
# --- Platform-specific builds ---
66161
if [ "$OS_TYPE" = "ubuntu" ]; then
67-
echo "Building APK for Android..."
162+
echo "🤖 Building APK for Android..."
68163
flutter build apk --release
164+
echo "✅ Android APK build complete!"
69165
elif [ "$OS_TYPE" = "macos" ]; then
70-
echo "Building IPA for iOS..."
166+
echo "🍎 Building IPA for iOS..."
71167
flutter build ipa --release --no-codesign
168+
echo "✅ iOS IPA build complete!"
72169
fi
73170

74-
# --- Trigger macOS builder on Ubuntu (Ubuntu can't build IPA) ---
75-
if [ "$OS_TYPE" = "ubuntu" ]; then
76-
echo "Ubuntu detected. Triggering flutter-ios-builder workflow for iOS build..."
77-
curl -X POST \
78-
-H "Accept: application/vnd.github.v3+json" \
79-
-H "Authorization: token ${GITHUB_PAT}" \
80-
https://api.github.com/repos/karimzakzouk/flutter-ios-builder/dispatches \
81-
-d "{
82-
\"event_type\": \"trigger-macos-build\",
83-
\"client_payload\": {
84-
\"owner_name\": \"${OWNER_NAME}\",
85-
\"repo_name\": \"${REPO_NAME}\",
86-
\"branch\": \"${BRANCH}\",
87-
\"commit_tag\": \"${COMMIT_TAG}\",
88-
\"env_tag\": \"${ENV_TAG}\",
89-
\"moving_tag\": \"${MOVING_TAG}\"
90-
}
91-
}"
92-
echo "iOS build workflow triggered."
93-
fi
171+
echo "🎉 All builds completed successfully!"
94172

cross-platform/deploy.sh

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,40 @@ fi
3737

3838
# Detect OS and upload appropriate build
3939
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
40-
# Ubuntu - Upload APK
40+
# Ubuntu - Upload APK with commit tag
4141
APK_PATH="build/app/outputs/flutter-apk/app-release.apk"
42+
APK_RENAMED="app-release-${COMMIT_TAG}.apk"
43+
4244
if [ -f "$APK_PATH" ]; then
43-
gh release upload "${RELEASE_TAG}" "$APK_PATH" \
45+
echo "📦 Renaming APK to: ${APK_RENAMED}"
46+
cp "$APK_PATH" "$APK_RENAMED"
47+
48+
gh release upload "${RELEASE_TAG}" "$APK_RENAMED" \
4449
--repo "${OWNER_NAME}/${REPO_NAME}" \
4550
--clobber
51+
52+
echo "✅ Uploaded: ${APK_RENAMED}"
4653
else
54+
echo "❌ APK not found at: ${APK_PATH}"
4755
exit 1
4856
fi
4957

5058
elif [[ "$OSTYPE" == "darwin"* ]]; then
51-
# macOS - Upload IPA
59+
# macOS - Upload IPA with commit tag
5260
IPA_PATH="build/ios/ipa/lam7a.ipa"
61+
IPA_RENAMED="lam7a-${COMMIT_TAG}.ipa"
62+
5363
if [ -f "$IPA_PATH" ]; then
54-
gh release upload "${RELEASE_TAG}" "$IPA_PATH" \
64+
echo "📦 Renaming IPA to: ${IPA_RENAMED}"
65+
cp "$IPA_PATH" "$IPA_RENAMED"
66+
67+
gh release upload "${RELEASE_TAG}" "$IPA_RENAMED" \
5568
--repo "${OWNER_NAME}/${REPO_NAME}" \
5669
--clobber
70+
71+
echo "✅ Uploaded: ${IPA_RENAMED}"
5772
else
73+
echo "❌ IPA not found at: ${IPA_PATH}"
5874
exit 1
5975
fi
6076
fi

0 commit comments

Comments
 (0)