name: Android Instrumented Data Tests

permissions:
  contents: read

on:
  pull_request:

jobs:
  instrumented-tests:
    name: Run Android Instrumented Data Tests
    runs-on: ubuntu-latest

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

      - name: Set up JDK 17
        uses: actions/setup-java@v4
        with:
          java-version: '17'
          distribution: 'temurin'

      - name: Enable KVM
        run: |
          echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
          sudo udevadm control --reload-rules
          sudo udevadm trigger --name-match=kvm

      - name: Run Instrumented Data Tests with emulator
        uses: reactivecircus/android-emulator-runner@v2
        with:
          api-level: 33
          target: google_apis
          arch: x86_64
          profile: pixel
          avd-name: instrumented-tests-avd
          force-avd-creation: true
          disable-animations: true
          emulator-options: -no-window -no-audio -no-boot-anim -accel auto -memory 2048
          script: ./gradlew :ownCloudData:connectedAndroidTest
