name: CI

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

env:
  NO_COLOR: "1"  # Disable Rich ANSI codes in CLI tests

jobs:
  lint:
    name: Lint
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - uses: astral-sh/setup-uv@v6
        with:
          enable-cache: true

      - name: Lint with Ruff
        run: |
          uv run ruff check src/ tests/
          uv run ruff format --check src/ tests/

  typecheck:
    name: Type Check
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - uses: astral-sh/setup-uv@v6
        with:
          enable-cache: true

      - name: Type check with MyPy
        run: uv run mypy src/ --strict

  test:
    name: Test
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - uses: astral-sh/setup-uv@v6
        with:
          enable-cache: true

      - name: Run tests
        timeout-minutes: 10
        run: |
          uv run pytest tests/ -v --tb=short \
            --timeout=60 \
            --cov=src/gpumod --cov-report=term-missing \
            --cov-fail-under=80 \
            -m "not gpu_required and not docker_required"

  audit:
    name: Security Audit
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - uses: astral-sh/setup-uv@v6
        with:
          enable-cache: true

      - name: Export requirements
        run: uv export --no-hashes > requirements.txt

      - name: Audit dependencies
        run: uvx pip-audit -r requirements.txt --desc on
        continue-on-error: true  # Informational - transitive deps may have CVEs
