name: Coverage Reporting

on:
  push:
    branches:
      - master
      - develop

  pull_request:
    branches:
      - '**'

jobs:

  coverageReport:
    strategy:
      max-parallel: 2
      matrix:
        api-level: [21, 30, 21,30]
      fail-fast: false
    runs-on: macOS-latest
    steps:
      - name: checkout
        uses: actions/checkout@v3
        with:
          fetch-depth: 1

      - name: create instrumentation coverage
        uses: ReactiveCircus/android-emulator-runner@v2.23.0
        with:
          api-level: ${{ matrix.api-level }}
          arch: x86_64
          ndk: 21.4.7075529
          script: bash contrib/instrumentation.sh

      - name: Upload screenshot result
        uses: actions/upload-artifact@v1
        if: failure()
        with:
          name: ${{ matrix.api-level }}
          path: screencap.png

      - name: create unit coverage
        run: ./gradlew jacocoTestDebugUnitTestReport jacocoTestCustomExampleDebugUnitTestReport

      - name: Upload coverage to Codecov
        run: |
          bash <(curl -s https://codecov.io/bash)

      - name: Upload Coverage to GH-Actions
        uses: actions/upload-artifact@v2.2.0
        if: ${{ always()  }}
        with:
          name: Tests Coverage Report
          path: |
            **/reports/
