-
Notifications
You must be signed in to change notification settings - Fork 1
311 lines (262 loc) · 8.73 KB
/
Copy pathci.yaml
File metadata and controls
311 lines (262 loc) · 8.73 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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
# =============================================================================
# CI/CD Pipeline
# =============================================================================
# Constitution: Reliability & Quality
# Runs on every push and PR:
# lint → [unit | integration | e2e] (parallel) → coverage + security
#
# Quality Gates:
# - All tests must pass
# - Coverage must not regress
# - Type checking must pass
# - Linting must pass
name: CI
on:
push:
branches: [main, develop]
pull_request:
branches: [main, develop]
env:
PYTHON_VERSION: "3.11"
UV_CACHE_DIR: /tmp/.uv-cache
jobs:
# ===========================================================================
# Lint & Type Check (Fast Feedback)
# ===========================================================================
lint:
name: Lint & Type Check
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
enable-cache: true
cache-dependency-glob: "uv.lock"
- name: Restore uv cache
uses: actions/cache@v4
with:
path: /tmp/.uv-cache
key: uv-${{ runner.os }}-${{ hashFiles('uv.lock') }}
restore-keys: |
uv-${{ runner.os }}-
- name: Install dependencies
run: uv sync --frozen --dev
- name: Run ruff (lint)
run: uv run ruff check src/ tests/
- name: Run ruff (format check)
run: uv run ruff format --check src/ tests/
- name: Run mypy
run: uv run mypy src/
- name: Minimize uv cache
run: uv cache prune --ci
# ===========================================================================
# Unit Tests (Fast, Isolated) — runs in parallel with integration-tests
# ===========================================================================
unit-tests:
name: Unit Tests
runs-on: ubuntu-latest
needs: lint
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
enable-cache: true
cache-dependency-glob: "uv.lock"
- name: Install dependencies
run: uv sync --frozen --dev
- name: Run unit tests
run: |
uv run pytest tests/unit \
-v \
--tb=short \
-m "unit or not (integration or e2e)" \
--cov=src \
--cov-report=xml:coverage-unit.xml \
--cov-report=term-missing
mv .coverage .coverage.unit
- name: Upload coverage
uses: actions/upload-artifact@v4
with:
name: coverage-unit
include-hidden-files: true
path: |
coverage-unit.xml
.coverage.unit
# ===========================================================================
# Integration Tests (Require Services) — runs in parallel with unit-tests
# ===========================================================================
integration-tests:
name: Integration Tests
runs-on: ubuntu-latest
needs: lint
services:
postgres:
image: postgres:16-alpine
env:
POSTGRES_USER: test
POSTGRES_PASSWORD: test
POSTGRES_DB: aether_test
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
enable-cache: true
cache-dependency-glob: "uv.lock"
- name: Install dependencies
run: uv sync --frozen --dev
- name: Run integration tests
env:
DATABASE_URL: postgresql+asyncpg://test:test@localhost:5432/aether_test
OPENAI_API_KEY: test-key
HA_URL: http://localhost:8123
HA_TOKEN: test-token
run: |
uv run pytest tests/integration \
-v \
--tb=short \
-m "integration" \
--cov=src \
--cov-report=xml:coverage-integration.xml \
--cov-fail-under=0
mv .coverage .coverage.integration
- name: Upload coverage
uses: actions/upload-artifact@v4
with:
name: coverage-integration
include-hidden-files: true
path: |
coverage-integration.xml
.coverage.integration
# ===========================================================================
# E2E Tests (Full System) — runs in parallel with unit & integration
# ===========================================================================
e2e-tests:
name: E2E Tests
runs-on: ubuntu-latest
needs: lint
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
enable-cache: true
cache-dependency-glob: "uv.lock"
- name: Install dependencies
run: uv sync --frozen --dev
- name: Start test services
run: |
docker compose -f infrastructure/test/docker-compose.test.yaml up -d
# Wait for services
sleep 10
- name: Run E2E tests
env:
DATABASE_URL: postgresql+asyncpg://test:test@localhost:5433/aether_test
OPENAI_API_KEY: test-key
HA_URL: http://localhost:8124
HA_TOKEN: test-token
MLFLOW_TRACKING_URI: http://localhost:5001
run: |
uv run pytest tests/e2e \
-v \
--tb=short \
-m "e2e" \
--cov=src \
--cov-report=xml:coverage-e2e.xml \
--cov-fail-under=0
mv .coverage .coverage.e2e || true
- name: Stop test services
if: always()
run: docker compose -f infrastructure/test/docker-compose.test.yaml down -v
- name: Upload coverage
if: always()
uses: actions/upload-artifact@v4
with:
name: coverage-e2e
include-hidden-files: true
path: |
coverage-e2e.xml
.coverage.e2e
# ===========================================================================
# Coverage Report
# ===========================================================================
coverage:
name: Coverage Report
runs-on: ubuntu-latest
needs: [unit-tests, integration-tests, e2e-tests]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download coverage artifacts
uses: actions/download-artifact@v4
with:
pattern: coverage-*
merge-multiple: true
- name: Upload to Codecov
uses: codecov/codecov-action@v4
with:
files: coverage-unit.xml,coverage-integration.xml,coverage-e2e.xml
fail_ci_if_error: false
verbose: true
- name: Check coverage threshold
run: |
# Combine binary .coverage files from each test step and enforce threshold
pip install coverage
coverage combine .coverage.unit .coverage.integration .coverage.e2e || coverage combine .coverage.unit .coverage.integration || coverage combine .coverage.unit
coverage report --fail-under=80
# ===========================================================================
# Security Scan
# ===========================================================================
security:
name: Security Scan
runs-on: ubuntu-latest
needs: lint
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
enable-cache: true
cache-dependency-glob: "uv.lock"
- name: Install dependencies
run: uv sync --frozen --dev
- name: Run bandit security scan
run: uv run bandit -r src/ -c pyproject.toml
- name: Check for vulnerabilities in dependencies
run: |
pip install pip-audit
pip-audit --requirement <(uv pip compile pyproject.toml) || true