# .github/workflows/quality-gates.yml
# Copy this file to .github/workflows/ in your repository.
# Budget: under 5 minutes total.

name: Quality Gates

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

jobs:
  quality:
    runs-on: ubuntu-latest
    services:
      postgres:
        image: postgres:15
        env:
          POSTGRES_USER: test
          POSTGRES_PASSWORD: test
          POSTGRES_DB: test_db
        ports:
          - 5432:5432
        options: >-
          --health-cmd pg_isready
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5

    steps:
      - uses: actions/checkout@v4

      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: "3.11"
          cache: pip

      - name: Install dependencies
        run: |
          pip install -r requirements.txt
          pip install -r requirements-dev.txt

      - name: Ruff format check
        run: ruff format --check app/ tests/

      - name: Ruff lint
        run: ruff check app/ tests/

      - name: Mypy strict type checking
        run: mypy app/ --strict

      - name: Run tests with coverage
        env:
          DATABASE_URL: postgresql+asyncpg://test:test@localhost:5432/test_db
        run: |
          pytest tests/ \
            --cov=app \
            --cov-report=term-missing \
            --cov-fail-under=80 \
            -x -q

      - name: Dependency vulnerability audit
        run: pip-audit --strict --progress-spinner=off
