Build apk action #14
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: 'Build APK with your Environment' | |
| on: | |
| pull_request: | |
| workflow_dispatch: | |
| inputs: | |
| base_url: | |
| description: 'Base URL for the service' | |
| required: true | |
| default: 'https://unified-dev.digit.org/' | |
| type: string | |
| mdms_api_path: | |
| description: 'MDMS API Path' | |
| required: true | |
| default: 'egov-mdms-service/v1/_search' | |
| type: string | |
| tenant_id: | |
| description: 'Tenant ID' | |
| required: true | |
| default: 'dev' | |
| type: string | |
| actions_api_path: | |
| description: 'Actions API Path' | |
| required: true | |
| default: 'access/v1/actions/mdms/_get' | |
| type: string | |
| hierarchy_type: | |
| description: 'Hierarchy Type' | |
| required: true | |
| default: 'ADMIN' | |
| type: string | |
| env_name: | |
| description: 'Environment Name' | |
| required: true | |
| default: 'DEV' | |
| type: choice | |
| options: | |
| - DEV | |
| - QA | |
| - UAT | |
| - DEMO | |
| - PROD | |
| check_bandwidth_api: | |
| description: 'Check Bandwidth API Path' | |
| required: false | |
| default: '/health-project/check/bandwidth' | |
| type: string | |
| build_type: | |
| description: 'Build Type' | |
| required: true | |
| default: 'release' | |
| type: choice | |
| options: | |
| - release | |
| - profile | |
| artifact_name: | |
| description: 'Custom APK artifact name (optional)' | |
| required: false | |
| default: 'health-campaign-app' | |
| type: string | |
| jobs: | |
| build: | |
| name: Build APK | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 30 | |
| steps: | |
| - name: Checkout Repository | |
| uses: actions/checkout@v4 | |
| with: | |
| submodules: true # ensure packages like ../../packages/complaints are pulled | |
| - name: Setup Java | |
| uses: actions/setup-java@v4 | |
| with: | |
| distribution: 'zulu' | |
| java-version: '17' | |
| - name: Setup Flutter | |
| uses: subosito/flutter-action@v2 | |
| with: | |
| flutter-version: '3.22.2' | |
| channel: 'stable' | |
| cache: true | |
| - name: Install Global Dependencies | |
| run: | | |
| dart pub global activate mason_cli | |
| dart pub global activate melos | |
| - name: Create Environment Configuration | |
| run: | | |
| cat > apps/health_campaign_field_worker_app/.env << EOF | |
| BASE_URL="${{ inputs.base_url }}" | |
| MDMS_API_PATH="${{ inputs.mdms_api_path }}" | |
| TENANT_ID="${{ inputs.tenant_id }}" | |
| ACTIONS_API_PATH="${{ inputs.actions_api_path }}" | |
| HIERARCHY_TYPE="${{ inputs.hierarchy_type }}" | |
| ENV_NAME="${{ inputs.env_name }}" | |
| SYNC_DOWN_RETRY_COUNT=3 | |
| RETRY_TIME_INTERVAL=5 | |
| CONNECT_TIMEOUT=120000 | |
| RECEIVE_TIMEOUT=120000 | |
| SEND_TIMEOUT=120000 | |
| CHECK_BANDWIDTH_API="${{ inputs.check_bandwidth_api }}" | |
| EOF | |
| - name: Display Configuration | |
| run: | | |
| echo "Building APK with the following configuration:" | |
| echo "Environment: ${{ inputs.env_name }}" | |
| echo "Base URL: ${{ inputs.base_url }}" | |
| echo "Tenant ID: ${{ inputs.tenant_id }}" | |
| echo "Build Type: ${{ inputs.build_type }}" | |
| - name: Install Project Dependencies (respect lock file) | |
| run: | | |
| cd apps/health_campaign_field_worker_app | |
| # Backup committed lock file | |
| if [ -f "pubspec.lock" ]; then | |
| cp pubspec.lock pubspec.lock.backup | |
| echo "Backed up committed pubspec.lock" | |
| fi | |
| # Install strictly according to lock file | |
| if [ -f "pubspec.lock.backup" ]; then | |
| flutter pub get --offline --enforce-lockfile || { | |
| echo "❌ Failed to resolve with committed lockfile" | |
| exit 1 | |
| } | |
| echo "Dependencies installed using committed lockfile" | |
| else | |
| flutter pub get | |
| echo "No lock file found, generated a new one" | |
| fi | |
| - name: Generate Code | |
| run: | | |
| cd apps/health_campaign_field_worker_app | |
| if [ ! -d ".dart_tool/build" ] || [ ! -f "lib/models/data_model.dart" ]; then | |
| dart run build_runner build --delete-conflicting-outputs | |
| else | |
| echo "Generated files appear up to date, skipping build_runner" | |
| fi | |
| - name: Build APK | |
| run: | | |
| cd apps/health_campaign_field_worker_app | |
| if [ "${{ inputs.build_type }}" == "release" ]; then | |
| flutter build apk --release | |
| elif [ "${{ inputs.build_type }}" == "profile" ]; then | |
| flutter build apk -t lib/main_driver.dart --profile | |
| fi | |
| - name: Rename APK | |
| run: | | |
| cd apps/health_campaign_field_worker_app/build/app/outputs/flutter-apk | |
| APK_NAME="${{ inputs.artifact_name }}-${{ inputs.env_name }}-${{ inputs.build_type }}.apk" | |
| if [ "${{ inputs.build_type }}" == "release" ]; then | |
| mv app-release.apk "$APK_NAME" | |
| elif [ "${{ inputs.build_type }}" == "profile" ]; then | |
| mv app-profile.apk "$APK_NAME" | |
| fi | |
| echo "APK_NAME=$APK_NAME" >> $GITHUB_ENV | |
| - name: Upload APK Artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ env.APK_NAME }} | |
| path: apps/health_campaign_field_worker_app/build/app/outputs/flutter-apk/${{ env.APK_NAME }} | |
| retention-days: 30 | |
| - name: Create Release Summary | |
| run: | | |
| echo "## 📱 APK Build Summary" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "| Parameter | Value |" >> $GITHUB_STEP_SUMMARY | |
| echo "|-----------|--------|" >> $GITHUB_STEP_SUMMARY | |
| echo "| Environment | ${{ inputs.env_name }} |" >> $GITHUB_STEP_SUMMARY | |
| echo "| Base URL | ${{ inputs.base_url }} |" >> $GITHUB_STEP_SUMMARY | |
| echo "| Tenant ID | ${{ inputs.tenant_id }} |" >> $GITHUB_STEP_SUMMARY | |
| echo "| Build Type | ${{ inputs.build_type }} |" >> $GITHUB_STEP_SUMMARY | |
| echo "| APK Name | ${{ env.APK_NAME }} |" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "✅ APK has been successfully built and uploaded as an artifact." >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "📥 You can download the APK from the **Artifacts** section of this workflow run." >> $GITHUB_STEP_SUMMARY |