-
-
Notifications
You must be signed in to change notification settings - Fork 3
369 lines (307 loc) · 11.6 KB
/
ci.yml
File metadata and controls
369 lines (307 loc) · 11.6 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
# AutoBot CI/CD Pipeline
# Uses self-hosted runner to avoid GitHub Actions quota limits
name: AutoBot CI/CD Pipeline
on:
push:
branches: [ main, Dev_new_gui ]
pull_request:
branches: [ main ]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
jobs:
security-tests:
runs-on: self-hosted
steps:
- uses: actions/checkout@v6
- name: Install Python 3.12 via deadsnakes PPA
run: |
if ! command -v python3.12 &> /dev/null; then
sudo add-apt-repository -y ppa:deadsnakes/ppa
sudo apt-get update -y
sudo apt-get install -y python3.12 python3.12-venv python3.12-dev
fi
- name: Free disk space and set up venv
run: |
pip cache purge 2>/dev/null || true
rm -rf .venv 2>/dev/null || true
python3.12 -m venv .venv
source .venv/bin/activate
echo "VIRTUAL_ENV=$VIRTUAL_ENV" >> $GITHUB_ENV
echo "$VIRTUAL_ENV/bin" >> $GITHUB_PATH
- name: Install Python dependencies
run: |
source .venv/bin/activate
python -m pip install --upgrade pip setuptools wheel
echo "Installing CI-safe requirements..."
python -m pip install -r requirements-ci.txt --prefer-binary
echo "Installing testing dependencies..."
python -m pip install pytest pytest-asyncio pytest-cov flake8 black isort mypy bandit
- name: Create necessary directories and config files
run: |
mkdir -p data logs static config
touch data/.gitkeep logs/.gitkeep static/.gitkeep
# Create minimal config.yaml for CI testing
cat > config/config.yaml << 'EOF'
# CI Testing Configuration
llm:
orchestrator_llm: "mock"
task_llm: "mock"
ollama:
model: "mock-model"
models: {}
unified:
embedding:
providers:
ollama:
selected_model: "mock-embed"
deployment:
mode: "local"
data:
reliability_stats_file: "data/reliability_stats.json"
diagnostics:
enabled: false
use_llm_for_analysis: false
use_web_search_for_analysis: false
auto_apply_fixes: false
redis:
host: "localhost"
port: 6379
db: 0
EOF
- name: Run code quality checks
run: |
source .venv/bin/activate
echo "Running code quality checks..."
# Code formatting check (matches pre-commit black config)
echo "Checking code formatting with black..."
black --check autobot-backend/ autobot-slm-backend/ autobot_shared/ --line-length=88
# Import sorting check — reads pyproject.toml for profile, src_paths, known_first_party (#2679)
echo "Checking import sorting with isort..."
isort --check-only --settings-path=. autobot-backend/ autobot-slm-backend/ autobot_shared/
# Linting (uses project .flake8 config — same as pre-commit)
echo "Running flake8 linter..."
flake8 --config=.flake8 autobot-backend/ autobot-slm-backend/ autobot_shared/
- name: Run security analysis
run: |
source .venv/bin/activate
echo "🔒 Running security analysis..."
# Security vulnerability scan — fail on medium+ severity/confidence
bandit -r autobot-backend/ autobot-slm-backend/ autobot_shared/ \
--severity-level medium --confidence-level medium \
-f json -o bandit-report.json
if [ -f bandit-report.json ]; then
echo "Security report generated"
python -m json.tool < bandit-report.json || true
fi
- name: Run unit tests with coverage gate
run: |
source .venv/bin/activate
echo "Running unit tests with 70% coverage gate (#3285)..."
# Run all unit tests excluding slow/integration/distributed/performance markers.
# --cov-fail-under=70 enforces the minimum 70% coverage threshold.
python -m pytest \
-m "not integration and not slow and not distributed and not performance" \
--cov=autobot-backend \
--cov=autobot-slm-backend \
--cov=autobot_shared \
--cov-report=xml:coverage.xml \
--cov-report=term-missing \
--cov-fail-under=70 \
--tb=short \
-q
- name: Run integration tests
run: |
source .venv/bin/activate
echo "🔄 Running integration tests..."
# Integration tests remain in shared directory (#734)
TEST_DIR="infrastructure/shared/tests/integration"
if [ -d "$TEST_DIR" ]; then
python -m pytest "$TEST_DIR" -v --tb=short --maxfail=5
else
echo "⚠️ No integration test directory found - skipping"
fi
- name: Upload coverage reports
uses: codecov/codecov-action@v6
with:
files: ./coverage.xml
flags: unittests
name: codecov-umbrella
fail_ci_if_error: false
- name: Cleanup
if: always()
run: |
rm -rf .venv || true
frontend-tests:
runs-on: self-hosted
steps:
- uses: actions/checkout@v6
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install frontend dependencies
run: |
cd autobot-frontend
npm ci
- name: Run frontend linting
run: |
cd autobot-frontend
npm run lint
- name: Check i18n keys
run: |
cd autobot-frontend
npm run check:i18n
- name: Run frontend type checking
run: |
cd autobot-frontend
npx vue-tsc --noEmit -p tsconfig.app.json
- name: Build frontend
run: |
cd autobot-frontend
npm run build
- name: Run frontend unit tests with coverage gate
run: |
cd autobot-frontend
# test:coverage enforces 70% threshold via vitest.config.ts thresholds (#3285)
npm run test:coverage
- name: Cleanup
if: always()
run: |
rm -rf autobot-frontend/node_modules autobot-frontend/dist || true
deployment-check:
runs-on: self-hosted
needs: [security-tests, frontend-tests]
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/Dev_new_gui'
steps:
- uses: actions/checkout@v6
- name: Install Python 3.12 via deadsnakes PPA
run: |
if ! command -v python3.12 &> /dev/null; then
sudo add-apt-repository -y ppa:deadsnakes/ppa
sudo apt-get update -y
sudo apt-get install -y python3.12 python3.12-venv python3.12-dev
fi
- name: Free disk space and set up venv
run: |
pip cache purge 2>/dev/null || true
rm -rf .venv 2>/dev/null || true
python3.12 -m venv .venv
source .venv/bin/activate
echo "VIRTUAL_ENV=$VIRTUAL_ENV" >> $GITHUB_ENV
echo "$VIRTUAL_ENV/bin" >> $GITHUB_PATH
- name: Install dependencies
run: |
source .venv/bin/activate
python -m pip install --upgrade pip setuptools wheel
python -m pip install -r requirements-ci.txt --prefer-binary
- name: Create necessary directories and config files
run: |
mkdir -p data logs static config
touch data/.gitkeep logs/.gitkeep static/.gitkeep
# Create minimal config.yaml for CI testing
cat > config/config.yaml << 'EOF'
# CI Testing Configuration
llm:
orchestrator_llm: "mock"
task_llm: "mock"
ollama:
model: "mock-model"
models: {}
unified:
embedding:
providers:
ollama:
selected_model: "mock-embed"
deployment:
mode: "local"
data:
reliability_stats_file: "data/reliability_stats.json"
diagnostics:
enabled: false
use_llm_for_analysis: false
use_web_search_for_analysis: false
auto_apply_fixes: false
redis:
host: "localhost"
port: 6379
db: 0
EOF
- name: Test production configuration
run: |
source .venv/bin/activate
echo "🚀 Testing production readiness..."
# Check that all required files exist
echo "Checking required files..."
test -f main.py || (echo "❌ main.py missing" && exit 1)
test -f requirements.txt || (echo "❌ requirements.txt missing" && exit 1)
echo "✅ All required files present"
# Test configuration loading (PYTHONPATH includes backend for imports)
PYTHONPATH="autobot-backend:autobot_shared:$PYTHONPATH" \
python3 -c 'from config import config; print("Configuration system working")'
# Test core imports
PYTHONPATH="autobot-backend:autobot_shared:$PYTHONPATH" \
python3 -c 'from security.enhanced_security_layer import EnhancedSecurityLayer; from security.secure_command_executor import SecureCommandExecutor; from app_factory import create_app; print("Core imports working")'
- name: Generate deployment artifact
run: |
echo "📦 Generating deployment summary..."
echo "# AutoBot Deployment Summary" > DEPLOYMENT_SUMMARY.md
echo "Generated at: $(date -u '+%Y-%m-%d %H:%M:%S UTC')" >> DEPLOYMENT_SUMMARY.md
echo "Commit: $GITHUB_SHA" >> DEPLOYMENT_SUMMARY.md
echo "Branch: $GITHUB_REF_NAME" >> DEPLOYMENT_SUMMARY.md
echo "" >> DEPLOYMENT_SUMMARY.md
echo "## Test Results" >> DEPLOYMENT_SUMMARY.md
echo "- ✅ Security tests passed" >> DEPLOYMENT_SUMMARY.md
echo "- ✅ Integration tests passed" >> DEPLOYMENT_SUMMARY.md
echo "- ✅ Frontend build successful" >> DEPLOYMENT_SUMMARY.md
echo "" >> DEPLOYMENT_SUMMARY.md
echo "## Security Features" >> DEPLOYMENT_SUMMARY.md
echo "- Command execution sandboxing ✅" >> DEPLOYMENT_SUMMARY.md
echo "- Risk assessment system ✅" >> DEPLOYMENT_SUMMARY.md
echo "- Audit logging ✅" >> DEPLOYMENT_SUMMARY.md
echo "- Role-based access control ✅" >> DEPLOYMENT_SUMMARY.md
echo "- API security endpoints ✅" >> DEPLOYMENT_SUMMARY.md
cat DEPLOYMENT_SUMMARY.md
- name: Upload deployment artifact
uses: actions/upload-artifact@v7
with:
name: deployment-summary
path: DEPLOYMENT_SUMMARY.md
- name: Cleanup
if: always()
run: |
rm -rf .venv || true
notify:
runs-on: self-hosted
needs: [security-tests, frontend-tests, deployment-check]
if: always()
steps:
- name: Notify results
run: |
echo "🎯 CI/CD Pipeline Results:"
echo "=========================="
if [ "${{ needs.security-tests.result }}" == "success" ]; then
echo "✅ Security tests: PASSED"
else
echo "❌ Security tests: FAILED"
fi
if [ "${{ needs.frontend-tests.result }}" == "success" ]; then
echo "✅ Frontend tests: PASSED"
else
echo "❌ Frontend tests: FAILED"
fi
if [ "${{ needs.deployment-check.result }}" == "success" ]; then
echo "✅ Deployment check: PASSED"
else
echo "❌ Deployment check: FAILED"
fi
echo ""
if [ "${{ needs.security-tests.result }}" == "success" ] &&
[ "${{ needs.frontend-tests.result }}" == "success" ] &&
[ "${{ needs.deployment-check.result }}" == "success" ]; then
echo "🎉 All checks passed! AutoBot is ready for deployment."
else
echo "⚠️ Some checks failed. Review the logs above."
fi