name: CI

# On every pull request, but only on push to master
on:
  push:
    branches:
    - main
    tags:
    - '*'
  pull_request:
env:
  LATEST_PY_VERSION: '3.11'

jobs:
  tests:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']

    steps:
      - uses: actions/checkout@v3
      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v4
        with:
          python-version: ${{ matrix.python-version }}

      - name: Install affine
        run: |
          python -m pip install --upgrade pip
          python -m pip install .["test"]

      - name: Run tests
        run: |
          python -m pytest --cov=affine --cov-report=term-missing --cov-report=xml

      - name: Upload Coverage Results
        if: ${{ matrix.python-version == env.LATEST_PY_VERSION }}
        uses: codecov/codecov-action@v3
        with:
          files: ./coverage.xml
          flags: unittests
          fail_ci_if_error: false

  lint:
    needs: tests
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Set up Python
        uses: actions/setup-python@v4
        with:
          python-version: ${{ env.LATEST_PY_VERSION }}

      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          python -m pip install flake8 pydocstyle

      - name: Run lint
        run: |
          flake8 --ignore=E501,W503
          python -m pydocstyle affine

  typing:
    needs: tests
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Set up Python
        uses: actions/setup-python@v4
        with:
          python-version: ${{ env.LATEST_PY_VERSION }}

      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          python -m pip install mypy pytest

      - name: Run typing test
        run: |
          mypy affine
