
name: Build Android APK

on:
  push:
    branches: ["main"]
  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest

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

    - name: Setup Node
      uses: actions/setup-node@v4
      with:
        node-version: '20'

    - name: Install dependencies
      run: npm ci

    # Se non hai un comando build, questo step viene ignorato
    - name: Build web (optional)
      if: ${{ false }}
      run: npm run build

    - name: Install Capacitor Android + Sync
      run: |
        npm install @capacitor/android
        npx cap sync android

    - name: Setup Java
      uses: actions/setup-java@v4
      with:
        distribution: "temurin"
        java-version: "17"

    - name: Build Android Debug APK
      run: |
        cd android
        ./gradlew assembleDebug

    - name: Upload APK
      uses: actions/upload-artifact@v4
      with:
        name: app-debug.apk
        path: android/app/build/outputs/apk/debug/app-debug.apk
