name: Check

on: [ pull_request ]

jobs:
  check:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0

      - uses: ashutoshgngwr/validate-fastlane-supply-metadata@v2
        with:
          fastlaneDir: ./fastlane/metadata/android
          usePlayStoreLocales: true

      - uses: actions/setup-java@v3
        with:
          distribution: temurin
          java-version: 11

      - name: Setup Gradle
        uses: gradle/gradle-build-action@v2

      - name: Run tests
        env:
          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
        run: ./gradlew check coverageReport sonar --no-configuration-cache --no-daemon

      - name: Publish test reports
        uses: mikepenz/action-junit-report@v3
        if: always() # always run even if the previous step fails
        with:
          report_paths: './**/build/test-results/**/TEST-*.xml'

  uiTests:
    runs-on: macos-latest
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0

      - uses: actions/setup-java@v3
        with:
          distribution: temurin
          java-version: 11

      - name: Setup Gradle
        uses: gradle/gradle-build-action@v2

      - name: Setup Android SDK
        uses: android-actions/setup-android@v2

      - name: Run tests
        run: ./gradlew allDevicesCheck --no-daemon -Pandroid.testoptions.manageddevices.emulator.gpu="swiftshader_indirect"
