|
| 1 | +name: Build Develop APK |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - develop |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: read |
| 11 | + |
| 12 | +jobs: |
| 13 | + build-develop-apk: |
| 14 | + runs-on: ubuntu-latest |
| 15 | + |
| 16 | + steps: |
| 17 | + - name: Checkout code |
| 18 | + uses: actions/checkout@v4 |
| 19 | + with: |
| 20 | + fetch-depth: 0 |
| 21 | + |
| 22 | + - name: Get commit info |
| 23 | + id: commit_info |
| 24 | + run: | |
| 25 | + COMMIT_SHA="${{ github.sha }}" |
| 26 | + SHORT_SHA="${COMMIT_SHA:0:7}" |
| 27 | +
|
| 28 | + echo "commit_sha=$COMMIT_SHA" >> $GITHUB_OUTPUT |
| 29 | + echo "short_sha=$SHORT_SHA" >> $GITHUB_OUTPUT |
| 30 | + echo "Building APK for develop branch at commit $SHORT_SHA" |
| 31 | +
|
| 32 | + - name: Setup Java |
| 33 | + uses: actions/setup-java@v5 |
| 34 | + with: |
| 35 | + distribution: 'zulu' |
| 36 | + java-version: '17' |
| 37 | + cache: 'gradle' |
| 38 | + |
| 39 | + - name: Setup Flutter |
| 40 | + uses: subosito/flutter-action@v2 |
| 41 | + with: |
| 42 | + channel: 'stable' |
| 43 | + cache: true |
| 44 | + cache-key: 'flutter-:os:-:channel:-:version:-:arch:-:hash:' |
| 45 | + cache-path: '${{ runner.tool_cache }}/flutter/:channel:-:version:-:arch:' |
| 46 | + |
| 47 | + - name: Cache Flutter dependencies |
| 48 | + uses: actions/cache@v4 |
| 49 | + with: |
| 50 | + path: | |
| 51 | + ~/.pub-cache |
| 52 | + app/example/.dart_tool |
| 53 | + packages/stadata_flutter_sdk/.dart_tool |
| 54 | + key: ${{ runner.os }}-pub-${{ hashFiles('**/pubspec.yaml') }}-${{ hashFiles('**/pubspec.lock') }} |
| 55 | + restore-keys: | |
| 56 | + ${{ runner.os }}-pub-${{ hashFiles('**/pubspec.yaml') }}- |
| 57 | + ${{ runner.os }}-pub- |
| 58 | +
|
| 59 | + - name: Cache build_runner outputs |
| 60 | + uses: actions/cache@v4 |
| 61 | + with: |
| 62 | + path: | |
| 63 | + app/example/lib/**/*.g.dart |
| 64 | + app/example/lib/**/*.gr.dart |
| 65 | + app/example/lib/**/*.config.dart |
| 66 | + app/example/.dart_tool/build |
| 67 | + key: ${{ runner.os }}-build-runner-${{ hashFiles('app/example/pubspec.yaml') }}-${{ hashFiles('app/example/lib/**/*.dart', '!app/example/lib/**/*.g.dart', '!app/example/lib/**/*.gr.dart', '!app/example/lib/**/*.config.dart') }}-${{ hashFiles('app/example/build.yaml') }} |
| 68 | + restore-keys: | |
| 69 | + ${{ runner.os }}-build-runner-${{ hashFiles('app/example/pubspec.yaml') }}- |
| 70 | + ${{ runner.os }}-build-runner- |
| 71 | +
|
| 72 | + - name: Get Flutter dependencies |
| 73 | + working-directory: app/example |
| 74 | + run: | |
| 75 | + echo "📦 Getting Flutter dependencies..." |
| 76 | + flutter pub get |
| 77 | + echo "✅ Dependencies ready" |
| 78 | +
|
| 79 | + - name: Setup .env file |
| 80 | + working-directory: app/example |
| 81 | + env: |
| 82 | + ENV_BASE64: ${{ secrets.ENV_BASE64 }} |
| 83 | + run: | |
| 84 | + if [ -n "$ENV_BASE64" ]; then |
| 85 | + echo "Decoding .env file from secret..." |
| 86 | + echo "$ENV_BASE64" | base64 -d > .env |
| 87 | + echo "✅ .env file created successfully" |
| 88 | + else |
| 89 | + echo "⚠️ Warning: ENV_BASE64 secret not found, creating empty .env" |
| 90 | + touch .env |
| 91 | + fi |
| 92 | +
|
| 93 | + - name: Run build_runner |
| 94 | + working-directory: app/example |
| 95 | + run: | |
| 96 | + echo "🔨 Running build_runner to generate code..." |
| 97 | + flutter pub run build_runner build --delete-conflicting-outputs |
| 98 | + echo "✅ Code generation completed" |
| 99 | +
|
| 100 | + - name: Build APK with Size Analysis |
| 101 | + working-directory: app/example |
| 102 | + run: | |
| 103 | + echo "Building APK for develop branch with size analysis..." |
| 104 | +
|
| 105 | + # Clean build directory |
| 106 | + flutter clean |
| 107 | +
|
| 108 | + # Build APK with size analysis |
| 109 | + flutter build apk --analyze-size --target-platform android-arm64 |
| 110 | +
|
| 111 | + # Check if APK was built |
| 112 | + APK_PATH="build/app/outputs/flutter-apk/app-release.apk" |
| 113 | +
|
| 114 | + if [ -f "$APK_PATH" ]; then |
| 115 | + # Rename APK |
| 116 | + NEW_APK_NAME="Stadata_Example_Develop_${{ steps.commit_info.outputs.short_sha }}.apk" |
| 117 | + mv "$APK_PATH" "build/app/outputs/flutter-apk/$NEW_APK_NAME" |
| 118 | + echo "apk_path=app/example/build/app/outputs/flutter-apk/$NEW_APK_NAME" >> $GITHUB_OUTPUT |
| 119 | + echo "apk_name=$NEW_APK_NAME" >> $GITHUB_OUTPUT |
| 120 | + echo "✅ APK built successfully: $NEW_APK_NAME" |
| 121 | +
|
| 122 | + # Get APK size |
| 123 | + APK_SIZE=$(du -h "build/app/outputs/flutter-apk/$NEW_APK_NAME" | cut -f1) |
| 124 | + echo "apk_size=$APK_SIZE" >> $GITHUB_OUTPUT |
| 125 | +
|
| 126 | + # Check for size analysis JSON |
| 127 | + echo "🔍 Searching for size analysis JSON..." |
| 128 | + chmod +x ../../scripts/ci/find_size_analysis_json.sh |
| 129 | + SIZE_JSON=$(../../scripts/ci/find_size_analysis_json.sh . || echo "") |
| 130 | +
|
| 131 | + if [ -n "$SIZE_JSON" ]; then |
| 132 | + echo "✅ Found size analysis JSON: $(basename $SIZE_JSON)" |
| 133 | + else |
| 134 | + echo "⚠️ Size analysis JSON not found" |
| 135 | + fi |
| 136 | +
|
| 137 | + if [ -n "$SIZE_JSON" ]; then |
| 138 | + # Copy to a known location with descriptive name |
| 139 | + mkdir -p build/size-analysis |
| 140 | + COMMIT_HASH="${{ steps.commit_info.outputs.short_sha }}" |
| 141 | + cp "$SIZE_JSON" "build/size-analysis/size_analysis_develop_${COMMIT_HASH}.json" |
| 142 | + echo "size_json=app/example/build/size-analysis/size_analysis_develop_${COMMIT_HASH}.json" >> $GITHUB_OUTPUT |
| 143 | + echo "✅ Size analysis saved as: size_analysis_develop_${COMMIT_HASH}.json" |
| 144 | + else |
| 145 | + echo "⚠️ Size analysis JSON not found" |
| 146 | + fi |
| 147 | + else |
| 148 | + echo "❌ APK build failed - file not found" |
| 149 | + exit 1 |
| 150 | + fi |
| 151 | + id: build_apk |
| 152 | + |
| 153 | + - name: Upload Develop APK |
| 154 | + uses: actions/upload-artifact@v4 |
| 155 | + with: |
| 156 | + name: develop-apk-latest |
| 157 | + path: ${{ steps.build_apk.outputs.apk_path }} |
| 158 | + retention-days: 30 |
| 159 | + overwrite: true |
| 160 | + |
| 161 | + - name: Upload Size Analysis JSON |
| 162 | + if: steps.build_apk.outputs.size_json != '' |
| 163 | + uses: actions/upload-artifact@v4 |
| 164 | + with: |
| 165 | + name: develop-size-analysis-latest |
| 166 | + path: ${{ steps.build_apk.outputs.size_json }} |
| 167 | + retention-days: 30 |
| 168 | + overwrite: true |
| 169 | + |
| 170 | + - name: Build summary |
| 171 | + if: always() |
| 172 | + run: | |
| 173 | + echo "## 📱 Develop APK Build Summary" >> $GITHUB_STEP_SUMMARY |
| 174 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 175 | + echo "### 📋 Build Information" >> $GITHUB_STEP_SUMMARY |
| 176 | + echo "- **Branch**: develop" >> $GITHUB_STEP_SUMMARY |
| 177 | + echo "- **Commit**: ${{ steps.commit_info.outputs.short_sha }}" >> $GITHUB_STEP_SUMMARY |
| 178 | + echo "- **APK Name**: ${{ steps.build_apk.outputs.apk_name }}" >> $GITHUB_STEP_SUMMARY |
| 179 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 180 | +
|
| 181 | + if [ "${{ job.status }}" = "success" ]; then |
| 182 | + echo "### ✅ Build Status" >> $GITHUB_STEP_SUMMARY |
| 183 | + echo "APK built successfully and cached for size comparison!" >> $GITHUB_STEP_SUMMARY |
| 184 | + echo "- **Size**: ${{ steps.build_apk.outputs.apk_size }}" >> $GITHUB_STEP_SUMMARY |
| 185 | + echo "- **Artifact**: develop-apk-latest" >> $GITHUB_STEP_SUMMARY |
| 186 | + echo "- **Retention**: 30 days" >> $GITHUB_STEP_SUMMARY |
| 187 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 188 | + echo "ℹ️ This APK will be used for size comparison in PR builds." >> $GITHUB_STEP_SUMMARY |
| 189 | + else |
| 190 | + echo "### ❌ Build Status" >> $GITHUB_STEP_SUMMARY |
| 191 | + echo "APK build failed!" >> $GITHUB_STEP_SUMMARY |
| 192 | + fi |
0 commit comments