-
Notifications
You must be signed in to change notification settings - Fork 0
337 lines (285 loc) · 12.7 KB
/
Copy pathci.yml
File metadata and controls
337 lines (285 loc) · 12.7 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
name: CI
on:
push:
branches: ["**"]
pull_request:
branches: [main]
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true
env:
PYTHON_VERSION: "3.11"
IMAGE_NAME: bessai-edge-gateway
jobs:
# ─────────────────────────────────────────────────────────────────
# Job 1: Lint
# ─────────────────────────────────────────────────────────────────
lint:
name: Lint (ruff)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: pip
- name: Install ruff
run: pip install ruff
- name: Run ruff check
run: ruff check src/ tests/
- name: Run ruff format check
run: ruff format --check src/ tests/
# ─────────────────────────────────────────────────────────────────
# Job 2: Type check
# ─────────────────────────────────────────────────────────────────
typecheck:
name: Type check (mypy)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: pip
- name: Install dependencies
run: pip install -r requirements.txt -r requirements-dev.txt
- name: Run mypy
run: mypy src/ --ignore-missing-imports --no-error-summary
# ─────────────────────────────────────────────────────────────────
# Job 3: Unit tests
# ─────────────────────────────────────────────────────────────────
test:
name: Tests (pytest)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: pip
- name: Install dependencies
run: pip install -r requirements.txt -r requirements-dev.txt
- name: Run tests with coverage
run: |
pytest tests/ -v --tb=short \
--cov=src \
--cov-report=xml \
--cov-report=term-missing \
--cov-fail-under=80
- name: Upload coverage to Codecov
if: always()
uses: codecov/codecov-action@v4
with:
file: coverage.xml
flags: unittests
fail_ci_if_error: false
# ─────────────────────────────────────────────────────────────────
# Job 4: Interoperability Contract Tests (BESSAI-SPEC-001 Category A)
# No hardware needed — uses SimulatorDriver
# ─────────────────────────────────────────────────────────────────
interop:
name: Interop Contract Tests (BESSAI-SPEC-001)
runs-on: ubuntu-latest
needs: [test]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: pip
- name: Install dependencies
run: pip install -r requirements.txt -r requirements-dev.txt
- name: Run BESSAI-SPEC-001 Category A contract tests
env:
SITE_ID: CI-INTEROP-TEST
INVERTER_IP: "127.0.0.1"
run: |
pytest tests/interop/test_driver_contract.py \
-v --tb=short \
-m "not slow" \
--junit-xml=interop-results.xml
- name: Upload interop test results
if: always()
uses: actions/upload-artifact@v6
with:
name: interop-test-results
path: interop-results.xml
# ─────────────────────────────────────────────────────────────────
# Job 5: Security — SAST + Dependency audit
# ─────────────────────────────────────────────────────────────────
security:
name: Security (bandit + pip-audit)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: pip
- name: Install security tools
run: pip install bandit pip-audit
- name: Run bandit SAST
run: |
bandit -r src/ \
--severity-level medium \
--confidence-level medium \
--format json \
--output bandit-report.json || true
bandit -r src/ \
--severity-level medium \
--confidence-level medium \
--exit-zero
- name: Upload bandit report
if: always()
uses: actions/upload-artifact@v6
with:
name: bandit-report
path: bandit-report.json
- name: Run pip-audit (dependency vulnerability scan)
run: |
pip-audit \
--requirement requirements.txt \
--format json \
--output pip-audit-report.json || true
pip-audit \
--requirement requirements.txt \
--ignore-vuln PYSEC-2022-42969
- name: Upload pip-audit report
if: always()
uses: actions/upload-artifact@v6
with:
name: pip-audit-report
path: pip-audit-report.json
# ─────────────────────────────────────────────────────────────────
# Job 5: Terraform validate (no GCP credentials needed)
# ─────────────────────────────────────────────────────────────────
terraform-validate:
name: Terraform validate
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: "~> 1.7"
- name: Terraform init (local backend only)
run: terraform -chdir=infrastructure/terraform init -backend=false
- name: Terraform validate
run: terraform -chdir=infrastructure/terraform validate
- name: Terraform fmt check
run: terraform -chdir=infrastructure/terraform fmt -check -recursive
# ─────────────────────────────────────────────────────────────────
# Job 6: Helm lint & template validation
# ─────────────────────────────────────────────────────────────────
helm-lint:
name: Helm lint & template
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Helm
uses: azure/setup-helm@v4
with:
version: "3.14.0"
- name: Helm lint
run: helm lint infrastructure/helm/bessai-edge/
- name: Helm template dry-run
run: |
helm template bessai-test infrastructure/helm/bessai-edge/ \
--set config.inverterIp=10.0.1.50 \
--set config.siteId=CI-TEST \
| head -60
# ─────────────────────────────────────────────────────────────────
# Job 7: Docker build (validates the image builds correctly)
# ─────────────────────────────────────────────────────────────────
docker-build:
name: Docker build
runs-on: ubuntu-latest
needs: [lint, test]
outputs:
image-digest: ${{ steps.build.outputs.digest }}
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build image (no push)
id: build
uses: docker/build-push-action@v5
with:
context: .
file: infrastructure/docker/Dockerfile
platforms: linux/amd64,linux/arm64
push: false
tags: ${{ env.IMAGE_NAME }}:${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
# ─────────────────────────────────────────────────────────────────
# Job 8: Trivy container security scan
# ─────────────────────────────────────────────────────────────────
trivy:
name: Container scan (Trivy)
runs-on: ubuntu-latest
needs: [docker-build]
permissions:
security-events: write # Required to upload SARIF to GitHub Security tab
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build image for scanning
uses: docker/build-push-action@v5
with:
context: .
file: infrastructure/docker/Dockerfile
platforms: linux/amd64
push: false
load: true
tags: ${{ env.IMAGE_NAME }}:scan
cache-from: type=gha
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
image-ref: "${{ env.IMAGE_NAME }}:scan"
format: "sarif"
output: "trivy-results.sarif"
severity: "CRITICAL,HIGH"
exit-code: "0" # Don't fail CI — upload results for visibility
- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v4
if: always()
with:
sarif_file: "trivy-results.sarif"
category: "trivy-container"
# ─────────────────────────────────────────────────────────────────
# Job 9: Push to GCP Artifact Registry (only on main)
# ─────────────────────────────────────────────────────────────────
docker-push:
name: Push to Artifact Registry
runs-on: ubuntu-latest
needs: [docker-build, security, trivy]
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
permissions:
contents: read
id-token: write # Required for Workload Identity Federation
steps:
- uses: actions/checkout@v4
- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v2
with:
workload_identity_provider: ${{ secrets.GCP_WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ secrets.GCP_SERVICE_ACCOUNT }}
- name: Configure Docker for Artifact Registry
run: gcloud auth configure-docker ${{ secrets.GCP_REGION }}-docker.pkg.dev --quiet
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
file: infrastructure/docker/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: |
${{ secrets.GCP_REGION }}-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/bessai/${{ env.IMAGE_NAME }}:latest
${{ secrets.GCP_REGION }}-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/bessai/${{ env.IMAGE_NAME }}:${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max