-
-
Notifications
You must be signed in to change notification settings - Fork 0
440 lines (388 loc) · 13.9 KB
/
Copy pathci-cd.yml
File metadata and controls
440 lines (388 loc) · 13.9 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
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
# SPDX-License-Identifier: MPL-2.0
name: CI/CD Pipeline
on:
push:
branches: [ main, develop, 'claude/**' ]
pull_request:
branches: [ main, develop ]
schedule:
# Run security scans daily at 2 AM UTC
- cron: '0 2 * * *'
permissions:
contents: read
env:
JULIA_VERSION: '1.12'
RUST_VERSION: 'stable'
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
# Code quality checks
quality:
name: Code Quality
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout code
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
fetch-depth: 0 # Full history for SonarCloud
- name: Set up Julia
uses: julia-actions/setup-julia@fa02766e078afaaf09b14210362cee14137e6a32 # v2.8.0
with:
version: ${{ env.JULIA_VERSION }}
- name: Install dependencies
run: |
cd src/julia/RobotVacuum
julia --project=. -e 'using Pkg; Pkg.instantiate()'
julia --project=. -e 'using Pkg; Pkg.add("JuliaFormatter")'
- name: Run JuliaFormatter (code formatting)
run: |
cd src/julia/RobotVacuum
julia --project=. -e 'using JuliaFormatter; exit(format("src"; overwrite=false) ? 0 : 1)'
continue-on-error: true
# Security scanning
security:
name: Security Scanning
runs-on: ubuntu-latest
permissions:
security-events: write
contents: read
steps:
- name: Checkout code
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- name: Run GitLeaks (secrets detection)
uses: gitleaks/gitleaks-action@e0c47f4f8be36e29cdc102c57e68cb5cbf0e8d1e # v3.0.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITLEAKS_LICENSE: ${{ secrets.GITLEAKS_LICENSE }}
- name: Run Trivy vulnerability scanner (filesystem)
uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # 0.33.0
with:
scan-type: 'fs'
scan-ref: '.'
format: 'sarif'
output: 'trivy-results.sarif'
severity: 'CRITICAL,HIGH'
exit-code: '0'
limit-severities-for-sarif: true
- name: Upload Trivy results to GitHub Security
uses: github/codeql-action/upload-sarif@7188fc363630916deb702c7fdcf4e481b751f97a # v3.28.1
if: always() && hashFiles('trivy-results.sarif') != ''
with:
sarif_file: 'trivy-results.sarif'
category: 'trivy-filesystem'
- name: Run Snyk security scan
uses: snyk/actions/node@8e119fbb6c251787721d34ba683ed48eba792766 # master 2024-12-09
continue-on-error: true
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
with:
args: --severity-threshold=high
- name: OWASP Dependency Check
uses: dependency-check/Dependency-Check_Action@1e54355a8b4c8abaa8cc7d0b70aa655a3bb15a6c # main 2024-12-09
with:
project: 'robot-vacuum-cleaner'
path: '.'
format: 'HTML'
out: 'reports'
continue-on-error: true
- name: Upload dependency check report
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v4.6.0
if: always()
with:
name: dependency-check-report
path: reports/
# Julia tests
test-julia:
name: Julia Tests
runs-on: ubuntu-latest
permissions:
contents: read
strategy:
matrix:
julia-version: ['1.12', 'nightly']
steps:
- name: Checkout code
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- name: Set up Julia ${{ matrix.julia-version }}
uses: julia-actions/setup-julia@fa02766e078afaaf09b14210362cee14137e6a32 # v2.8.0
with:
version: ${{ matrix.julia-version }}
- name: Install dependencies
run: |
cd src/julia/RobotVacuum
julia --project=. -e 'using Pkg; Pkg.instantiate()'
- name: Run tests with coverage
run: |
cd src/julia/RobotVacuum
julia --project=. -e 'using Pkg; Pkg.test(coverage=true)'
- name: Process coverage
uses: julia-actions/julia-processcoverage@03114f09f119417c3242a9fb6e0b722676aedf38 # v1.2.2
with:
directories: src/julia/RobotVacuum/src
- name: Upload coverage to Codecov
uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v5.0.7
with:
files: lcov.info
flags: julia-${{ matrix.julia-version }}
name: julia-${{ matrix.julia-version }}
token: ${{ secrets.CODECOV_TOKEN }}
# Rust tests
test-rust:
name: Rust Tests
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout code
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- name: Install Rust toolchain
uses: actions-rust-lang/setup-rust-toolchain@166cdcfd11aee3cb47222f9ddb555ce30ddb9659 # v1.17.0
with:
toolchain: ${{ env.RUST_VERSION }}
components: rustfmt, clippy
- name: Cargo format check
run: cargo fmt --all -- --check
working-directory: src/rust
continue-on-error: true
- name: Cargo clippy
run: cargo clippy --all-targets --all-features -- -D warnings
working-directory: src/rust
continue-on-error: true
- name: Run Rust tests
run: cargo test --verbose
working-directory: src/rust
- name: Generate coverage
run: |
cargo install cargo-tarpaulin
cargo tarpaulin --out Xml --output-dir coverage
working-directory: src/rust
continue-on-error: true
- name: Upload Rust coverage
uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v5.0.7
with:
file: src/rust/coverage/cobertura.xml
flags: rust
name: rust
token: ${{ secrets.CODECOV_TOKEN }}
continue-on-error: true
# Build and scan container images
container-build:
name: Build & Scan Containers
runs-on: ubuntu-latest
needs: [quality, test-julia]
permissions:
contents: read
packages: write
security-events: write
id-token: write
attestations: write
steps:
- name: Checkout code
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@bb05f3f5519dd87d3ba754cc423b652a5edd6d2c # v4.2.0
- name: Log in to Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@af1e73f918a031802d376d3c8bbc3fe56130a9b0 # v4.4.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@dc802804100637a589fabce1cb79ff13a1411302 # v6.2.0
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha,prefix={{branch}}-
type=raw,value=latest,enable={{is_default_branch}}
- name: Build container image
uses: docker/build-push-action@53b7df96c91f9c12dcc8a07bcb9ccacbed38856a # v7.3.0
with:
context: .
file: ./docker/Containerfile
push: false
load: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Run Trivy vulnerability scanner (image)
uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # 0.33.0
with:
image-ref: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }}
format: 'sarif'
output: 'trivy-image-results.sarif'
severity: 'CRITICAL,HIGH'
exit-code: '0'
limit-severities-for-sarif: true
- name: Upload Trivy image results
uses: github/codeql-action/upload-sarif@7188fc363630916deb702c7fdcf4e481b751f97a # v3.28.1
if: always() && hashFiles('trivy-image-results.sarif') != ''
with:
sarif_file: 'trivy-image-results.sarif'
category: 'trivy-container'
- name: Run Hadolint (Dockerfile linting)
uses: hadolint/hadolint-action@2332a7b74a6de0dda2e2221d575162eba76ba5e5 # v3.3.0
with:
dockerfile: docker/Containerfile
failure-threshold: warning
- name: Scan with Grype
uses: anchore/scan-action@e1165082ffb1fe366ebaf02d8526e7c4989ea9d2 # v5.0.0
with:
image: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }}
fail-build: false
severity-cutoff: high
- name: Push container image
id: push
if: github.event_name != 'pull_request'
uses: docker/build-push-action@53b7df96c91f9c12dcc8a07bcb9ccacbed38856a # v7.3.0
with:
context: .
file: ./docker/Containerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Attest container provenance
if: github.event_name != 'pull_request'
uses: actions/attest-build-provenance@0f67c3f4856b2e3261c31976d6725780e5e4c373 # v4.1.1
with:
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true
# SonarCloud analysis
sonarcloud:
name: SonarCloud Analysis
runs-on: ubuntu-latest
needs: [test-julia]
permissions:
contents: read
steps:
- name: Checkout code
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
fetch-depth: 0
- name: Download Julia coverage
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: julia-coverage
path: htmlcov/
- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@ffc3010689be73b8e5ae0c57ce35968afd7909e8 # v3.1.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
args: >
-Dsonar.projectKey=robot-vacuum-cleaner
-Dsonar.organization=${{ github.repository_owner }}
-Dsonar.coverage.reportPaths=lcov.info
-Dsonar.sources=src/
-Dsonar.tests=tests/
-Dsonar.exclusions=**/*_test.py,**/test_*.py
# Integration tests
integration:
name: Integration Tests
runs-on: ubuntu-latest
needs: [container-build]
permissions:
contents: read
services:
redis:
image: redis:alpine
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 6379:6379
postgres:
image: postgres:16-alpine
env:
POSTGRES_DB: robot_vacuum_test
POSTGRES_USER: test
POSTGRES_PASSWORD: test
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- name: Checkout code
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- name: Set up Julia
uses: julia-actions/setup-julia@fa02766e078afaaf09b14210362cee14137e6a32 # v2.8.0
with:
version: ${{ env.JULIA_VERSION }}
- name: Install dependencies
run: |
cd src/julia/RobotVacuum
julia --project=. -e 'using Pkg; Pkg.instantiate()'
- name: Run integration tests
env:
REDIS_HOST: localhost
POSTGRES_HOST: localhost
POSTGRES_DB: robot_vacuum_test
POSTGRES_USER: test
POSTGRES_PASSWORD: test
run: |
cd src/julia/RobotVacuum
julia --project=. -e 'using Pkg; Pkg.test()'
# Deployment (only on main branch)
deploy:
name: Deploy
runs-on: ubuntu-latest
needs: [integration, security, sonarcloud]
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
permissions:
contents: read
environment:
name: production
url: https://robot-vacuum.example.com
steps:
- name: Checkout code
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- name: Deploy to production
run: |
echo "Deploying to production environment..."
# Add actual deployment commands here
# e.g., kubectl apply, helm upgrade, etc.
- name: Notify deployment
uses: 8398a7/action-slack@77eaa4f1c608a7d68b38af4e3f739dcd8cba273e # v3.18.3
if: always()
with:
status: ${{ job.status }}
text: 'Deployment to production ${{ job.status }}'
webhook_url: ${{ secrets.SLACK_WEBHOOK }}
continue-on-error: true
# Notification job
notify:
name: Notify
runs-on: ubuntu-latest
needs: [quality, security, test-julia, test-rust, container-build, integration]
if: always()
permissions: {}
steps:
- name: Check job statuses
id: check
run: |
if [ "${{ contains(needs.*.result, 'failure') }}" == "true" ]; then
echo "status=failure" >> $GITHUB_OUTPUT
elif [ "${{ contains(needs.*.result, 'cancelled') }}" == "true" ]; then
echo "status=cancelled" >> $GITHUB_OUTPUT
else
echo "status=success" >> $GITHUB_OUTPUT
fi
- name: Send notification
run: |
echo "Pipeline status: ${{ steps.check.outputs.status }}"
# Add notification logic (Slack, email, etc.)