name: CI

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

jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6

      - uses: astral-sh/setup-uv@v7
        with:
          version: "latest"

      - name: Lint with ruff
        run: uvx ruff check drakkar/ tests/

      - name: Check formatting
        run: uvx ruff format --check drakkar/ tests/

  test:
    runs-on: ubuntu-latest
    needs: lint
    strategy:
      matrix:
        python-version: ["3.13", "3.14"]
    steps:
      - uses: actions/checkout@v6

      - uses: astral-sh/setup-uv@v7
        with:
          version: "latest"

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

      - name: Install dependencies
        run: uv sync --extra=dev

      - name: Type check with ty
        if: matrix.python-version == '3.14'
        run: uv run ty check drakkar/

      - name: Run tests with coverage
        run: uv run pytest --cov=drakkar --cov-report=term-missing --cov-report=xml --junitxml=junit.xml

      - name: Upload coverage artifact
        if: matrix.python-version == '3.14'
        uses: actions/upload-artifact@v6
        with:
          name: coverage-report
          path: |
            coverage.xml
            junit.xml

      - name: Coverage summary
        if: always() && hashFiles('.coverage') != ''
        run: uv run coverage report --format=markdown >> "$GITHUB_STEP_SUMMARY"
