22set -e
33
44# =========================================
5- # Cross-platform Flutter build script (macOS friendly)
5+ # Cross-platform Flutter build script
66# =========================================
7+ # Supports: Ubuntu, macOS
78# Environment variables passed from workflow:
89# - COMMIT_TAG: Short commit SHA (e.g., abc123)
910# - ENV_TAG: Environment tag (prod/dev)
@@ -13,18 +14,32 @@ set -e
1314echo " 🏗️ Starting build process..."
1415cd ../../app
1516
16- # --- Ensure Homebrew is available ---
17- if ! command -v brew & > /dev/null; then
18- echo " 🍺 Homebrew not found. Installing..."
19- /bin/bash -c " $( curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh) "
20- echo ' eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~ /.zprofile
21- eval " $( /opt/homebrew/bin/brew shellenv) "
17+ # --- Detect OS ---
18+ if [[ " $OSTYPE " == " linux-gnu" * ]]; then
19+ OS_TYPE=" ubuntu"
20+ echo " 🐧 Detected Ubuntu/Linux"
21+ elif [[ " $OSTYPE " == " darwin" * ]]; then
22+ OS_TYPE=" macos"
23+ echo " 🍎 Detected macOS"
24+ else
25+ echo " ❌ Unsupported OS: $OSTYPE "
26+ exit 1
2227fi
2328
2429# --- Ensure Node.js & npm ---
2530if ! command -v npm & > /dev/null; then
2631 echo " 📦 Installing Node.js..."
27- brew install node
32+ if [ " $OS_TYPE " = " ubuntu" ]; then
33+ sudo apt-get update
34+ sudo apt-get install -y nodejs npm
35+ elif [ " $OS_TYPE " = " macos" ]; then
36+ if ! command -v brew & > /dev/null; then
37+ echo " 🍺 Installing Homebrew..."
38+ /bin/bash -c " $( curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh) "
39+ eval " $( /opt/homebrew/bin/brew shellenv) "
40+ fi
41+ brew install node
42+ fi
2843else
2944 echo " 📦 Node.js already installed."
3045fi
4156
4257export PATH=" $PATH :$FLUTTER_DIR /bin"
4358
44- # --- Generate Lam7aApi package ---
59+ # --- Download Swagger JSON from backend ---
60+ echo " 🔧 Downloading Swagger specification from backend..."
61+ SWAGGER_URL=" http://backend-code.duckdns.org/dev/swagger.json"
62+ if ! curl -f -s -o swagger.json " $SWAGGER_URL " ; then
63+ echo " ⚠️ Failed to download swagger.json from $SWAGGER_URL "
64+ echo " 📥 Attempting fallback: letting update_api.dart download it..."
65+ else
66+ echo " ✅ Downloaded swagger.json successfully"
67+ fi
68+
69+ # --- Generate Lam7aApi package via Swagger ---
4570echo " 🔧 Generating OpenAPI client (Lam7aApi)..."
4671if [ -f ./tools/update_api.dart ]; then
47- dart run ./tools/update_api.dart
72+ # Check if local swagger.json exists
73+ if [ -f ./swagger.json ]; then
74+ echo " 📄 Using swagger.json..."
75+ dart run ./tools/update_api.dart ./swagger.json
76+ else
77+ echo " 📥 No swagger.json found, letting update_api.dart download it..."
78+ dart run ./tools/update_api.dart
79+ fi
80+
81+ if [ $? -ne 0 ]; then
82+ echo " ❌ API generation failed"
83+ exit 1
84+ fi
4885else
49- echo " ⚠️ update_api.dart not found, creating minimal Lam7aApi package..."
50- mkdir -p ../Lam7aApi
51- cat > ../Lam7aApi/pubspec.yaml << 'EOF '
52- name: openapi
53- description: Generated OpenAPI client
54- publish_to: 'none'
55- version: 1.0.0
56-
57- environment:
58- sdk: ^3.9.2
59-
60- dependencies:
61- flutter:
62- sdk: flutter
63- dio: ^5.9.0
64- json_annotation: ^4.9.0
65-
66- dev_dependencies:
67- flutter_test:
68- sdk: flutter
69- json_serializable: ^6.11.1
70- build_runner: ^2.7.1
71- EOF
72- mkdir -p ../Lam7aApi/lib
73- echo " // Generated API client" > ../Lam7aApi/lib/openapi.dart
86+ echo " ❌ update_api.dart not found"
87+ exit 1
7488fi
7589
7690# --- Flutter build steps ---
@@ -84,15 +98,16 @@ flutter pub run build_runner build --delete-conflicting-outputs
8498echo " 📱 Building Android APK..."
8599flutter build apk --release --verbose
86100
87- # --- macOS -specific: build iOS if available ---
88- if [[ " $OSTYPE " == " darwin " * ] ]; then
101+ # --- Platform -specific builds ---
102+ if [ " $OS_TYPE " = " macos " ]; then
89103 echo " 🍎 Building iOS app..."
90-
91- # Build the iOS app (no code signing, suitable for CI)
92104 flutter build ipa --release --no-codesign
93-
94- # The .ipa file will be located under:
95- # build/ios/ipa/
96105 echo " ✅ iOS IPA built successfully!"
97106 echo " 📦 Path: build/ios/ipa/app-release.ipa"
107+ elif [ " $OS_TYPE " = " ubuntu" ]; then
108+ echo " 🐧 Ubuntu build complete (Android APK built)."
109+ echo " 📦 Path: build/app/outputs/flutter-apk/app-release.apk"
98110fi
111+
112+ echo " "
113+ echo " ✅ Build process completed successfully!"
0 commit comments