name: CI

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

jobs:
  lint:
    name: Lint & Format Check
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      
      - name: Install uv
        uses: astral-sh/setup-uv@v2
        with:
          version: "latest"
      
      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: "{{ python_version }}"
      
      - name: Install dependencies
        run: uv sync --all-extras
      
      - name: Run Ruff linter
        run: uv run ruff check .
      
      - name: Run Ruff formatter
        run: uv run ruff format --check .
{% if enable_strict_mypy %}
      
      - name: Run mypy
        run: uv run mypy src
{% endif %}

  test:
    name: Test
    runs-on: {% raw %}${{ matrix.os }}{% endraw %}
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, windows-latest, macos-latest]
        python-version: ["{{ python_version }}"]
    
    steps:
      - uses: actions/checkout@v4
      
      - name: Install uv
        uses: astral-sh/setup-uv@v2
        with:
          version: "latest"
      
      - name: Set up Python {% raw %}${{ matrix.python-version }}{% endraw %}
        uses: actions/setup-python@v5
        with:
          python-version: {% raw %}${{ matrix.python-version }}{% endraw %}
      
      - name: Install dependencies
        run: uv sync --all-extras
      
      - name: Run tests
        run: uv run pytest --cov={{ package_name }} --cov-report=xml --cov-report=term
      
      - name: Upload coverage to Codecov
        uses: codecov/codecov-action@v3
        with:
          file: ./coverage.xml
          fail_ci_if_error: false

{% if include_docker %}
  docker:
    name: Docker Build
    runs-on: ubuntu-latest
    needs: [lint, test]
    steps:
      - uses: actions/checkout@v4
      
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3
      
      - name: Build Docker image
        uses: docker/build-push-action@v5
        with:
          context: .
          push: false
          tags: {{ project_slug }}:latest
          cache-from: type=gha
          cache-to: type=gha,mode=max
{% endif %}

  security:
    name: Security Scan
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      
      - name: Install uv
        uses: astral-sh/setup-uv@v2
        with:
          version: "latest"
      
      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: "{{ python_version }}"
      
      - name: Install dependencies
        run: uv sync
      
      - name: Run safety check
        run: uv run pip-audit
        continue-on-error: true