name: Tests
on:
  push:
    branches:
      - 'master'
jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
    steps:
    - name: Checkout
      uses: actions/checkout@v4
      with:
        fetch-depth: 0
    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v5
      with:
        python-version: ${{ matrix.python-version }}
    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install -r requirements.txt
        pip install pytest
        pip install pytest-xdist
        pip install pytest-cov
        pip install faker
        pip install pillow
    - name: Add 'testrail_api_reporter' to PYTHONPATH
      run: echo "PYTHONPATH=$PYTHONPATH:$(pwd)/testrail_api_reporter:." >> $GITHUB_ENV
    - name: Execute tests
      id: tests
      continue-on-error: true
      env:
        FREEIMAGEHOST_API_KEY: ${{ secrets.FREEIMAGEHOST_API_KEY }}
      run: pytest tests -n=auto --cov=testrail_api_reporter --cov-report=term --cov-report=xml:coverage.xml --cov-report=html
    - name: Upload coverage reports to Codecov
      uses: codecov/codecov-action@v4.0.1
      with:
        token: ${{ secrets.CODECOV_TOKEN }}
        slug: wwakabobik/testrail_api_reporter
        flags: unittests
        name: codecov-umbrella
        fail_ci_if_error: true
    - name: Coveralls GitHub Action
      uses: coverallsapp/github-action@v2.2.3
      with:
        github-token: ${{ secrets.COVERALLS_REPO_TOKEN }}
    - name: Summary status of tests
      run:  |
        if [[ "${{ steps.tests.outcome }}" == "failure" ]]; then
          exit 1
        fi
