-
Notifications
You must be signed in to change notification settings - Fork 3
191 lines (171 loc) · 5.63 KB
/
Copy pathbackend-quality.yml
File metadata and controls
191 lines (171 loc) · 5.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
name: Backend quality
on:
# NO ``paths:`` filter — every required status check below is gated by
# the branch protection ruleset, and GitHub holds a required check in
# "Expected" forever if its workflow doesn't run at all. Always trigger
# on every PR so the checks always report; the jobs themselves are
# cheap when nothing in backend/ changed.
pull_request:
push:
branches: [main]
jobs:
mypy:
name: mypy --strict (blocks merge)
runs-on: ubuntu-latest
timeout-minutes: 10
defaults:
run:
working-directory: backend
steps:
- uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.12"
cache: "pip"
cache-dependency-path: backend/pyproject.toml
- name: Install backend (with dev extras)
run: |
python -m pip install --upgrade pip
pip install -e ".[dev]"
- name: Run mypy
run: mypy app/
ruff:
name: ruff (lint + format)
runs-on: ubuntu-latest
timeout-minutes: 5
defaults:
run:
working-directory: backend
steps:
- uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.12"
cache: "pip"
cache-dependency-path: backend/pyproject.toml
- name: Install ruff
run: pip install ruff
- name: ruff check
run: ruff check app/
- name: ruff format --check
run: ruff format --check app/
pytest:
name: pytest (backend tests)
runs-on: ubuntu-latest
timeout-minutes: 15
defaults:
run:
working-directory: backend
services:
postgres:
image: pgvector/pgvector:pg16
env:
POSTGRES_USER: bodhiorchard
POSTGRES_PASSWORD: bodhiorchard
POSTGRES_DB: bodhiorchard_test
ports:
- 5432:5432
options: >-
--health-cmd "pg_isready -U bodhiorchard"
--health-interval 5s
--health-timeout 5s
--health-retries 12
redis:
image: redis:7-alpine
ports:
- 6379:6379
options: >-
--health-cmd "redis-cli ping"
--health-interval 5s
--health-timeout 5s
--health-retries 12
env:
DATABASE_URL: postgresql+asyncpg://bodhiorchard:bodhiorchard@localhost:5432/bodhiorchard_test
REDIS_URL: redis://localhost:6379
SECRET_KEY: ci-secret-not-for-prod
ENCRYPTION_KEY: ci-encryption-key-not-for-prod
steps:
- uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.12"
cache: "pip"
cache-dependency-path: backend/pyproject.toml
- name: Install backend (with dev extras)
run: |
python -m pip install --upgrade pip
pip install -e ".[dev]"
- name: Run pytest with coverage
run: |
pytest -q --maxfail=10 \
--cov=app --cov-report=term-missing --cov-report=xml --cov-report=html
- name: Upload coverage report
if: always()
uses: actions/upload-artifact@v4
with:
name: backend-coverage
path: |
backend/coverage.xml
backend/htmlcov/
retention-days: 14
alembic-check:
name: alembic (migrations in sync with models)
runs-on: ubuntu-latest
timeout-minutes: 10
defaults:
run:
working-directory: backend
services:
postgres:
image: pgvector/pgvector:pg16
env:
POSTGRES_USER: bodhiorchard
POSTGRES_PASSWORD: bodhiorchard
POSTGRES_DB: bodhiorchard_migrations
ports:
- 5432:5432
options: >-
--health-cmd "pg_isready -U bodhiorchard"
--health-interval 5s
--health-timeout 5s
--health-retries 12
env:
DATABASE_URL: postgresql+asyncpg://bodhiorchard:bodhiorchard@localhost:5432/bodhiorchard_migrations
SECRET_KEY: ci-secret-not-for-prod
ENCRYPTION_KEY: ci-encryption-key-not-for-prod
steps:
- uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.12"
cache: "pip"
cache-dependency-path: backend/pyproject.toml
- name: Install backend (with dev extras)
run: |
python -m pip install --upgrade pip
pip install -e ".[dev]"
- name: Apply existing migrations
run: alembic upgrade head
- name: Detect un-migrated model changes
run: |
set -euo pipefail
# Autogenerate a candidate revision; if alembic finds any
# divergence between models and the post-`upgrade head` DB
# state, the revision file will be non-empty.
alembic revision --autogenerate -m "ci_drift_check" --rev-id ci_drift_check
drift_file=$(ls alembic/versions/ci_drift_check_*.py 2>/dev/null | head -n 1 || true)
if [ -z "$drift_file" ]; then
echo "alembic produced no revision file — assuming no drift."
exit 0
fi
if grep -E "op\.(add_column|drop_column|create_table|drop_table|alter_column|create_index|drop_index|create_foreign_key|drop_constraint)" "$drift_file"; then
echo "::error::Model changes detected without a matching migration."
echo "Run \`alembic revision --autogenerate -m '<message>'\` locally, review, and commit."
cat "$drift_file"
exit 1
fi
echo "Generated revision had no schema ops — no drift."