name: CI

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

jobs:
  test:
    name: Test Python ${{ matrix.python-version }}
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version: ["3.13"]

    steps:
    - uses: actions/checkout@v4

    - name: Install uv
      uses: astral-sh/setup-uv@v5
      with:
        version: "latest"

    - name: Set up Python ${{ matrix.python-version }}
      run: uv python install ${{ matrix.python-version }}

    - name: Create virtual environment
      run: uv venv

    - name: Install dependencies
      run: |
        uv pip install -e ".[dev]"

    - name: Run tests
      run: |
        source .venv/bin/activate
        pytest --cov=schema_sentinel --cov-report=xml --cov-report=term-missing

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

  lint:
    name: Lint and Format Check
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v4

    - name: Install uv
      uses: astral-sh/setup-uv@v5
      with:
        version: "latest"

    - name: Set up Python
      run: uv python install 3.13

    - name: Create virtual environment
      run: uv venv

    - name: Install dependencies
      run: |
        uv pip install -e ".[dev]"

    - name: Check code formatting with Ruff
      run: |
        source .venv/bin/activate
        ruff format --check .

    - name: Lint with Ruff
      run: |
        source .venv/bin/activate
        ruff check .

  type-check:
    name: Type Checking
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v4

    - name: Install uv
      uses: astral-sh/setup-uv@v5
      with:
        version: "latest"

    - name: Set up Python
      run: uv python install 3.13

    - name: Create virtual environment
      run: uv venv

    - name: Install dependencies
      run: |
        uv pip install -e ".[dev]"

    - name: Type check with mypy
      run: |
        source .venv/bin/activate
        mypy schema_sentinel/ --ignore-missing-imports
      continue-on-error: true
