name: MotorSignal Android CI on: push: branches: [ master ] pull_request: branches: [ master ] workflow_dispatch: permissions: contents: read concurrency: group: android-build-${{ github.ref }} cancel-in-progress: true env: FLUTTER_VERSION: '3.44.6' JAVA_VERSION: '17' ANDROID_COMPILE_SDK: '37.0' ANDROID_BUILD_TOOLS: '37.0.0' GRADLE_VERSION: '9.1.0' jobs: analyze-and-build: name: Analyze, test and debug build runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v6 with: fetch-depth: 1 - name: Set up Java uses: actions/setup-java@v5 with: distribution: temurin java-version: ${{ env.JAVA_VERSION }} - name: Set up Flutter uses: subosito/flutter-action@v2 with: flutter-version: ${{ env.FLUTTER_VERSION }} channel: stable cache: true - name: Free runner disk space shell: bash run: | set -euo pipefail sudo rm -rf /usr/share/dotnet /usr/local/share/powershell /opt/ghc /usr/local/.ghcup /usr/local/lib/android/sdk/emulator /usr/local/lib/android/sdk/system-images sudo apt-get clean || true sudo rm -rf /var/lib/apt/lists/* docker system prune -af --volumes 2>/dev/null || true df -h / AVAILABLE_KB="$(df --output=avail / | tail -n 1 | tr -d ' ')" test "$AVAILABLE_KB" -ge "$((5 * 1024 * 1024))" - name: Create Flutter local.properties shell: bash run: | set -euo pipefail test -n "${FLUTTER_ROOT:-}" && test -d "$FLUTTER_ROOT" printf 'flutter.sdk=%s\n' "$FLUTTER_ROOT" > android/local.properties - name: Provision Android SDK shell: bash run: | set -euo pipefail SDKROOT="${ANDROID_SDK_ROOT:-${ANDROID_HOME:-}}" SDKMANAGER="$(find "$SDKROOT/cmdline-tools" -type f -name sdkmanager -print -quit 2>/dev/null || true)" test -x "$SDKMANAGER" "$SDKMANAGER" --licenses /dev/null 2>&1 || true "$SDKMANAGER" "platform-tools" "platforms;android-${ANDROID_COMPILE_SDK}" "build-tools;${ANDROID_BUILD_TOOLS}" yes | "$SDKMANAGER" --licenses >/dev/null 2>&1 || true echo "ANDROID_SDK_ROOT=$SDKROOT" >> "$GITHUB_ENV" - name: Provision Gradle wrapper shell: bash run: | set -euo pipefail if [ ! -f android/gradlew ]; then (cd android && gradle wrapper --gradle-version "$GRADLE_VERSION" --distribution-type all); fi chmod +x android/gradlew - name: Flutter and Android environment run: | flutter --version flutter doctor -v java -version - name: Get dependencies run: flutter pub get - name: Generate Drift sources run: dart run build_runner build --delete-conflicting-outputs - name: Analyze run: flutter analyze --no-fatal-infos - name: Run tests run: flutter test - name: Build debug APK shell: bash run: flutter build apk --debug - name: Verify debug APK shell: bash run: | set -euo pipefail APK="build/app/outputs/flutter-apk/app-debug.apk" test -s "$APK" file "$APK" sha256sum "$APK" | tee build/app/outputs/flutter-apk/app-debug.apk.sha256 - name: Upload debug APK uses: actions/upload-artifact@v5 with: name: motorsignal-debug-apk path: | build/app/outputs/flutter-apk/app-debug.apk build/app/outputs/flutter-apk/app-debug.apk.sha256 if-no-files-found: error retention-days: 14 release: name: Build signed release APK and AAB runs-on: ubuntu-latest needs: analyze-and-build if: github.event_name == 'workflow_dispatch' || github.event_name == 'push' steps: - name: Checkout uses: actions/checkout@v6 with: fetch-depth: 1 - name: Set up Java uses: actions/setup-java@v5 with: distribution: temurin java-version: ${{ env.JAVA_VERSION }} - name: Set up Flutter uses: subosito/flutter-action@v2 with: flutter-version: ${{ env.FLUTTER_VERSION }} channel: stable cache: true - name: Get dependencies run: flutter pub get - name: Generate Drift sources run: dart run build_runner build --delete-conflicting-outputs - name: Build release artifacts run: flutter build apk --release