-
Notifications
You must be signed in to change notification settings - Fork 0
500 lines (442 loc) · 17.1 KB
/
Copy pathci.yml
File metadata and controls
500 lines (442 loc) · 17.1 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
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
---
name: CI/CD Pipeline
on:
push:
branches:
- main
- develop
paths-ignore:
- "**.md"
- "docs/**"
- "LICENSE"
pull_request:
branches:
- main
- develop
paths-ignore:
- "**.md"
- "docs/**"
- "LICENSE"
schedule:
# Run weekly security scans
- cron: "0 2 * * 1"
workflow_dispatch:
env:
ANSIBLE_FORCE_COLOR: "1"
ANSIBLE_VERBOSITY: "1"
PY_COLORS: "1"
PYTHON_VERSIONS: "3.8, 3.9, 3.10, 3.11"
ANSIBLE_VERSIONS: "core 2.12, 2.13, 2.14, 2.15"
UBUNTU_VERSIONS: "20.04, 22.04, 24.04"
jobs:
# Job to determine which files have changed to optimize CI execution
changes:
name: Detect Changes
runs-on: ubuntu-latest
outputs:
any: ${{ steps.changes.outputs.any_changed }}
roles: ${{ steps.changes.outputs.roles_any_changed }}
molecule: ${{ steps.changes.outputs.molecule_any_changed }}
docs: ${{ steps.changes.outputs.docs_any_changed }}
workflow: ${{ steps.changes.outputs.workflow_any_changed }}
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check for Changes
id: changes
uses: dorny/paths-filter@v3
with:
filters: |
roles:
- 'roles/**'
molecule:
- 'molecule/**'
docs:
- '**/*.md'
- 'docs/**'
workflow:
- '.github/workflows/**'
- 'requirements.yml'
- 'ansible.cfg'
- '.ansible-lint'
# Linting job to validate code quality and syntax
lint:
name: Linting
runs-on: ubuntu-latest
needs: changes
if: needs.changes.outputs.any == 'true' || needs.changes.outputs.workflow == 'true'
strategy:
matrix:
python-version: [3.9]
ansible-core-version: ["2.15"]
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Cache Python Dependencies
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('**/requirements.yml') }}
restore-keys: |
${{ runner.os }}-pip-${{ matrix.python-version }}-
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install "ansible-core==${{ matrix.ansible-core-version }}" ansible-lint yamllint
ansible-galaxy collection install -r requirements.yml
- name: Ansible Syntax Check
run: ansible-playbook site.yml --syntax-check
- name: YAML Lint
run: yamllint .
- name: Ansible Lint
run: ansible-lint .
- name: Role Linting
run: |
for role in roles/*/; do
echo "Linting $role"
ansible-lint "$role" || echo "Linting failed for $role"
done
# Security scanning job for vulnerabilities and secrets
security:
name: Security Scanning
runs-on: ubuntu-latest
needs: changes
if: needs.changes.outputs.any == 'true' || needs.changes.outputs.workflow == 'true'
strategy:
matrix:
python-version: [3.9]
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Cache Python Dependencies
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-security-${{ matrix.python-version }}-${{ hashFiles('**/requirements.yml') }}
restore-keys: |
${{ runner.os }}-pip-security-${{ matrix.python-version }}-
- name: Install Security Tools
run: |
python -m pip install --upgrade pip
pip install "ansible-core==2.15" bandit safety
- name: Secret Detection with GitLeaks
uses: gitleaks/gitleaks-action@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Dependency Vulnerability Scanning
run: |
# Check for known vulnerabilities in Python dependencies
safety check || echo "Safety check completed with findings"
- name: Ansible Security Analysis
run: |
# Check for common security issues in Ansible playbooks
ansible-playbook site.yml --check --diff -e "ansible_check_mode=true"
- name: Configuration Security Validation
run: |
# Validate that security configurations are properly set
echo "Checking for security best practices..."
# Add specific security checks here based on project requirements
# Molecule testing job for role-level testing
molecule:
name: Molecule Testing
runs-on: ubuntu-latest
needs: [changes, lint]
if: needs.changes.outputs.roles == 'true' || needs.changes.outputs.molecule == 'true' || needs.changes.outputs.workflow == 'true'
strategy:
matrix:
python-version: [3.8, 3.9, 3.10, 3.11]
ansible-core-version: ["2.12", "2.13", "2.14", "2.15"]
scenario: [default, docker, rust, common]
include:
# Include specific combinations for comprehensive testing
- python-version: 3.11
ansible-core-version: "2.15"
scenario: default
- python-version: 3.8
ansible-core-version: "2.12"
scenario: default
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Cache Python Dependencies
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-molecule-${{ matrix.python-version }}-${{ matrix.ansible-core-version }}-${{ hashFiles('**/requirements.yml') }}
restore-keys: |
${{ runner.os }}-pip-molecule-${{ matrix.python-version }}-${{ matrix.ansible-core-version }}-
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install "ansible-core==${{ matrix.ansible-core-version }}" molecule[docker] pytest
ansible-galaxy collection install -r requirements.yml
- name: Cache Docker Images
uses: actions/cache@v4
with:
path: /tmp/docker-images
key: ${{ runner.os }}-docker-images-${{ matrix.scenario }}
restore-keys: |
${{ runner.os }}-docker-images-
- name: Run Molecule Tests
run: |
cd molecule/${{ matrix.scenario }}
molecule test
env:
PY_COLORS: "1"
ANSIBLE_FORCE_COLOR: "1"
- name: Upload Test Results
uses: actions/upload-artifact@v4
if: always()
with:
name: molecule-test-results-${{ matrix.python-version }}-${{ matrix.ansible-core-version }}-${{ matrix.scenario }}
path: |
reports/
logs/
coverage.xml
if-no-files-found: ignore
# Integration testing job for full playbook testing
integration:
name: Integration Testing
runs-on: ubuntu-latest
needs: [changes, lint]
if: needs.changes.outputs.any == 'true' || needs.changes.outputs.workflow == 'true'
strategy:
matrix:
python-version: [3.9, 3.10, 3.11]
ansible-core-version: ["2.14", "2.15"]
ubuntu-version: ["20.04", "22.04", "24.04"]
include:
# Include specific combinations for comprehensive testing
- python-version: 3.11
ansible-core-version: "2.15"
ubuntu-version: "22.04"
- python-version: 3.9
ansible-core-version: "2.13"
ubuntu-version: "20.04"
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Cache Python Dependencies
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-integration-${{ matrix.python-version }}-${{ matrix.ansible-core-version }}-${{ hashFiles('**/requirements.yml') }}
restore-keys: |
${{ runner.os }}-pip-integration-${{ matrix.python-version }}-${{ matrix.ansible-core-version }}-
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install "ansible-core==${{ matrix.ansible-core-version }}"
ansible-galaxy collection install -r requirements.yml
- name: Create Test Inventory Directory
run: |
mkdir -p inventory/test
cat > inventory/test.ini << EOF
[test]
localhost ansible_connection=local
EOF
- name: Create Test Vault Directory
run: |
mkdir -p group_vars/all
cat > group_vars/all/test-vault.yml << EOF
# Test vault values for CI
tailscale_auth_key: "test-key"
atuin_user: "test-user"
atuin_pass: "test-pass"
atuin_key: "test-key"
EOF
- name: Run Integration Tests
run: |
ansible-playbook -i inventory/test.ini test-docker.yml --check --diff
ansible-playbook -i inventory/test.ini test-rust.yml --check --diff
ansible-playbook -i inventory/test.ini test-atuin.yml --check --diff
- name: Run Full Playbook in Check Mode
run: |
ansible-playbook -i inventory/test.ini site.yml --check --diff
- name: Upload Integration Test Results
uses: actions/upload-artifact@v4
if: always()
with:
name: integration-test-results-${{ matrix.python-version }}-${{ matrix.ansible-core-version }}-ubuntu${{ matrix.ubuntu-version }}
path: |
reports/
logs/
coverage.xml
if-no-files-found: ignore
# Performance testing job for benchmarking critical operations
performance:
name: Performance Testing
runs-on: ubuntu-latest
needs: [changes, lint]
if: needs.changes.outputs.any == 'true' || needs.changes.outputs.workflow == 'true'
strategy:
matrix:
python-version: [3.9, 3.11]
ansible-core-version: ["2.15"]
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Cache Python Dependencies
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-performance-${{ matrix.python-version }}-${{ matrix.ansible-core-version }}-${{ hashFiles('**/requirements.yml') }}
restore-keys: |
${{ runner.os }}-pip-performance-${{ matrix.python-version }}-${{ matrix.ansible-core-version }}-
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install "ansible-core==${{ matrix.ansible-core-version }}"
ansible-galaxy collection install -r requirements.yml
- name: Performance Benchmark
run: |
echo "Running performance tests..."
# Add performance testing commands here
# This could include timing ansible runs, measuring resource usage, etc.
- name: Upload Performance Results
uses: actions/upload-artifact@v4
if: always()
with:
name: performance-results-${{ matrix.python-version }}-${{ matrix.ansible-core-version }}
path: |
performance-reports/
benchmarks/
if-no-files-found: ignore
# Deployment validation job for different environments
deployment:
name: Deployment Validation
runs-on: ubuntu-latest
needs: [changes, lint]
if: needs.changes.outputs.any == 'true' || needs.changes.outputs.workflow == 'true'
strategy:
matrix:
environment: [development, staging, production]
python-version: [3.9, 3.11]
ansible-core-version: ["2.14", "2.15"]
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Cache Python Dependencies
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-deployment-${{ matrix.python-version }}-${{ matrix.ansible-core-version }}-${{ matrix.environment }}-${{ hashFiles('**/requirements.yml') }}
restore-keys: |
${{ runner.os }}-pip-deployment-${{ matrix.python-version }}-${{ matrix.ansible-core-version }}-${{ matrix.environment }}-
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install "ansible-core==${{ matrix.ansible-core-version }}"
ansible-galaxy collection install -r requirements.yml
- name: Validate Environment Configuration
run: |
echo "Validating configuration for ${{ matrix.environment }} environment"
# Add environment-specific validation here
- name: Run Environment-Specific Tests
run: |
echo "Running tests for ${{ matrix.environment }} environment"
# Add environment-specific tests here
# Job to collect and report test results
report:
name: Test Results & Reporting
runs-on: ubuntu-latest
needs: [lint, security, molecule, integration, performance, deployment]
if: always()
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Download All Artifacts
uses: actions/download-artifact@v4
with:
path: artifacts/
- name: Create Test Summary
run: |
echo "## CI/CD Pipeline Results" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Job | Status |" >> $GITHUB_STEP_SUMMARY
echo "|-----|--------|" >> $GITHUB_STEP_SUMMARY
echo "| Linting | ${{ needs.lint.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| Security | ${{ needs.security.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| Molecule | ${{ needs.molecule.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| Integration | ${{ needs.integration.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| Performance | ${{ needs.performance.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| Deployment | ${{ needs.deployment.result }} |" >> $GITHUB_STEP_SUMMARY
- name: Quality Gate Check
run: |
# Check if all required jobs passed
if [[ "${{ needs.lint.result }}" == "success" && "${{ needs.security.result }}" == "success" ]]; then
echo "Quality gates passed"
else
echo "Quality gates failed"
exit 1
fi
- name: Notify on Failure
if: failure()
run: |
echo "Pipeline failed! Notifying team..."
# Add notification logic here (Slack, email, etc.)
- name: Notify on Success
if: success()
run: |
echo "Pipeline succeeded! All tests passed."
# Add success notification logic here if needed
- name: Generate Coverage Report
run: |
echo "Generating coverage report..."
# Add coverage report generation logic here
- name: Comment on Pull Request
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs');
const summary = `## CI/CD Pipeline Results\n\n| Job | Status |\n|-----|--------|\n| Linting | ${{ needs.lint.result }} |\n| Security | ${{ needs.security.result }} |\n| Molecule | ${{ needs.molecule.result }} |\n| Integration | ${{ needs.integration.result }} |\n| Performance | ${{ needs.performance.result }} |\n| Deployment | ${{ needs.deployment.result }} |`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: summary
});
- name: Create Issue on Failure
if: failure() && github.ref == 'refs/heads/main'
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: `CI/CD Pipeline Failure on ${context.ref}`,
body: `The CI/CD pipeline failed on ${context.ref}.\n\nCheck the workflow run: ${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`
});
# Conditional execution based on changed files
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true