# This workflow runs tests on every push and pull request

name: Tests

on:
  push:
    branches: [ main, develop ]
  pull_request:
    branches: [ main, develop ]

permissions:
  contents: read

jobs:
  test:
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest, windows-latest, macos-latest]
        python-version: ["3.8", "3.9", "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
          pip install -e ".[dev]"

      - name: Run tests with coverage
        run: |
          python -m pytest tests/ -v --cov=cse_lk --cov-report=xml --cov-report=term

      - name: Upload coverage to Codecov
        uses: codecov/codecov-action@v3
        with:
          file: ./coverage.xml
          flags: unittests
          name: codecov-umbrella
          fail_ci_if_error: false

  lint:
    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 linting dependencies
        run: |
          python -m pip install --upgrade pip
          pip install black flake8 mypy

      - name: Run Black
        run: |
          python -m black --check --diff cse_lk/ tests/ examples/

      - name: Run Flake8
        run: |
          python -m flake8 cse_lk/ tests/ examples/ --max-line-length=88 --extend-ignore=E203,W503

      - name: Run MyPy
        run: |
          python -m mypy cse_lk/ --ignore-missing-imports 