name: Mobile

on:
  push:
  workflow_dispatch:

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  build_android:
    name: Build Android APK
    runs-on: ubuntu-latest
    steps:
      - name: Checkout the repository
        uses: actions/checkout@v6

      - uses: pnpm/action-setup@v6

      - name: Set up Node.js
        uses: actions/setup-node@v6
        with:
          node-version: 24
          cache: "pnpm"

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

      - name: Set up Gradle
        uses: gradle/actions/setup-gradle@v5

      - name: Install dependencies
        run: pnpm install --frozen-lockfile

      - name: Update build info
        run: pnpm run chore:update-build-info

      - name: Build client-standalone (webDir for Capacitor)
        run: pnpm --filter @triliumnext/mobile build

      - name: Sync Capacitor Android project
        run: pnpm --filter @triliumnext/mobile exec cap sync android

      - name: Assemble debug APK
        working-directory: apps/mobile/android
        run: ./gradlew assembleDebug --no-daemon

      - name: Upload APK
        uses: actions/upload-artifact@v7
        with:
          name: trilium-mobile-debug-apk
          path: apps/mobile/android/app/build/outputs/apk/debug/*.apk
          retention-days: 14
