name: Android UI Tests
on:
  pull_request:
    branches: [main, master]
  push:
    branches: [main, master]
jobs:
  ui-tests:
    runs-on: macos-14
    timeout-minutes: 45
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-java@v4
        with: { distribution: temurin, java-version: 17 }
      - name: Accept Android licenses
        run: yes | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --licenses || true
      - name: Verify test-tag parity
        run: ./scripts/verify_test_tag_parity.sh
      - name: Run unit tests
        run: ./gradlew :composeApp:testDebugUnitTest
      - name: Verify screenshot regressions
        run: ./gradlew :composeApp:verifyRoborazziDebug
      - name: Upload screenshot diffs on failure
        if: failure()
        uses: actions/upload-artifact@v4
        with:
          name: roborazzi-diffs
          path: composeApp/build/outputs/roborazzi/
      - name: Run instrumented tests (managed device)
        run: ./gradlew :composeApp:pixel7Api34DebugAndroidTest
        env:
          GRADLE_OPTS: -Xmx4g -XX:+UseParallelGC
      - name: Upload test reports
        if: failure()
        uses: actions/upload-artifact@v4
        with:
          name: test-reports
          path: composeApp/build/reports/
