forked from johanzander/bess-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
389 lines (345 loc) · 15.8 KB
/
Copy pathci.yml
File metadata and controls
389 lines (345 loc) · 15.8 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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
name: CI
on:
pull_request:
push:
branches: [main]
jobs:
# ── Detect which areas changed ──────────────────────────────────
changes:
name: Detect changes
runs-on: ubuntu-latest
outputs:
backend: ${{ steps.filter.outputs.backend }}
frontend: ${{ steps.filter.outputs.frontend }}
algorithm: ${{ steps.algorithm.outputs.changed }}
e2e: ${{ steps.filter.outputs.e2e }}
steps:
- uses: actions/checkout@v5
with:
fetch-depth: 0
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
backend:
- 'backend/**'
- 'core/bess/**'
- 'pyproject.toml'
- 'requirements-dev.txt'
frontend:
- 'frontend/**'
e2e:
- 'backend/**'
- 'core/bess/**'
- 'frontend/**'
- 'e2e/**'
- 'scripts/mock_ha/**'
- 'docker-compose.ci.yml'
- 'docker-compose.prod-test.yml'
- 'Dockerfile'
# Algorithm filter uses a script instead of dorny because dorny's
# negation patterns don't work correctly with the default 'some'
# quantifier — any unrelated file matches '!core/bess/excluded.py',
# so algorithm always triggers. This script checks whether any
# core/bess/ file changed that is NOT in the I/O-only exclusion list.
- name: Check algorithm-relevant changes
id: algorithm
run: |
# I/O-only files excluded from algorithm tests (fully mocked in slow suite)
EXCLUDED=(
core/bess/ha_api_controller.py
core/bess/sensor_collector.py
core/bess/weather.py
core/bess/octopus_energy_source.py
core/bess/official_nordpool_source.py
core/bess/debug_data_exporter.py
core/bess/debug_report_formatter.py
core/bess/health_check.py
core/bess/influxdb_helper.py
core/bess/prediction_analyzer.py
)
if [ "${{ github.event_name }}" = "pull_request" ]; then
BASE="${{ github.event.pull_request.base.sha }}"
HEAD="${{ github.event.pull_request.head.sha }}"
else
BASE="${{ github.event.before }}"
HEAD="${{ github.sha }}"
fi
CHANGED="false"
for file in $(git diff --name-only "$BASE" "$HEAD" -- 'core/bess/'); do
SKIP="false"
for ex in "${EXCLUDED[@]}"; do
if [ "$file" = "$ex" ]; then
SKIP="true"
break
fi
done
if [ "$SKIP" = "false" ]; then
echo "Algorithm-relevant change: $file"
CHANGED="true"
fi
done
echo "changed=$CHANGED" >> "$GITHUB_OUTPUT"
echo "Algorithm tests needed: $CHANGED"
# ── Fast tests: backend API + non-optimizer unit tests ──────────
test-fast:
name: Fast tests
needs: changes
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
if: needs.changes.outputs.backend == 'true'
- uses: actions/setup-python@v5
if: needs.changes.outputs.backend == 'true'
with:
python-version: "3.13"
cache: pip
- name: Install dependencies
if: needs.changes.outputs.backend == 'true'
run: |
pip install -r backend/requirements.txt
pip install -r requirements-dev.txt
- name: Run fast tests
if: needs.changes.outputs.backend == 'true'
run: pytest -m "not slow" --tb=short -q
- name: No backend changes
if: needs.changes.outputs.backend != 'true'
run: echo "No backend changes — skipping"
# ── Slow tests: full optimizer / scenario / integration ─────────
test-algorithm:
name: Algorithm tests
needs: changes
if: needs.changes.outputs.algorithm == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: actions/setup-python@v5
with:
python-version: "3.13"
cache: pip
- name: Install dependencies
run: |
pip install -r backend/requirements.txt
pip install -r requirements-dev.txt
- name: Run algorithm tests
run: pytest -m slow --tb=short -q
# ── Frontend: type-check + lint ─────────────────────────────────
test-frontend:
name: Frontend checks
needs: changes
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
if: needs.changes.outputs.frontend == 'true'
- uses: actions/setup-node@v4
if: needs.changes.outputs.frontend == 'true'
with:
node-version: "20"
cache: npm
cache-dependency-path: frontend/package-lock.json
- name: Install and test
if: needs.changes.outputs.frontend == 'true'
run: cd frontend && npm ci && npm test && npm run type-check && npm run lint
- name: No frontend changes
if: needs.changes.outputs.frontend != 'true'
run: echo "No frontend changes — skipping"
# ── E2E: Playwright against docker-compose mock HA ───────────────
e2e:
name: E2E tests
needs: changes
runs-on: ubuntu-latest
env:
RUN_E2E: ${{ needs.changes.outputs.e2e }}
steps:
- name: No E2E changes
if: env.RUN_E2E != 'true'
run: echo "No E2E-relevant changes — skipping"
- uses: actions/checkout@v5
if: env.RUN_E2E == 'true'
- uses: actions/setup-node@v4
if: env.RUN_E2E == 'true'
with:
node-version: "20"
cache: npm
cache-dependency-path: frontend/package-lock.json
- name: Build frontend
if: env.RUN_E2E == 'true'
run: cd frontend && npm ci && npm run build
- name: Install Playwright
if: env.RUN_E2E == 'true'
run: cd e2e && npm ci && npx playwright install chromium --with-deps
# Phase 1: Smoke / navigation / dashboard tests (pre-configured system)
- name: "E2E: Start environment (normal day)"
if: env.RUN_E2E == 'true'
run: |
SCENARIO=ci-normal-day docker compose -f docker-compose.ci.yml up -d
timeout 120 bash -c 'until curl -sf http://localhost:8080/api/settings > /dev/null 2>&1; do sleep 2; done'
- name: "E2E: Run smoke & navigation tests"
if: env.RUN_E2E == 'true'
run: cd e2e && npx playwright test --project=chromium
- name: "E2E: Stop environment"
if: always() && env.RUN_E2E == 'true'
run: docker compose -f docker-compose.ci.yml down
# Phase 2: Setup wizard tests (all scenario combinations)
# Each step resets bess_settings.json to empty so the wizard triggers fresh.
- name: "E2E: Wizard — Nordpool + MIN"
if: env.RUN_E2E == 'true'
run: |
echo '{}' > ./e2e/ci-wizard-settings.json
SCENARIO=ci-wizard-nordpool-min BESS_SETTINGS=./e2e/ci-wizard-settings.json BESS_OPTIONS=./e2e/ci-wizard-options.json docker compose -f docker-compose.ci.yml up -d
timeout 120 bash -c 'until curl -sf http://localhost:8080/api/setup/status > /dev/null 2>&1; do sleep 2; done'
cd e2e && SCENARIO=ci-wizard-nordpool-min npx playwright test --project=wizard
- name: "E2E: Stop wizard (Nordpool + MIN)"
if: always() && env.RUN_E2E == 'true'
run: docker compose -f docker-compose.ci.yml down
- name: "E2E: Wizard — Nordpool + SPH"
if: always() && env.RUN_E2E == 'true'
run: |
echo '{}' > ./e2e/ci-wizard-settings.json
SCENARIO=ci-wizard-nordpool-sph BESS_SETTINGS=./e2e/ci-wizard-settings.json BESS_OPTIONS=./e2e/ci-wizard-options.json docker compose -f docker-compose.ci.yml up -d
timeout 120 bash -c 'until curl -sf http://localhost:8080/api/setup/status > /dev/null 2>&1; do sleep 2; done'
cd e2e && SCENARIO=ci-wizard-nordpool-sph npx playwright test --project=wizard
- name: "E2E: Stop wizard (Nordpool + SPH)"
if: always() && env.RUN_E2E == 'true'
run: docker compose -f docker-compose.ci.yml down
- name: "E2E: Wizard — Nordpool + SolaX"
if: always() && env.RUN_E2E == 'true'
run: |
echo '{}' > ./e2e/ci-wizard-settings.json
SCENARIO=ci-wizard-nordpool-solax BESS_SETTINGS=./e2e/ci-wizard-settings.json BESS_OPTIONS=./e2e/ci-wizard-options.json docker compose -f docker-compose.ci.yml up -d
timeout 120 bash -c 'until curl -sf http://localhost:8080/api/setup/status > /dev/null 2>&1; do sleep 2; done'
cd e2e && SCENARIO=ci-wizard-nordpool-solax npx playwright test --project=wizard
- name: "E2E: Stop wizard (Nordpool + SolaX)"
if: always() && env.RUN_E2E == 'true'
run: docker compose -f docker-compose.ci.yml down
- name: "E2E: Wizard — Octopus + MIN"
if: always() && env.RUN_E2E == 'true'
run: |
echo '{}' > ./e2e/ci-wizard-settings.json
SCENARIO=ci-wizard-octopus BESS_SETTINGS=./e2e/ci-wizard-settings.json BESS_OPTIONS=./e2e/ci-wizard-options.json docker compose -f docker-compose.ci.yml up -d
timeout 120 bash -c 'until curl -sf http://localhost:8080/api/setup/status > /dev/null 2>&1; do sleep 2; done'
cd e2e && SCENARIO=ci-wizard-octopus npx playwright test --project=wizard
- name: "E2E: Stop wizard (Octopus + MIN)"
if: always() && env.RUN_E2E == 'true'
run: docker compose -f docker-compose.ci.yml down
- name: "E2E: Wizard — Full integrations"
if: always() && env.RUN_E2E == 'true'
run: |
echo '{}' > ./e2e/ci-wizard-settings.json
SCENARIO=ci-wizard-full BESS_SETTINGS=./e2e/ci-wizard-settings.json BESS_OPTIONS=./e2e/ci-wizard-options.json docker compose -f docker-compose.ci.yml up -d
timeout 120 bash -c 'until curl -sf http://localhost:8080/api/setup/status > /dev/null 2>&1; do sleep 2; done'
cd e2e && SCENARIO=ci-wizard-full npx playwright test --project=wizard
- name: "E2E: Stop wizard (Full)"
if: always() && env.RUN_E2E == 'true'
run: docker compose -f docker-compose.ci.yml down
- name: "E2E: Wizard — Nordpool HACS"
if: always() && env.RUN_E2E == 'true'
run: |
echo '{}' > ./e2e/ci-wizard-settings.json
SCENARIO=ci-wizard-nordpool-hacs BESS_SETTINGS=./e2e/ci-wizard-settings.json BESS_OPTIONS=./e2e/ci-wizard-options.json docker compose -f docker-compose.ci.yml up -d
timeout 120 bash -c 'until curl -sf http://localhost:8080/api/setup/status > /dev/null 2>&1; do sleep 2; done'
cd e2e && SCENARIO=ci-wizard-nordpool-hacs npx playwright test --project=wizard
- name: "E2E: Stop wizard (Nordpool HACS)"
if: always() && env.RUN_E2E == 'true'
run: docker compose -f docker-compose.ci.yml down
- name: "E2E: Wizard — Octopus + SPH"
if: always() && env.RUN_E2E == 'true'
run: |
echo '{}' > ./e2e/ci-wizard-settings.json
SCENARIO=ci-wizard-octopus-sph BESS_SETTINGS=./e2e/ci-wizard-settings.json BESS_OPTIONS=./e2e/ci-wizard-options.json docker compose -f docker-compose.ci.yml up -d
timeout 120 bash -c 'until curl -sf http://localhost:8080/api/setup/status > /dev/null 2>&1; do sleep 2; done'
cd e2e && SCENARIO=ci-wizard-octopus-sph npx playwright test --project=wizard
- name: "E2E: Stop wizard (Octopus + SPH)"
if: always() && env.RUN_E2E == 'true'
run: docker compose -f docker-compose.ci.yml down
- name: "E2E: Wizard — Both providers"
if: always() && env.RUN_E2E == 'true'
run: |
echo '{}' > ./e2e/ci-wizard-settings.json
SCENARIO=ci-wizard-both-providers BESS_SETTINGS=./e2e/ci-wizard-settings.json BESS_OPTIONS=./e2e/ci-wizard-options.json docker compose -f docker-compose.ci.yml up -d
timeout 120 bash -c 'until curl -sf http://localhost:8080/api/setup/status > /dev/null 2>&1; do sleep 2; done'
cd e2e && SCENARIO=ci-wizard-both-providers npx playwright test --project=wizard
- name: "E2E: Stop wizard (Both providers)"
if: always() && env.RUN_E2E == 'true'
run: docker compose -f docker-compose.ci.yml down
- uses: actions/upload-artifact@v4
if: failure() && env.RUN_E2E == 'true'
with:
name: playwright-report
path: e2e/playwright-report/
# ── Quality gate: linting + formatting ──────────────────────────
quality:
name: Code quality
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: actions/setup-python@v5
with:
python-version: "3.13"
cache: pip
- name: Install tools
run: pip install black ruff
- name: Black formatting
run: black --check . --exclude="/(build|\.venv|node_modules)/"
- name: Ruff linting
run: ruff check . --exclude="build,.venv,node_modules"
# ── Docker build & boot: verify production image starts ──────────
docker-build-test:
name: Docker build & boot
needs: changes
if: needs.changes.outputs.e2e == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: Build production image
run: docker compose -f docker-compose.prod-test.yml build
- name: Start and verify process runs
run: |
BESS_PORT=8080 docker compose -f docker-compose.prod-test.yml up -d
sleep 10
# Verify the bess container is still running (not crashed from ImportError etc.)
STATUS=$(docker compose -f docker-compose.prod-test.yml ps bess --format '{{.State}}')
echo "Container state: $STATUS"
if [ "$STATUS" != "running" ]; then
echo "FAIL: bess container is not running (state: $STATUS)"
docker compose -f docker-compose.prod-test.yml logs bess
exit 1
fi
# Verify app logged successful initialization (not just an import crash)
docker compose -f docker-compose.prod-test.yml logs bess 2>&1 | grep -q "BESS Controller initialized"
echo "Production image boots correctly — no missing imports or COPY entries."
- name: Dump logs on failure
if: failure()
run: docker compose -f docker-compose.prod-test.yml logs
- name: Stop environment
if: always()
run: docker compose -f docker-compose.prod-test.yml down
# ── Merge gate: single required check for branch protection ──────
# Branch protection cannot require the conditional jobs (test-algorithm,
# docker-build-test) by name: when their path filter skips them, the
# required status never reports and the PR is blocked forever. Instead
# this gate always runs, depends on every job, and fails only if one
# genuinely failed or was cancelled (skipped is allowed). Require ONLY
# "Merge gate" in branch protection — it transitively enforces the rest,
# including the slow Algorithm job whenever core/bess/ actually changed.
ci-gate:
name: Merge gate
if: always()
needs:
- changes
- test-fast
- test-algorithm
- test-frontend
- e2e
- quality
- docker-build-test
runs-on: ubuntu-latest
steps:
- name: Fail if any required job failed or was cancelled
if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')
run: |
echo "A required CI job failed or was cancelled — blocking merge."
echo "Job results: ${{ join(needs.*.result, ', ') }}"
exit 1
- name: Gate passed
run: echo "All required CI jobs passed (skipped jobs allowed)."