name: Windows

on:
  push:
  pull_request:

jobs:
  test:
    name: Test on Python ${{ matrix.python-version }} and ${{ matrix.os }}
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        python-version: [ 3.7, 3.8, 3.9, '3.10' ]
        os: [ windows-latest ]
    env:
      APKTOOL_VERSION: 2.6.0
      BUILD_TOOLS_VERSION: 32.0.0

    steps:
      - name: Checkout repository
        uses: actions/checkout@v2

      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v2
        with:
          python-version: ${{ matrix.python-version }}
          architecture: x64

      - name: Install Python packages
        run: |
          python -m pip install --upgrade pip
          python -m pip install -r ./src/requirements.txt

      - name: Install dependencies
        shell: powershell
        run: |
          # Install Apktool.
          wget https://raw.githubusercontent.com/iBotPeaches/Apktool/master/scripts/windows/apktool.bat -OutFile C:\Windows\apktool.bat
          wget "https://bitbucket.org/iBotPeaches/apktool/downloads/apktool_$env:APKTOOL_VERSION.jar" -OutFile C:\Windows\apktool.jar

      - name: Run tests
        shell: powershell
        run: |
          $env:PATH="$($env:PATH);$($env:ANDROID_HOME)\build-tools\$($env:BUILD_TOOLS_VERSION)"
          pytest --verbose --cov=./ --cov-report xml

      - name: Upload tests coverage to Codacy
        if: contains(github.event_name, 'pull_request') == false
        env:
          CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }}
        run: |
          python -m pip install codacy-coverage
          python-codacy-coverage

      - name: Upload tests coverage to Codecov
        uses: codecov/codecov-action@v1
        with:
          fail_ci_if_error: false
