name: build
on: [pull_request, push]
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout the code
        uses: actions/checkout@v3
      - name: Validate Gradle wrapper
        uses: gradle/wrapper-validation-action@e6e38bacfdf1a337459f332974bb2327a31aaf4b
      - name: Build the app
        run: ./gradlew build
      - uses: actions/upload-artifact@v3
        with:
          name: apk
          path: app/build/outputs/apk/debug/app-debug.apk
  test:
    runs-on: macos-latest
    # This is probably pretty expensive for GitHub, so restrict the repositories that this job runs on
    if: github.repository == 'beemdevelopment/Aegis' || github.repository == 'alexbakker/Aegis'
    steps:
      - name: Checkout
        uses: actions/checkout@v3
      - uses: actions/setup-java@v3
        with:
          java-version: '11'
          distribution: 'temurin'
          cache: 'gradle'
      - name: Install HAXM
        run: brew install --cask intel-haxm
      - name: Tests
        uses: reactivecircus/android-emulator-runner@e790971012b979513b4e2fe70d4079bc0ca8a1ae
        with:
          api-level: 31
          arch: x86_64
          profile: pixel_3a
          heap-size: 512M
          ram-size: 4096M
          emulator-options: -memory 4096 -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
          disable-animations: true
          disk-size: 8G
          script: |
            mkdir -p artifacts/report
            adb logcat -c
            adb logcat -G 16M && adb logcat -g
            ./gradlew connectedCheck || touch tests_failing
            adb logcat -d > artifacts/logcat.txt
            cp -r app/build/reports/androidTests/connected/* artifacts/report/
            if adb shell '[ -e /sdcard/Pictures/screenshots ]'; then adb pull /sdcard/Pictures/screenshots artifacts/; fi
          # test ! -f tests_failing
      - uses: actions/upload-artifact@v3
        if: always()
        with:
          name: instrumented-test-report
          path: |
            artifacts/*
          if-no-files-found: ignore
