johnaugustine commited on
Commit
92c5169
Β·
verified Β·
1 Parent(s): 5b392ea

Create .github/workflows/cae-ci-cd.yml

Browse files
Files changed (1) hide show
  1. .github/workflows/cae-ci-cd.yml +454 -0
.github/workflows/cae-ci-cd.yml ADDED
@@ -0,0 +1,454 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # CAE CI/CD Pipeline
2
+ # Continuous Integration and Deployment for Confessional Agency Ecosystem
3
+
4
+ name: CAE CI/CD Pipeline
5
+
6
+ on:
7
+ push:
8
+ branches: [ main, develop, feature/* ]
9
+ pull_request:
10
+ branches: [ main, develop ]
11
+ release:
12
+ types: [ published ]
13
+
14
+ env:
15
+ PYTHON_VERSION: "3.9"
16
+ PYTORCH_VERSION: "2.0.0"
17
+ CUDA_VERSION: "11.7"
18
+ HF_TOKEN: ${{ secrets.HF_TOKEN }}
19
+ DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
20
+ DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
21
+
22
+ jobs:
23
+ # Code Quality and Security Checks
24
+ code-quality:
25
+ name: Code Quality & Security
26
+ runs-on: ubuntu-latest
27
+ steps:
28
+ - name: Checkout code
29
+ uses: actions/checkout@v4
30
+
31
+ - name: Set up Python
32
+ uses: actions/setup-python@v4
33
+ with:
34
+ python-version: ${{ env.PYTHON_VERSION }}
35
+
36
+ - name: Cache pip dependencies
37
+ uses: actions/cache@v3
38
+ with:
39
+ path: ~/.cache/pip
40
+ key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
41
+ restore-keys: |
42
+ ${{ runner.os }}-pip-
43
+
44
+ - name: Install dependencies
45
+ run: |
46
+ python -m pip install --upgrade pip
47
+ pip install black flake8 mypy bandit safety
48
+ pip install -r requirements.txt
49
+
50
+ - name: Code formatting check
51
+ run: |
52
+ black --check --diff unified_cae.py deploy_cae.py community_templates.py
53
+
54
+ - name: Linting
55
+ run: |
56
+ flake8 unified_cae.py deploy_cae.py community_templates.py --max-line-length=100
57
+
58
+ - name: Type checking
59
+ run: |
60
+ mypy unified_cae.py --ignore-missing-imports
61
+
62
+ - name: Security scanning
63
+ run: |
64
+ bandit -r . -f json -o bandit-report.json
65
+ safety check --json --output safety-report.json
66
+
67
+ - name: Upload security reports
68
+ uses: actions/upload-artifact@v3
69
+ if: always()
70
+ with:
71
+ name: security-reports
72
+ path: |
73
+ bandit-report.json
74
+ safety-report.json
75
+
76
+ # Unit Tests
77
+ unit-tests:
78
+ name: Unit Tests
79
+ runs-on: ubuntu-latest
80
+ strategy:
81
+ matrix:
82
+ python-version: ["3.8", "3.9", "3.10", "3.11"]
83
+ steps:
84
+ - name: Checkout code
85
+ uses: actions/checkout@v4
86
+
87
+ - name: Set up Python ${{ matrix.python-version }}
88
+ uses: actions/setup-python@v4
89
+ with:
90
+ python-version: ${{ matrix.python-version }}
91
+
92
+ - name: Cache pip dependencies
93
+ uses: actions/cache@v3
94
+ with:
95
+ path: ~/.cache/pip
96
+ key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('**/requirements.txt') }}
97
+ restore-keys: |
98
+ ${{ runner.os }}-pip-${{ matrix.python-version }}-
99
+
100
+ - name: Install dependencies
101
+ run: |
102
+ python -m pip install --upgrade pip
103
+ pip install pytest pytest-cov pytest-mock
104
+ pip install -r requirements.txt
105
+
106
+ - name: Run unit tests
107
+ run: |
108
+ pytest tests/ -v --cov=cae --cov-report=xml --cov-report=html
109
+
110
+ - name: Upload coverage reports
111
+ uses: actions/upload-artifact@v3
112
+ if: always()
113
+ with:
114
+ name: coverage-reports-${{ matrix.python-version }}
115
+ path: |
116
+ coverage.xml
117
+ htmlcov/
118
+
119
+ # Integration Tests
120
+ integration-tests:
121
+ name: Integration Tests
122
+ runs-on: ubuntu-latest
123
+ needs: [code-quality, unit-tests]
124
+ steps:
125
+ - name: Checkout code
126
+ uses: actions/checkout@v4
127
+
128
+ - name: Set up Python
129
+ uses: actions/setup-python@v4
130
+ with:
131
+ python-version: ${{ env.PYTHON_VERSION }}
132
+
133
+ - name: Cache pip dependencies
134
+ uses: actions/cache@v3
135
+ with:
136
+ path: ~/.cache/pip
137
+ key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
138
+
139
+ - name: Install dependencies
140
+ run: |
141
+ python -m pip install --upgrade pip
142
+ pip install -r requirements.txt
143
+
144
+ - name: Run integration tests
145
+ run: |
146
+ python -m pytest tests/integration/ -v --tb=short
147
+
148
+ - name: Test CAE initialization
149
+ run: |
150
+ python -c "
151
+ from unified_cae import ConfessionalAgencyEcosystem
152
+ cae = ConfessionalAgencyEcosystem()
153
+ print('βœ“ CAE initialization successful')
154
+ "
155
+
156
+ # Performance Benchmarks
157
+ performance-benchmarks:
158
+ name: Performance Benchmarks
159
+ runs-on: ubuntu-latest
160
+ needs: [unit-tests]
161
+ steps:
162
+ - name: Checkout code
163
+ uses: actions/checkout@v4
164
+
165
+ - name: Set up Python
166
+ uses: actions/setup-python@v4
167
+ with:
168
+ python-version: ${{ env.PYTHON_VERSION }}
169
+
170
+ - name: Install dependencies
171
+ run: |
172
+ python -m pip install --upgrade pip
173
+ pip install -r requirements.txt
174
+
175
+ - name: Run performance benchmarks
176
+ run: |
177
+ python benchmarks/run_performance_tests.py
178
+
179
+ - name: Upload benchmark results
180
+ uses: actions/upload-artifact@v3
181
+ with:
182
+ name: benchmark-results
183
+ path: benchmarks/results/
184
+
185
+ # Ethical Audit
186
+ ethical-audit:
187
+ name: Ethical Audit
188
+ runs-on: ubuntu-latest
189
+ needs: [integration-tests]
190
+ steps:
191
+ - name: Checkout code
192
+ uses: actions/checkout@v4
193
+
194
+ - name: Set up Python
195
+ uses: actions/setup-python@v4
196
+ with:
197
+ python-version: ${{ env.PYTHON_VERSION }}
198
+
199
+ - name: Install dependencies
200
+ run: |
201
+ python -m pip install --upgrade pip
202
+ pip install -r requirements.txt
203
+
204
+ - name: Run ethical audit
205
+ run: |
206
+ python ethical_audit/run_audit.py --output-format json
207
+
208
+ - name: Upload ethical audit results
209
+ uses: actions/upload-artifact@v3
210
+ with:
211
+ name: ethical-audit-results
212
+ path: ethical_audit/reports/
213
+
214
+ # Security Audit
215
+ security-audit:
216
+ name: Security Audit
217
+ runs-on: ubuntu-latest
218
+ needs: [code-quality]
219
+ steps:
220
+ - name: Checkout code
221
+ uses: actions/checkout@v4
222
+
223
+ - name: Run Trivy vulnerability scanner
224
+ uses: aquasecurity/trivy-action@master
225
+ with:
226
+ scan-type: 'fs'
227
+ scan-ref: '.'
228
+ format: 'sarif'
229
+ output: 'trivy-results.sarif'
230
+
231
+ - name: Upload Trivy scan results
232
+ uses: github/codeql-action/upload-sarif@v2
233
+ with:
234
+ sarif_file: 'trivy-results.sarif'
235
+
236
+ # Build Docker Image
237
+ build-docker:
238
+ name: Build Docker Image
239
+ runs-on: ubuntu-latest
240
+ needs: [integration-tests, security-audit]
241
+ steps:
242
+ - name: Checkout code
243
+ uses: actions/checkout@v4
244
+
245
+ - name: Set up Docker Buildx
246
+ uses: docker/setup-buildx-action@v3
247
+
248
+ - name: Login to Docker Hub
249
+ uses: docker/login-action@v3
250
+ with:
251
+ username: ${{ env.DOCKER_USERNAME }}
252
+ password: ${{ env.DOCKER_PASSWORD }}
253
+
254
+ - name: Extract metadata
255
+ id: meta
256
+ uses: docker/metadata-action@v5
257
+ with:
258
+ images: cae/framework
259
+ tags: |
260
+ type=ref,event=branch
261
+ type=ref,event=pr
262
+ type=semver,pattern={{version}}
263
+ type=semver,pattern={{major}}.{{minor}}
264
+ type=raw,value=latest,enable={{is_default_branch}}
265
+
266
+ - name: Build and push
267
+ uses: docker/build-push-action@v5
268
+ with:
269
+ context: .
270
+ push: true
271
+ tags: ${{ steps.meta.outputs.tags }}
272
+ labels: ${{ steps.meta.outputs.labels }}
273
+ cache-from: type=gha
274
+ cache-to: type=gha,mode=max
275
+
276
+ # Deploy to HuggingFace Hub
277
+ deploy-hf-hub:
278
+ name: Deploy to HuggingFace Hub
279
+ runs-on: ubuntu-latest
280
+ needs: [integration-tests, performance-benchmarks]
281
+ if: github.ref == 'refs/heads/main'
282
+ steps:
283
+ - name: Checkout code
284
+ uses: actions/checkout@v4
285
+
286
+ - name: Set up Python
287
+ uses: actions/setup-python@v4
288
+ with:
289
+ python-version: ${{ env.PYTHON_VERSION }}
290
+
291
+ - name: Install dependencies
292
+ run: |
293
+ python -m pip install --upgrade pip
294
+ pip install -r requirements.txt
295
+
296
+ - name: Deploy to HuggingFace Hub
297
+ env:
298
+ HF_TOKEN: ${{ secrets.HF_TOKEN }}
299
+ run: |
300
+ python deploy_cae.py --deploy-hub --model-name cae-base
301
+
302
+ # Deploy Demo to HuggingFace Spaces
303
+ deploy-hf-spaces:
304
+ name: Deploy to HuggingFace Spaces
305
+ runs-on: ubuntu-latest
306
+ needs: [integration-tests, ethical-audit]
307
+ if: github.ref == 'refs/heads/main'
308
+ steps:
309
+ - name: Checkout code
310
+ uses: actions/checkout@v4
311
+
312
+ - name: Deploy to Spaces
313
+ uses: huggingface/hub-spaces-deploy-action@v1
314
+ with:
315
+ github-token: ${{ secrets.GITHUB_TOKEN }}
316
+ space-organization: augstentatious
317
+ space-name: cae-demo
318
+
319
+ # Deploy to TestPyPI
320
+ deploy-testpypi:
321
+ name: Deploy to TestPyPI
322
+ runs-on: ubuntu-latest
323
+ needs: [unit-tests, integration-tests]
324
+ if: github.event_name == 'push' && github.ref == 'refs/heads/develop'
325
+ steps:
326
+ - name: Checkout code
327
+ uses: actions/checkout@v4
328
+
329
+ - name: Set up Python
330
+ uses: actions/setup-python@v4
331
+ with:
332
+ python-version: ${{ env.PYTHON_VERSION }}
333
+
334
+ - name: Install build dependencies
335
+ run: |
336
+ python -m pip install --upgrade pip
337
+ pip install build twine
338
+
339
+ - name: Build package
340
+ run: |
341
+ python -m build
342
+
343
+ - name: Publish to TestPyPI
344
+ uses: pypa/gh-action-pypi-publish@release/v1
345
+ with:
346
+ repository-url: https://test.pypi.org/legacy/
347
+ password: ${{ secrets.TEST_PYPI_API_TOKEN }}
348
+
349
+ # Deploy to PyPI
350
+ deploy-pypi:
351
+ name: Deploy to PyPI
352
+ runs-on: ubuntu-latest
353
+ needs: [unit-tests, integration-tests, performance-benchmarks, ethical-audit]
354
+ if: github.event_name == 'release'
355
+ steps:
356
+ - name: Checkout code
357
+ uses: actions/checkout@v4
358
+
359
+ - name: Set up Python
360
+ uses: actions/setup-python@v4
361
+ with:
362
+ python-version: ${{ env.PYTHON_VERSION }}
363
+
364
+ - name: Install build dependencies
365
+ run: |
366
+ python -m pip install --upgrade pip
367
+ pip install build twine
368
+
369
+ - name: Build package
370
+ run: |
371
+ python -m build
372
+
373
+ - name: Publish to PyPI
374
+ uses: pypa/gh-action-pypi-publish@release/v1
375
+ with:
376
+ password: ${{ secrets.PYPI_API_TOKEN }}
377
+
378
+ # Notification
379
+ notify:
380
+ name: Notification
381
+ runs-on: ubuntu-latest
382
+ needs: [build-docker, deploy-hf-hub, deploy-hf-spaces]
383
+ if: always()
384
+ steps:
385
+ - name: Notify on success
386
+ if: needs.build-docker.result == 'success' && needs.deploy-hf-hub.result == 'success'
387
+ run: |
388
+ echo "πŸŽ‰ CAE deployment successful!"
389
+ echo "πŸ“¦ Docker image: cae/framework:latest"
390
+ echo "πŸ€— HuggingFace Hub: augstentatious/cae-base"
391
+ echo "πŸš€ HuggingFace Spaces: augstentatious/cae-demo"
392
+
393
+ - name: Notify on failure
394
+ if: failure()
395
+ run: |
396
+ echo "❌ CAE deployment failed"
397
+ echo "Please check the logs for details"
398
+
399
+ # Additional workflow for community templates
400
+ community-templates:
401
+ name: Community Templates Validation
402
+ runs-on: ubuntu-latest
403
+ if: github.event_name == 'pull_request' && contains(github.event.pull_request.files.*.filename, 'community_templates/')
404
+ steps:
405
+ - name: Checkout code
406
+ uses: actions/checkout@v4
407
+
408
+ - name: Set up Python
409
+ uses: actions/setup-python@v4
410
+ with:
411
+ python-version: ${{ env.PYTHON_VERSION }}
412
+
413
+ - name: Install dependencies
414
+ run: |
415
+ python -m pip install --upgrade pip
416
+ pip install -r requirements.txt
417
+
418
+ - name: Validate community templates
419
+ run: |
420
+ python scripts/validate_community_templates.py
421
+
422
+ - name: Check template quality
423
+ run: |
424
+ python scripts/check_template_quality.py
425
+
426
+ # Workflow for documentation updates
427
+ documentation:
428
+ name: Documentation
429
+ runs-on: ubuntu-latest
430
+ if: github.event_name == 'push' && (contains(github.event.head_commit.message, 'docs:') || contains(github.event.head_commit.message, 'Documentation:'))
431
+ steps:
432
+ - name: Checkout code
433
+ uses: actions/checkout@v4
434
+
435
+ - name: Set up Python
436
+ uses: actions/setup-python@v4
437
+ with:
438
+ python-version: ${{ env.PYTHON_VERSION }}
439
+
440
+ - name: Install documentation dependencies
441
+ run: |
442
+ python -m pip install --upgrade pip
443
+ pip install sphinx sphinx-rtd-theme nbsphinx
444
+
445
+ - name: Build documentation
446
+ run: |
447
+ cd docs
448
+ make html
449
+
450
+ - name: Deploy documentation
451
+ uses: peaceiris/actions-gh-pages@v3
452
+ with:
453
+ github_token: ${{ secrets.GITHUB_TOKEN }}
454
+ publish_dir: ./docs/_build/html