# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Python package

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

defaults:
  run:
    shell: bash

jobs:

  testCode:

    strategy:
      matrix:
        os: [ubuntu-latest, windows-latest]
        python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
    runs-on: ${{ matrix.os }}

    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
        pip install flake8 pytest
        if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
    - name: Lint with flake8
      run: |
        # stop the build if there are Python syntax errors or undefined names
        flake8 . --count --show-source --statistics
    - name: Check black formatting
      run: |
        # stop the build if black detect any changes
        black --check .
    - name: Check isort sorting
      run: |
        # stop the build if isort detect any changes
        isort . --check --diff
    - name: Test with pytest
      run: |
        pytest

  testUploadability:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v4
    - name: Set up Python
      uses: actions/setup-python@v5
      with:
        python-version: '3.x'
    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install setuptools wheel twine
        if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
    - name: Test with rstcheck
      run: |
        rstcheck README.rst
    - name: Build and check
      run: |
        python setup.py sdist bdist_wheel
        twine check dist/*
