name: Python QA

on: [push, pull_request]

jobs:
  build-test:
    name: Build & Test
    runs-on: ubuntu-20.04
    strategy:
      matrix:
        python-version: ['3.10',
                         '3.11',
                         '3.12']

    steps:
    - uses: actions/checkout@v4
    - 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 setuptools wheel pytest flit
        python -m pip install -r requirements.all.txt
        python -m pip install -r docs/requirements.txt
        
    - name: Build (Flit)
      run: |
        python -m flit build
        rm -r dist/

    - name: Test
      run: |
        python -m pytest

    - name: Build & Install
      run: |
        python ./setup.py build
        python ./setup.py install --root=/tmp


  lint:
    name: Linting
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - uses: actions/setup-python@v5
      with:
        python-version: '3.x'
    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip setuptools wheel 'flake8>=4.0' 'pylint>=2.12' black
        python -m pip install -r requirements.all.txt

    - name: Lint (flake8)
      run: |
        python -m flake8 ./edlio ./tests --show-source --statistics

    - name: Lint (pylint)
      run: |
        python -m pylint -f colorized ./edlio ./tests
        python -m pylint -f colorized setup.py

    - name: Lint (black)
      run: |
        python -m black --diff .


  mypy:
    name: MyPy Typecheck
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - uses: actions/setup-python@v5
      with:
        python-version: '3.x'
    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip setuptools wheel mypy
        python -m pip install -r requirements.all.txt

    - name: Check with MyPy
      run: |
        mypy --pretty edlio
