name: Android CI

on:
  workflow_dispatch:
  push:
    branches: [main, master]
    paths:
      - "app/**"
      - "shared/**"
      - "server/**"
      - "build.gradle.kts"
      - "settings.gradle.kts"
      - "gradle/**"
      - ".github/workflows/android-ci.yml"
  pull_request:
    paths:
      - "app/**"
      - "shared/**"
      - "server/**"
      - "build.gradle.kts"
      - "settings.gradle.kts"
      - "gradle/**"
      - ".github/workflows/android-ci.yml"

jobs:
  build:
    name: Build & Test
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Set up JDK 17
        uses: actions/setup-java@v4
        with:
          distribution: temurin
          java-version: 17

      - name: Setup Gradle
        uses: gradle/actions/setup-gradle@v4

      - name: Build debug APK
        run: ./gradlew assembleDebug

      - name: Run unit tests (app + shared + server)
        run: ./gradlew test

      - name: Upload debug APK
        uses: actions/upload-artifact@v4
        if: success()
        with:
          name: debug-apk
          path: app/build/outputs/apk/debug/*.apk
          retention-days: 14
