name: Android build PR
on: [pull_request]
jobs:
  run-build:
    runs-on: ubuntu-20.04
    if: github.event.pull_request.head.repo.full_name != github.repository && github.actor != 'MickeyMoz'
    steps:
      - name: Checkout repository
        uses: actions/checkout@v2
      - name: Setup Java
        uses: actions/setup-java@v1
        with:
          java-version: 11
      - name: "Clean & Assemble Debug"
        uses: eskatos/gradle-command-action@v1
        with:
          wrapper-cache-enabled: true
          dependencies-cache-enabled: true
          configuration-cache-enabled: true
          arguments: clean app:assembleDebug

  run-testDebugUnitTest:
    runs-on: ubuntu-20.04
    if: github.event.pull_request.head.repo.full_name != github.repository && github.actor != 'MickeyMoz'

    steps:
      - name: Checkout repository
        uses: actions/checkout@v2
      - name: Setup Java
        uses: actions/setup-java@v1
        with:
          java-version: 11
      - name: "Test Debug Unit Tests"
        uses: eskatos/gradle-command-action@v1
        with:
          wrapper-cache-enabled: true
          dependencies-cache-enabled: true
          configuration-cache-enabled: true
          arguments: testDebugUnitTest

  run-detekt:
    runs-on: ubuntu-20.04
    if: github.event.pull_request.head.repo.full_name != github.repository && github.actor != 'MickeyMoz'

    steps:
      - name: Checkout repository
        uses: actions/checkout@v2
      - name: Setup Java
        uses: actions/setup-java@v1
        with:
          java-version: 11
      - name: "Detekt"
        uses: eskatos/gradle-command-action@v1
        with:
          wrapper-cache-enabled: true
          dependencies-cache-enabled: true
          configuration-cache-enabled: true
          arguments: detekt
      - name: Archive detekt results
        uses: actions/upload-artifact@v2
        with:
          name: detekt report
          path: build/reports/detekt.html

  run-ktlint:
    runs-on: ubuntu-20.04
    if: github.event.pull_request.head.repo.full_name != github.repository && github.actor != 'MickeyMoz'

    steps:
      - name: Checkout repository
        uses: actions/checkout@v2
      - name: Setup Java
        uses: actions/setup-java@v1
        with:
          java-version: 11
      - name: "Ktlint"
        uses: eskatos/gradle-command-action@v1
        with:
          wrapper-cache-enabled: true
          dependencies-cache-enabled: true
          configuration-cache-enabled: true
          arguments: ktlint

  run-lintDebug:
    runs-on: ubuntu-20.04
    if: github.event.pull_request.head.repo.full_name != github.repository && github.actor != 'MickeyMoz'

    steps:
      - name: Checkout repository
        uses: actions/checkout@v2
      - name: Setup Java
        uses: actions/setup-java@v1
        with:
          java-version: 11
      - name: "Lint Debug"
        uses: eskatos/gradle-command-action@v1
        with:
          wrapper-cache-enabled: true
          dependencies-cache-enabled: true
          configuration-cache-enabled: true
          arguments: lintDebug
      - name: Archive lint results
        uses: actions/upload-artifact@v2
        with:
          name: lintDebug report
          path: app/build/reports/lint-results-debug.html

  run-ui:
    runs-on: macos-11
    if: ${{ false }}

    timeout-minutes: 60
    strategy:
      matrix:
        api-level: [28]
        target: [google_apis]
    steps:
      - name: Checkout
        uses: actions/checkout@v2
      - name: Run subset of UI Tests
        uses: reactivecircus/android-emulator-runner@v2.21.0
        with:
          api-level: ${{ matrix.api-level }}
          target: ${{ matrix.target }}
          arch: x86_64
          profile: pixel_2
          script:
            "JAVA_HOME=$JAVA_HOME_11_X64 && ./gradlew connectedDebugAndroidTest -Pandroid.testInstrumentationRunnerArguments.class=\
            org.mozilla.fenix.ui.NavigationToolbarTest#visitURLTest"
      - name: Upload Test Artifacts
        uses: actions/upload-artifact@v2
        with:
          name: test-report
          path: app/build/reports
