|
| 1 | +# ============================================================================= |
| 2 | +# CI Workflow - Continuous Integration for Pull Requests and Pushes |
| 3 | +# ============================================================================= |
| 4 | +# |
| 5 | +# Purpose: Validates code quality, runs tests, and builds example apps for |
| 6 | +# both Android and iOS platforms on every PR and push to development/master. |
| 7 | +# |
| 8 | +# What it does: |
| 9 | +# 1. Runs Dart/Flutter unit tests |
| 10 | +# 2. Builds Android example app (APK) |
| 11 | +# 3. Builds iOS example app (simulator + no-codesign IPA) |
| 12 | +# 4. Caches dependencies for faster subsequent runs |
| 13 | +# |
| 14 | +# Triggers: |
| 15 | +# - Pull requests to development or master branches |
| 16 | +# - Direct pushes to development or master branches |
| 17 | +# - Manual workflow dispatch for testing |
| 18 | +# |
| 19 | +# ============================================================================= |
| 20 | + |
| 21 | +name: CI - Build & Test |
| 22 | + |
| 23 | +on: |
| 24 | + # Trigger on pull requests targeting main branches |
| 25 | + pull_request: |
| 26 | + branches: |
| 27 | + - development |
| 28 | + - master |
| 29 | + paths-ignore: |
| 30 | + - '**.md' |
| 31 | + - 'doc/**' |
| 32 | + - 'assets/**' |
| 33 | + - '.github/workflows/close_inactive_issues.yml' |
| 34 | + - '.github/workflows/responseToSupportIssue*.yml' |
| 35 | + |
| 36 | + # Trigger on direct pushes to main branches |
| 37 | + push: |
| 38 | + branches: |
| 39 | + - development |
| 40 | + - master |
| 41 | + paths-ignore: |
| 42 | + - '**.md' |
| 43 | + - 'doc/**' |
| 44 | + - 'assets/**' |
| 45 | + |
| 46 | + # Allow manual triggering for testing |
| 47 | + workflow_dispatch: |
| 48 | + |
| 49 | + # Allow this workflow to be called by other workflows (reusable workflow) |
| 50 | + workflow_call: |
| 51 | + |
| 52 | +# Ensure only one CI run per PR/branch at a time |
| 53 | +concurrency: |
| 54 | + group: ci-${{ github.ref }} |
| 55 | + cancel-in-progress: true |
| 56 | + |
| 57 | +jobs: |
| 58 | + # =========================================================================== |
| 59 | + # Job 1: Run Unit Tests |
| 60 | + # =========================================================================== |
| 61 | + # Runs all Dart/Flutter unit tests for the plugin |
| 62 | + # Uses: Ubuntu runner (fastest and free for public repos) |
| 63 | + # =========================================================================== |
| 64 | + |
| 65 | + test: |
| 66 | + name: 🧪 Run Unit Tests |
| 67 | + runs-on: ubuntu-latest |
| 68 | + |
| 69 | + steps: |
| 70 | + # Step 1: Checkout the repository code |
| 71 | + - name: 📥 Checkout repository |
| 72 | + uses: actions/checkout@v4 |
| 73 | + |
| 74 | + # Step 2: Set up Flutter SDK |
| 75 | + # Uses subosito/flutter-action which caches Flutter SDK automatically |
| 76 | + - name: 🔧 Setup Flutter SDK |
| 77 | + uses: subosito/flutter-action@v2 |
| 78 | + with: |
| 79 | + channel: 'stable' # Use latest stable Flutter |
| 80 | + cache: true # Cache Flutter SDK for faster runs |
| 81 | + |
| 82 | + # Step 3: Verify Flutter installation |
| 83 | + - name: ℹ️ Display Flutter version |
| 84 | + run: | |
| 85 | + flutter --version |
| 86 | + dart --version |
| 87 | + |
| 88 | + # Step 4: Get plugin dependencies |
| 89 | + # This installs all packages defined in pubspec.yaml |
| 90 | + - name: 📦 Install plugin dependencies |
| 91 | + run: flutter pub get |
| 92 | + |
| 93 | + # Step 5: Analyze code for issues |
| 94 | + # Checks for code quality issues, unused imports, etc. |
| 95 | + # Only fails on actual errors, not info-level warnings |
| 96 | + - name: 🔍 Analyze code |
| 97 | + run: flutter analyze --no-fatal-infos --no-fatal-warnings |
| 98 | + |
| 99 | + # Step 6: Format check |
| 100 | + # Ensures code follows Dart formatting standards |
| 101 | + - name: 💅 Check code formatting |
| 102 | + run: dart format --set-exit-if-changed . |
| 103 | + |
| 104 | + # Step 7: Run unit tests |
| 105 | + # Executes all tests in the test/ directory |
| 106 | + - name: 🧪 Run unit tests |
| 107 | + run: flutter test --coverage |
| 108 | + |
| 109 | + # Step 8: Upload coverage report (optional) |
| 110 | + # Useful for tracking code coverage over time |
| 111 | + - name: 📊 Upload coverage to Codecov (optional) |
| 112 | + if: success() |
| 113 | + uses: codecov/codecov-action@v4 |
| 114 | + with: |
| 115 | + files: ./coverage/lcov.info |
| 116 | + fail_ci_if_error: false # Don't fail CI if coverage upload fails |
| 117 | + |
| 118 | + # =========================================================================== |
| 119 | + # Job 2: Build Android Example App |
| 120 | + # =========================================================================== |
| 121 | + # Builds the example app for Android to ensure plugin integration works |
| 122 | + # Uses: Ubuntu runner with Java 17 |
| 123 | + # =========================================================================== |
| 124 | + |
| 125 | + build-android: |
| 126 | + name: 🤖 Build Android Example |
| 127 | + runs-on: ubuntu-latest |
| 128 | + needs: test # Only run if tests pass |
| 129 | + |
| 130 | + steps: |
| 131 | + # Step 1: Checkout code |
| 132 | + - name: 📥 Checkout repository |
| 133 | + uses: actions/checkout@v4 |
| 134 | + |
| 135 | + # Step 2: Set up Java (required for Android builds) |
| 136 | + # Android builds require JDK 17 for modern Gradle versions |
| 137 | + - name: ☕ Setup Java |
| 138 | + uses: actions/setup-java@v4 |
| 139 | + with: |
| 140 | + distribution: 'temurin' # Eclipse Temurin (formerly AdoptOpenJDK) |
| 141 | + java-version: '17' |
| 142 | + cache: 'gradle' # Cache Gradle dependencies |
| 143 | + |
| 144 | + # Step 3: Set up Flutter SDK |
| 145 | + - name: 🔧 Setup Flutter SDK |
| 146 | + uses: subosito/flutter-action@v2 |
| 147 | + with: |
| 148 | + channel: 'stable' |
| 149 | + cache: true |
| 150 | + |
| 151 | + # Step 4: Display versions for debugging |
| 152 | + - name: ℹ️ Display versions |
| 153 | + run: | |
| 154 | + flutter --version |
| 155 | + java -version |
| 156 | + echo "JAVA_HOME: $JAVA_HOME" |
| 157 | + |
| 158 | + # Step 5: Get plugin dependencies |
| 159 | + - name: 📦 Install plugin dependencies |
| 160 | + run: flutter pub get |
| 161 | + |
| 162 | + # Step 6: Get example app dependencies |
| 163 | + - name: 📦 Install example app dependencies |
| 164 | + working-directory: example |
| 165 | + run: flutter pub get |
| 166 | + |
| 167 | + # Step 7: Build Android APK (debug mode) |
| 168 | + # This validates that the plugin integrates correctly with Android |
| 169 | + - name: 🔨 Build Android APK (debug) |
| 170 | + working-directory: example |
| 171 | + run: flutter build apk --debug |
| 172 | + |
| 173 | + # Step 8: Build Android App Bundle (release mode, no signing) |
| 174 | + # App Bundle is the preferred format for Play Store |
| 175 | + - name: 🔨 Build Android App Bundle (release) |
| 176 | + working-directory: example |
| 177 | + run: flutter build appbundle --release |
| 178 | + |
| 179 | + # Step 9: Upload build artifacts (optional) |
| 180 | + # Useful for manual testing or archiving |
| 181 | + - name: 📤 Upload APK artifact |
| 182 | + if: success() |
| 183 | + uses: actions/upload-artifact@v4 |
| 184 | + with: |
| 185 | + name: android-apk-debug |
| 186 | + path: example/build/app/outputs/flutter-apk/app-debug.apk |
| 187 | + retention-days: 7 # Keep for 7 days |
| 188 | + |
| 189 | + # =========================================================================== |
| 190 | + # Job 3: Build iOS Example App |
| 191 | + # =========================================================================== |
| 192 | + # Builds the example app for iOS to ensure plugin integration works |
| 193 | + # Uses: macOS runner (required for Xcode and iOS builds) |
| 194 | + # Note: macOS runners consume 10x minutes on private repos |
| 195 | + # =========================================================================== |
| 196 | + |
| 197 | + build-ios: |
| 198 | + name: 🍎 Build iOS Example |
| 199 | + runs-on: macos-14 # macOS 14 (Sonoma) with Xcode 15+ |
| 200 | + needs: test # Only run if tests pass |
| 201 | + |
| 202 | + steps: |
| 203 | + # Step 1: Checkout code |
| 204 | + - name: 📥 Checkout repository |
| 205 | + uses: actions/checkout@v4 |
| 206 | + |
| 207 | + # Step 2: Set up Flutter SDK |
| 208 | + - name: 🔧 Setup Flutter SDK |
| 209 | + uses: subosito/flutter-action@v2 |
| 210 | + with: |
| 211 | + channel: 'stable' |
| 212 | + cache: true |
| 213 | + |
| 214 | + # Step 3: Display versions |
| 215 | + - name: ℹ️ Display versions |
| 216 | + run: | |
| 217 | + flutter --version |
| 218 | + xcodebuild -version |
| 219 | + pod --version |
| 220 | + |
| 221 | + # Step 4: Get plugin dependencies |
| 222 | + - name: 📦 Install plugin dependencies |
| 223 | + run: flutter pub get |
| 224 | + |
| 225 | + # Step 5: Get example app dependencies |
| 226 | + - name: 📦 Install example app dependencies |
| 227 | + working-directory: example |
| 228 | + run: flutter pub get |
| 229 | + |
| 230 | + # Step 6: Update CocoaPods repo (ensures latest pod specs) |
| 231 | + # This can be slow, so we only update if needed |
| 232 | + - name: 🔄 Update CocoaPods repo |
| 233 | + working-directory: example/ios |
| 234 | + run: pod repo update |
| 235 | + |
| 236 | + # Step 7: Install CocoaPods dependencies |
| 237 | + # This installs native iOS dependencies including AppsFlyer SDK |
| 238 | + - name: 📦 Install CocoaPods dependencies |
| 239 | + working-directory: example/ios |
| 240 | + run: pod install |
| 241 | + |
| 242 | + # Step 8: Build for iOS Simulator (fastest iOS build) |
| 243 | + # Validates that the plugin compiles for iOS |
| 244 | + - name: 🔨 Build iOS for Simulator |
| 245 | + working-directory: example |
| 246 | + run: flutter build ios --simulator --debug |
| 247 | + |
| 248 | + # Step 9: Build iOS IPA without code signing (release mode) |
| 249 | + # This validates a full release build without requiring certificates |
| 250 | + - name: 🔨 Build iOS IPA (no codesign) |
| 251 | + working-directory: example |
| 252 | + run: flutter build ipa --release --no-codesign |
| 253 | + |
| 254 | + # Step 10: Upload build artifacts (optional) |
| 255 | + - name: 📤 Upload iOS build artifact |
| 256 | + if: success() |
| 257 | + uses: actions/upload-artifact@v4 |
| 258 | + with: |
| 259 | + name: ios-app-unsigned |
| 260 | + path: example/build/ios/archive/Runner.xcarchive |
| 261 | + retention-days: 7 |
| 262 | + |
| 263 | + # =========================================================================== |
| 264 | + # Job 4: Summary Report |
| 265 | + # =========================================================================== |
| 266 | + # Provides a summary of all CI jobs |
| 267 | + # =========================================================================== |
| 268 | + |
| 269 | + ci-summary: |
| 270 | + name: 📋 CI Summary |
| 271 | + runs-on: ubuntu-latest |
| 272 | + needs: [test, build-android, build-ios] |
| 273 | + if: always() # Run even if previous jobs fail |
| 274 | + |
| 275 | + steps: |
| 276 | + - name: 📊 Check CI Results |
| 277 | + run: | |
| 278 | + echo "===================================" |
| 279 | + echo "CI Pipeline Summary" |
| 280 | + echo "===================================" |
| 281 | + echo "Test Job: ${{ needs.test.result }}" |
| 282 | + echo "Android Build: ${{ needs.build-android.result }}" |
| 283 | + echo "iOS Build: ${{ needs.build-ios.result }}" |
| 284 | + echo "===================================" |
| 285 | + |
| 286 | + # Fail this job if any required job failed |
| 287 | + if [[ "${{ needs.test.result }}" != "success" ]] || \ |
| 288 | + [[ "${{ needs.build-android.result }}" != "success" ]] || \ |
| 289 | + [[ "${{ needs.build-ios.result }}" != "success" ]]; then |
| 290 | + echo "❌ CI Pipeline Failed" |
| 291 | + exit 1 |
| 292 | + fi |
| 293 | + |
| 294 | + echo "✅ CI Pipeline Passed Successfully" |
0 commit comments