|
| 1 | +name: Quality Gate |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + - master |
| 8 | + pull_request: |
| 9 | + |
| 10 | +jobs: |
| 11 | + # Fast, deterministic checks — no database, no network beyond pip. |
| 12 | + free-tier: |
| 13 | + name: free-tier (unit, lint, health, evals-p) |
| 14 | + runs-on: ubuntu-latest |
| 15 | + steps: |
| 16 | + - name: Checkout |
| 17 | + uses: actions/checkout@v4 |
| 18 | + |
| 19 | + - name: Setup Python |
| 20 | + uses: actions/setup-python@v7 |
| 21 | + with: |
| 22 | + python-version: '3.11' |
| 23 | + |
| 24 | + - name: Install dev dependencies |
| 25 | + # api/requirements.txt is needed too: tests/test_api.py imports FastAPI |
| 26 | + # at module level, so without it pytest collection fails. |
| 27 | + run: pip install -r requirements-dev.txt -r api/requirements.txt |
| 28 | + |
| 29 | + - name: Unit / regression / security / snapshot tests — final result |
| 30 | + run: | |
| 31 | + python3 scripts/test_report.py \ |
| 32 | + --markers "unit or regression or security or snapshot" --strict |
| 33 | +
|
| 34 | + - name: Lint (flake8 + bandit) |
| 35 | + run: make lint |
| 36 | + |
| 37 | + - name: Component health check |
| 38 | + run: make health |
| 39 | + |
| 40 | + - name: Evals — Tier P (offline validator scenarios) |
| 41 | + run: python3 evals/runner.py --tiers p --verbose |
| 42 | + |
| 43 | + # Reports (incl. the VCRM gap report) are written to evals/reports/ and |
| 44 | + # would otherwise vanish with the runner — keep them for auditability. |
| 45 | + - name: Upload eval reports |
| 46 | + if: always() |
| 47 | + uses: actions/upload-artifact@v4 |
| 48 | + with: |
| 49 | + name: eval-reports-free-tier |
| 50 | + path: evals/reports/ |
| 51 | + if-no-files-found: ignore |
| 52 | + retention-days: 30 |
| 53 | + |
| 54 | + # Full integration surface: Tier I deploys env_dev.sql twice (idempotency), |
| 55 | + # Tier S runs the 142-assertion SQL suite, then the PG-gated pytest tiers run. |
| 56 | + integration-postgres: |
| 57 | + name: integration (postgres service) |
| 58 | + runs-on: ubuntu-latest |
| 59 | + services: |
| 60 | + postgres: |
| 61 | + image: postgres:16-alpine |
| 62 | + env: |
| 63 | + POSTGRES_PASSWORD: postgres |
| 64 | + ports: |
| 65 | + - 5432:5432 |
| 66 | + options: >- |
| 67 | + --health-cmd "pg_isready -U postgres" |
| 68 | + --health-interval 5s |
| 69 | + --health-timeout 5s |
| 70 | + --health-retries 10 |
| 71 | + env: |
| 72 | + PGHOST: localhost |
| 73 | + PGPORT: "5432" |
| 74 | + PGUSER: postgres |
| 75 | + PGPASSWORD: postgres |
| 76 | + PGDATABASE: postgres |
| 77 | + steps: |
| 78 | + - name: Checkout |
| 79 | + uses: actions/checkout@v4 |
| 80 | + |
| 81 | + - name: Setup Python |
| 82 | + uses: actions/setup-python@v7 |
| 83 | + with: |
| 84 | + python-version: '3.11' |
| 85 | + |
| 86 | + - name: Install dev dependencies |
| 87 | + # api/requirements.txt is needed too: tests/test_api.py imports FastAPI |
| 88 | + # at module level, so without it pytest collection fails. |
| 89 | + run: pip install -r requirements-dev.txt -r api/requirements.txt |
| 90 | + |
| 91 | + - name: Install PostgreSQL client |
| 92 | + run: sudo apt-get update && sudo apt-get install -y --no-install-recommends postgresql-client |
| 93 | + |
| 94 | + - name: Write CI database config |
| 95 | + run: | |
| 96 | + cat > build/config.local.env <<'EOF' |
| 97 | + DB_ENGINE="postgresql" |
| 98 | + PG_HOST="localhost" |
| 99 | + PG_PORT="5432" |
| 100 | + PG_SUPERUSER="postgres" |
| 101 | + PG_SUPERUSER_PASSWORD="postgres" |
| 102 | + PG_DB_DEV="te_mgmt_dev" |
| 103 | + PG_SCHEMA_DEV="te_dev" |
| 104 | + PG_DB_TEST="te_mgmt_test" |
| 105 | + PG_SCHEMA_TEST="te_test" |
| 106 | + PG_DB_STAGING="te_mgmt_staging" |
| 107 | + PG_SCHEMA_STAGING="te_staging" |
| 108 | + PG_DB_PROD="te_mgmt_prod" |
| 109 | + PG_SCHEMA_PROD="te_prod" |
| 110 | + EOF |
| 111 | +
|
| 112 | + # env_*.sql scripts do not create their databases — deploy_all.sh does that |
| 113 | + # before invoking them (see build/te_core_schema.sql:41). Mirror it here. |
| 114 | + # Only *.example.sql are committed (concrete env_<env>.sql are gitignored), |
| 115 | + # so materialise them before anything that deploys an environment. |
| 116 | + - name: Materialise environment launchers from templates |
| 117 | + run: | |
| 118 | + for env in dev test staging prod; do |
| 119 | + cp "build/environments/env_${env}.example.sql" \ |
| 120 | + "build/environments/env_${env}.sql" |
| 121 | + done |
| 122 | + ls -1 build/environments/ |
| 123 | +
|
| 124 | + - name: Create environment databases |
| 125 | + run: | |
| 126 | + for db in te_mgmt_dev te_mgmt_test te_mgmt_staging te_mgmt_prod; do |
| 127 | + if [ -z "$(psql -d postgres -tA -c "SELECT 1 FROM pg_database WHERE datname = '$db'")" ]; then |
| 128 | + psql -v ON_ERROR_STOP=1 -d postgres -c \ |
| 129 | + "CREATE DATABASE \"$db\" WITH OWNER = postgres ENCODING = 'UTF8' TEMPLATE = template0 CONNECTION LIMIT = -1" |
| 130 | + fi |
| 131 | + done |
| 132 | +
|
| 133 | + - name: Evals — Tiers P, I, S |
| 134 | + run: python3 evals/runner.py --tiers p,i,s --verbose |
| 135 | + |
| 136 | + - name: Deploy all environments (for cross-env parity) |
| 137 | + run: | |
| 138 | + for env in dev test staging prod; do |
| 139 | + bash build/deploy_all.sh "$env" |
| 140 | + done |
| 141 | +
|
| 142 | + # Prints a final block accounting for every test: PASSED / FAILED / |
| 143 | + # ERROR / SKIPPED (with reasons) / NOT RUN (deselected). --strict fails |
| 144 | + # the build on any skip. |
| 145 | + - name: Full test suite — final result with skip accounting |
| 146 | + run: python3 scripts/test_report.py --strict |
| 147 | + |
| 148 | + - name: Upload eval reports |
| 149 | + if: always() |
| 150 | + uses: actions/upload-artifact@v4 |
| 151 | + with: |
| 152 | + name: eval-reports-integration |
| 153 | + path: evals/reports/ |
| 154 | + if-no-files-found: ignore |
| 155 | + retention-days: 30 |
0 commit comments