name: field-tech-android
# Usine de build Android (APK) — runner Linux auto-hébergé (act_runner). Zéro impact prod.
# Artefact téléchargeable depuis l'exécution Gitea Actions. Voir apps/field-tech/CI-SETUP.md.
on:
  push:
    paths:
      - 'apps/field-tech/**'
      - '.gitea/workflows/field-tech-android.yml'
  workflow_dispatch: {}

jobs:
  build-apk:
    runs-on: ubuntu-latest        # un act_runner Linux étiqueté ubuntu-latest (image catthehacker/ubuntu)
    defaults:
      run:
        working-directory: apps/field-tech
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-java@v4
        with: { distribution: temurin, java-version: '17' }
      - uses: actions/setup-node@v4
        with:
          node-version: '20'
          cache: npm
          cache-dependency-path: apps/field-tech/package-lock.json
      - uses: android-actions/setup-android@v3   # installe le SDK Android (platform-tools, platforms;android-34, build-tools)
      - name: Cache Gradle
        uses: actions/cache@v4
        with:
          path: |
            ~/.gradle/caches
            ~/.gradle/wrapper
          key: gradle-${{ runner.os }}-${{ hashFiles('apps/field-tech/android/**/*.gradle', 'apps/field-tech/android/gradle/wrapper/gradle-wrapper.properties') }}
          restore-keys: gradle-${{ runner.os }}-
      - name: Build web (Vite) + Capacitor sync
        run: |
          npm install --no-audit --no-fund
          npm run build
          [ -d android ] || npx cap add android
          npx cap sync android
      - name: Gradle assembleDebug
        working-directory: apps/field-tech/android
        run: ./gradlew assembleDebug --no-daemon --stacktrace
      # RELEASE (plus tard) : secrets TRANSISTORSOFT_LICENSE + keystore → assembleRelease + signature.
      - uses: actions/upload-artifact@v4
        with:
          name: targo-tech-android-debug
          path: apps/field-tech/android/app/build/outputs/apk/debug/*.apk
          if-no-files-found: error
