diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index efb5421..84de679 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -1,31 +1,62 @@ -# This workflow will install Python dependencies, run tests and lint with a single version of Python -# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python - -name: Tests +name: '🔎 Python Tests' on: - push: - branches: [ "main" ] pull_request: - branches: [ "main" ] + branches: + - main -permissions: - contents: read +concurrency: + group: ci-tests-${{ github.ref }}-pytest + cancel-in-progress: true jobs: - build: + python-tests: runs-on: ubuntu-latest + strategy: + matrix: + python-version: [ "3.8", "3.12" ] steps: - - uses: actions/checkout@v3 - - name: Set up Python 3.12 - uses: actions/setup-python@v3 - with: - python-version: "3.12" - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -e .[test] - - name: Test with pytest - run: pytest + - name: Checkout repo + uses: actions/checkout@v4 + + + - id: setup_python + name: Set up Python ${{ matrix.python-version }} Environment + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + + - id: python_cache + name: Retrieve Cached Python Dependencies + uses: actions/cache@v3 + with: + path: ${{ env.pythonLocation }} + key: ${{ runner.os }}-pip-${{ steps.setup_python.outputs.python-version }}-${{ hashFiles('pyproject.toml') }} + + - name: Upgrade pip + if: steps.python_cache.outputs.cache-hit != 'true' + run: python -m pip install --upgrade pip + + - name: Install Dependencies + run: pip install .[test] + + - name: Tests (Coverage) + if: matrix.python-version == '3.12' + run: | + coverage run --data-file=data -m pytest tests + coverage xml -i --data-file=data -o coverage.xml + + - name: Tests + if: matrix.python-version != '3.12' + run: pytest tests + + - name: Upload to Codecov + if: matrix.python-version == '3.12' + uses: codecov/codecov-action@v3.1.1 + with: + token: ${{ secrets.CODECOV_TOKEN }} + files: coverage.xml + fail_ci_if_error: false + verbose: true