-
Notifications
You must be signed in to change notification settings - Fork 0
329 lines (273 loc) · 8.73 KB
/
ci.yml
File metadata and controls
329 lines (273 loc) · 8.73 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
# CI/CD 파이프라인 - 지속적 통합
name: CI Pipeline
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]
env:
PYTHON_VERSION: '3.11'
NODE_VERSION: '18'
jobs:
# 코드 품질 검사
code-quality:
name: Code Quality Check
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Cache pip dependencies
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install black flake8 mypy bandit safety
- name: Code formatting check (Black)
run: black --check --diff .
- name: Linting (Flake8)
run: flake8 app tests --max-line-length=88 --extend-ignore=E203,W503
- name: Type checking (MyPy)
run: mypy app --ignore-missing-imports
- name: Security check (Bandit)
run: bandit -r app -f json -o bandit-report.json
- name: Dependency vulnerability check (Safety)
run: safety check --json --output safety-report.json
- name: Upload security reports
uses: actions/upload-artifact@v3
if: always()
with:
name: security-reports
path: |
bandit-report.json
safety-report.json
# 단위 테스트
unit-tests:
name: Unit Tests
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.9', '3.10', '3.11']
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Cache pip dependencies
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-${{ matrix.python-version }}-
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run unit tests
run: |
pytest tests/unit/ -v \
--cov=app \
--cov-report=xml \
--cov-report=html \
--cov-fail-under=90 \
--junitxml=junit-results.xml
- name: Upload test results
uses: actions/upload-artifact@v3
if: always()
with:
name: test-results-${{ matrix.python-version }}
path: |
junit-results.xml
htmlcov/
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
if: matrix.python-version == '3.11'
with:
file: ./coverage.xml
flags: unittests
name: codecov-umbrella
# 통합 테스트
integration-tests:
name: Integration Tests
runs-on: ubuntu-latest
services:
postgres:
image: postgres:15
env:
POSTGRES_PASSWORD: testpass
POSTGRES_USER: testuser
POSTGRES_DB: testdb
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
redis:
image: redis:7
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 6379:6379
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y postgresql-client
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run database migrations
env:
DATABASE_URL: postgresql://testuser:testpass@localhost:5432/testdb
run: |
alembic upgrade head
- name: Run integration tests
env:
DATABASE_URL: postgresql://testuser:testpass@localhost:5432/testdb
REDIS_URL: redis://localhost:6379/0
TESTING: true
run: |
pytest tests/integration/ -v \
--junitxml=integration-results.xml
- name: Upload integration test results
uses: actions/upload-artifact@v3
if: always()
with:
name: integration-test-results
path: integration-results.xml
# Docker 이미지 빌드 테스트
docker-build:
name: Docker Build Test
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build production image
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
push: false
tags: backup-manager:test
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Build development image
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile.dev
push: false
tags: backup-manager:dev-test
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Test Docker Compose
run: |
docker-compose -f docker-compose.yml config
docker-compose -f docker-compose.dev.yml config
# 성능 테스트 (선택적)
performance-tests:
name: Performance Tests
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run performance tests
run: |
pytest tests/performance/ -v -m performance \
--junitxml=performance-results.xml
- name: Upload performance test results
uses: actions/upload-artifact@v3
if: always()
with:
name: performance-test-results
path: performance-results.xml
# 보안 스캔
security-scan:
name: Security Scan
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
scan-type: 'fs'
scan-ref: '.'
format: 'sarif'
output: 'trivy-results.sarif'
- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v2
if: always()
with:
sarif_file: 'trivy-results.sarif'
# 결과 요약
test-summary:
name: Test Summary
runs-on: ubuntu-latest
needs: [code-quality, unit-tests, integration-tests, docker-build]
if: always()
steps:
- name: Download all artifacts
uses: actions/download-artifact@v3
- name: Generate test summary
run: |
echo "## 🧪 Test Results Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [ "${{ needs.code-quality.result }}" == "success" ]; then
echo "✅ Code Quality: PASSED" >> $GITHUB_STEP_SUMMARY
else
echo "❌ Code Quality: FAILED" >> $GITHUB_STEP_SUMMARY
fi
if [ "${{ needs.unit-tests.result }}" == "success" ]; then
echo "✅ Unit Tests: PASSED" >> $GITHUB_STEP_SUMMARY
else
echo "❌ Unit Tests: FAILED" >> $GITHUB_STEP_SUMMARY
fi
if [ "${{ needs.integration-tests.result }}" == "success" ]; then
echo "✅ Integration Tests: PASSED" >> $GITHUB_STEP_SUMMARY
else
echo "❌ Integration Tests: FAILED" >> $GITHUB_STEP_SUMMARY
fi
if [ "${{ needs.docker-build.result }}" == "success" ]; then
echo "✅ Docker Build: PASSED" >> $GITHUB_STEP_SUMMARY
else
echo "❌ Docker Build: FAILED" >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
echo "📊 **Coverage Report**: Available in artifacts" >> $GITHUB_STEP_SUMMARY
echo "🔒 **Security Report**: Available in Security tab" >> $GITHUB_STEP_SUMMARY