-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.gitlab-ci.yml
More file actions
209 lines (194 loc) · 5.01 KB
/
.gitlab-ci.yml
File metadata and controls
209 lines (194 loc) · 5.01 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
# GitLab CI/CD with AIOps Integration
variables:
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
cache:
paths:
- .cache/pip
- venv/
stages:
- setup
- analysis
- test
- review
- deploy
# Setup stage
install_aiops:
stage: setup
image: python:3.10
script:
- python -m venv venv
- source venv/bin/activate
- pip install --upgrade pip
- pip install -e .
artifacts:
paths:
- venv/
expire_in: 1 hour
# AI Code Review
ai_code_review:
stage: review
image: python:3.10
dependencies:
- install_aiops
script:
- source venv/bin/activate
- |
# Review changed files
git diff --name-only $CI_MERGE_REQUEST_DIFF_BASE_SHA...$CI_COMMIT_SHA | grep '\.py$' > changed_files.txt || echo "No Python files"
if [ -s changed_files.txt ]; then
while IFS= read -r file; do
echo "Reviewing $file..."
aiops review "$file" --language python > "${file}.review.txt" || true
done < changed_files.txt
# Combine reviews
cat *.review.txt > code_review_report.txt 2>/dev/null || echo "No reviews generated"
fi
artifacts:
reports:
codequality: code_review_report.txt
paths:
- "*.review.txt"
expire_in: 30 days
only:
- merge_requests
# Security Scanning
ai_security_scan:
stage: analysis
image: python:3.10
dependencies:
- install_aiops
script:
- source venv/bin/activate
- echo "Running AI security scan..."
- |
# Scan Python files for security issues
find . -name "*.py" -not -path "./venv/*" | while read file; do
aiops security-scan "$file" --output "$file.security.json" || true
done
artifacts:
reports:
sast: "**/*.security.json"
expire_in: 30 days
allow_failure: true
# Run Tests with Coverage
test:
stage: test
image: python:3.10
dependencies:
- install_aiops
script:
- source venv/bin/activate
- pip install -r requirements.txt
- pip install -r requirements-dev.txt
- pytest aiops/tests/ --cov=aiops --cov-fail-under=70 --cov-report=xml --cov-report=term-missing -v
coverage: '/TOTAL.*\s+(\d+%)$/'
artifacts:
reports:
coverage_report:
coverage_format: cobertura
path: coverage.xml
paths:
- coverage.xml
expire_in: 30 days
# Test Generation
ai_test_generation:
stage: test
image: python:3.10
dependencies:
- install_aiops
script:
- source venv/bin/activate
- |
# Generate tests for new files without tests
find . -name "*.py" -not -path "./venv/*" -not -path "./tests/*" | while read file; do
test_file="tests/test_$(basename $file)"
if [ ! -f "$test_file" ]; then
echo "Generating tests for $file..."
aiops generate-tests "$file" --output "$test_file" || true
fi
done
artifacts:
paths:
- tests/
expire_in: 7 days
when: manual
# Log Analysis (for failed pipelines)
ai_log_analysis:
stage: analysis
image: python:3.10
dependencies:
- install_aiops
script:
- source venv/bin/activate
- |
# Analyze previous pipeline logs if this is a retry
if [ -n "$CI_PIPELINE_ID" ]; then
echo "Analyzing pipeline logs..."
# In a real scenario, fetch logs from previous pipeline
aiops analyze-logs ci_pipeline.log > log_analysis.md || echo "No logs to analyze"
fi
artifacts:
paths:
- log_analysis.md
expire_in: 7 days
when: on_failure
# Performance Analysis
ai_performance_check:
stage: analysis
image: python:3.10
dependencies:
- install_aiops
script:
- source venv/bin/activate
- |
# Analyze performance-critical files
find . -name "*.py" -not -path "./venv/*" | while read file; do
if grep -q "performance\|optimization\|cache" "$file"; then
echo "Analyzing performance of $file..."
aiops analyze-performance "$file" > "$file.perf.txt" || true
fi
done
artifacts:
paths:
- "**/*.perf.txt"
expire_in: 30 days
allow_failure: true
# Pipeline Optimization (weekly)
optimize_pipeline:
stage: analysis
image: python:3.10
dependencies:
- install_aiops
script:
- source venv/bin/activate
- |
echo "Analyzing CI/CD pipeline for optimization..."
aiops optimize-pipeline .gitlab-ci.yml > pipeline_optimization.md
artifacts:
paths:
- pipeline_optimization.md
expire_in: 30 days
only:
- schedules
when: manual
# Code Quality Analysis
ai_quality_check:
stage: analysis
image: python:3.10
dependencies:
- install_aiops
script:
- source venv/bin/activate
- |
# Quality check for main source files
find ./aiops -name "*.py" | while read file; do
echo "Quality check: $file..."
aiops quality-check "$file" > "$file.quality.json" || true
done
# Generate summary report
cat **/*.quality.json > quality_report.json 2>/dev/null || echo "{}" > quality_report.json
artifacts:
reports:
metrics: quality_report.json
expire_in: 30 days
allow_failure: true