name: Android Test

on:
  push: {}
  workflow_dispatch: {}

jobs:
  test:
    runs-on: debian

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

      - name: Configure SDK path
        run: echo "sdk.dir=/opt/android-sdk" > local.properties

      - name: Check Java version
        run: |
          if ! command -v java >/dev/null; then
            echo "❌ Java is not installed"
            exit 1
          fi
          echo "✅ Java version:"
          java -version

      - name: Extract version from build.gradle
        id: version
        run: |
          VERSION=$(sed -nE 's/^[[:space:]]*versionName[[:space:]]*=[[:space:]]*"([^"]+)"/\1/p' app/build.gradle)
          VERSION="v${VERSION#v}"  # normalize to vX.Y.Z
          echo "$VERSION" > version.txt
          echo "✅ Detected version: $VERSION"

      - name: Set up gradle
        run: chmod +x ./gradlew

      - name: Run tests
        run: ./gradlew testDebugUnitTest
