-
-
Notifications
You must be signed in to change notification settings - Fork 0
451 lines (372 loc) · 12.8 KB
/
test.yml
File metadata and controls
451 lines (372 loc) · 12.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
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
441
442
443
444
445
446
447
448
449
450
451
name: Test Suite
on:
pull_request:
branches: [ main, develop ]
push:
branches: [ main, develop ]
workflow_dispatch:
jobs:
validate-compose:
name: Validate Docker Compose
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Validate docker-compose.yml
run: |
docker compose config > /dev/null
echo "✓ docker-compose.yml is valid"
- name: Check for docker-compose syntax issues
run: |
docker compose config --quiet
echo "✓ No syntax errors found"
validate-env:
name: Validate Environment Configuration
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Validate .env.example exists
run: |
if [ ! -f .env.example ]; then
echo "✗ .env.example not found"
exit 1
fi
echo "✓ .env.example exists"
- name: Check .env.example format
run: |
# Check for basic environment variable format
if ! grep -qE '^[A-Z_]+=.*$' .env.example; then
echo "✗ .env.example has invalid format"
exit 1
fi
echo "✓ .env.example format is valid"
- name: Check for required variables
run: |
required_vars=(
"VAULT_ADDR"
"VAULT_TOKEN"
"POSTGRES_USER"
"POSTGRES_DB"
"POSTGRES_PASSWORD"
"MYSQL_USER"
"MYSQL_DATABASE"
"RABBITMQ_VHOST"
"MONGODB_USER"
"MONGODB_DATABASE"
)
missing=0
for var in "${required_vars[@]}"; do
if ! grep -q "^${var}=" .env.example; then
echo "✗ Missing required variable: $var"
missing=1
fi
done
if [ $missing -eq 1 ]; then
exit 1
fi
echo "✓ All required variables present (Vault-managed credentials)"
validate-scripts:
name: Validate Shell Scripts
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Check script executability
run: |
scripts=(
"manage-colima.sh"
"configs/vault/scripts/vault-init.sh"
"configs/vault/scripts/vault-bootstrap.sh"
)
for script in "${scripts[@]}"; do
if [ -f "$script" ] && [ ! -x "$script" ]; then
echo "✗ Script not executable: $script"
exit 1
fi
done
echo "✓ All scripts are executable"
- name: Check for bash shebangs
run: |
scripts=$(find . -name "*.sh" -type f)
for script in $scripts; do
shebang=$(head -n 1 "$script")
if [[ ! "$shebang" =~ ^#!/bin/bash$ ]] && \
[[ ! "$shebang" =~ ^#!/usr/bin/env\ bash$ ]] && \
[[ ! "$shebang" =~ ^#!/bin/sh$ ]]; then
echo "✗ Missing or incorrect shebang in: $script"
echo " Found: $shebang"
echo " Expected: #!/bin/bash, #!/usr/bin/env bash, or #!/bin/sh"
exit 1
fi
done
echo "✓ All scripts have proper shebangs"
validate-configs:
name: Validate Configuration Files
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Validate JSON files
run: |
json_files=$(find configs -name "*.json" -type f 2>/dev/null || true)
if [ -n "$json_files" ]; then
for file in $json_files; do
if ! python3 -m json.tool "$file" > /dev/null 2>&1; then
echo "✗ Invalid JSON in: $file"
exit 1
fi
done
echo "✓ All JSON files are valid"
else
echo "ℹ No JSON files to validate"
fi
- name: Validate YAML files
run: |
yaml_files=$(find configs -name "*.yml" -o -name "*.yaml" -type f 2>/dev/null || true)
if [ -n "$yaml_files" ]; then
pip install pyyaml
for file in $yaml_files; do
if ! python3 -c "import yaml; yaml.safe_load(open('$file'))" 2>/dev/null; then
echo "✗ Invalid YAML in: $file"
exit 1
fi
done
echo "✓ All YAML files are valid"
else
echo "ℹ No YAML files to validate"
fi
test-documentation:
name: Test Documentation
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Check README exists and is not empty
run: |
if [ ! -f README.md ]; then
echo "✗ README.md not found"
exit 1
fi
if [ ! -s README.md ]; then
echo "✗ README.md is empty"
exit 1
fi
echo "✓ README.md exists and has content"
- name: Check for broken markdown links
uses: gaurav-nelson/github-action-markdown-link-check@v1
with:
use-quiet-mode: 'yes'
config-file: '.github/workflows/markdown-link-check-config.json'
continue-on-error: true
- name: Validate required documentation sections
run: |
required_sections=(
"Quick Start"
"Installation"
"Prerequisites"
"Services"
"Troubleshooting"
)
for section in "${required_sections[@]}"; do
if ! grep -qi "## $section" README.md; then
echo "⚠ Missing recommended section: $section"
fi
done
echo "✓ Documentation validation complete"
test-python:
name: Test Python Scripts
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.11'
- name: Check Python syntax
run: |
python_files=$(find scripts tests -name "*.py" -type f 2>/dev/null || true)
if [ -n "$python_files" ]; then
for file in $python_files; do
if ! python3 -m py_compile "$file"; then
echo "✗ Syntax error in: $file"
exit 1
fi
done
echo "✓ All Python files have valid syntax"
else
echo "ℹ No Python files to validate"
fi
unit-tests:
name: Unit Tests
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.11'
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version-file: 'reference-apps/golang/go.mod'
- name: Set up Rust
uses: dtolnay/rust-toolchain@stable
- name: Install Python test dependencies
run: |
pip install pytest pytest-asyncio pytest-cov pytest-mock httpx
- name: Run FastAPI unit tests
run: |
cd reference-apps/fastapi
pip install -r requirements.txt
# Run tests that don't require external services
pytest tests/ -v --ignore=tests/test_integration.py -k "not integration" \
--tb=short || echo "⚠ Some tests require running services (expected in CI)"
continue-on-error: true
- name: Run Go unit tests
run: |
cd reference-apps/golang
go test -v -short ./... 2>&1 || echo "⚠ Some tests require running services (expected in CI)"
continue-on-error: true
- name: Run Rust unit tests
run: |
cd reference-apps/rust
cargo test --lib -- --test-threads=1 2>&1 || echo "⚠ Some tests require running services (expected in CI)"
continue-on-error: true
- name: Test summary
run: |
echo "=========================================="
echo "Unit Test Summary"
echo "=========================================="
echo ""
echo "Note: Full test coverage requires running infrastructure services."
echo "Unit tests that don't require external dependencies were executed."
echo ""
echo "For full integration tests, run locally with:"
echo " ./devstack start --profile standard"
echo " ./tests/run-all-tests.sh"
integration-test:
name: Integration Test (Basic)
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Create .env from example
run: cp .env.example .env
- name: Validate Docker Compose can parse files
run: |
docker compose config > /dev/null
echo "✓ Docker Compose configuration is valid"
- name: Check service definitions (no profile)
run: |
services=$(docker compose config --services)
echo "Services with no profile: $services"
# Vault should always be available (no profile)
if ! echo "$services" | grep -q "^vault$"; then
echo "✗ Missing vault (should have no profile)"
exit 1
fi
echo "✓ Vault is defined (no profile required)"
- name: Check minimal profile services
run: |
services=$(docker compose --profile minimal config --services)
expected_services=(
"vault"
"postgres"
"pgbouncer"
"redis-1"
"forgejo"
)
echo "Minimal profile services:"
echo "$services"
for service in "${expected_services[@]}"; do
if ! echo "$services" | grep -q "^${service}$"; then
echo "✗ Missing expected service in minimal profile: $service"
exit 1
fi
done
echo "✓ All minimal profile services are defined"
- name: Check standard profile services
run: |
services=$(docker compose --profile standard config --services)
expected_services=(
"vault"
"postgres"
"pgbouncer"
"mysql"
"mongodb"
"redis-1"
"redis-2"
"redis-3"
"rabbitmq"
"forgejo"
)
echo "Standard profile services:"
echo "$services"
for service in "${expected_services[@]}"; do
if ! echo "$services" | grep -q "^${service}$"; then
echo "✗ Missing expected service in standard profile: $service"
exit 1
fi
done
echo "✓ All standard profile services are defined"
test-summary:
name: Test Summary
runs-on: ubuntu-latest
needs:
- validate-compose
- validate-env
- validate-scripts
- validate-configs
- test-documentation
- test-python
- unit-tests
- integration-test
if: always()
steps:
- name: Check test results
run: |
failed=0
if [ "${{ needs.validate-compose.result }}" != "success" ]; then
echo "❌ Docker Compose validation failed"
failed=1
fi
if [ "${{ needs.validate-env.result }}" != "success" ]; then
echo "❌ Environment validation failed"
failed=1
fi
if [ "${{ needs.validate-scripts.result }}" != "success" ]; then
echo "❌ Script validation failed"
failed=1
fi
if [ "${{ needs.validate-configs.result }}" != "success" ]; then
echo "❌ Config validation failed"
failed=1
fi
if [ "${{ needs.test-documentation.result }}" != "success" ]; then
echo "❌ Documentation tests failed"
failed=1
fi
if [ "${{ needs.test-python.result }}" != "success" ]; then
echo "❌ Python syntax check failed"
failed=1
fi
if [ "${{ needs.integration-test.result }}" != "success" ]; then
echo "❌ Integration tests failed"
failed=1
fi
# Unit tests are informational (some require services)
if [ "${{ needs.unit-tests.result }}" == "failure" ]; then
echo "⚠ Unit tests had failures (some may require running services)"
fi
if [ $failed -eq 1 ]; then
exit 1
fi
echo "✅ All validation tests passed!"
echo ""
echo "Note: Unit tests for reference apps may have partial failures"
echo "when external services are not available. This is expected in CI."