Repository navigation
348 lines (294 loc) · 9.31 KB
/
Copy pathci.yml
File metadata and controls
348 lines (294 loc) · 9.31 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
name: CI/CD Pipeline
on:
push:
branches: [ main, develop ]
tags:
- 'v*'
pull_request:
branches: [ main, develop ]
schedule:
# Run weekly on Monday at 00:00 UTC
- cron: '0 0 * * 1'
env:
PYTHON_DEFAULT_VERSION: '3.11'
jobs:
# Job 1: Code Quality Checks
code-quality:
name: Code Quality
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_DEFAULT_VERSION }}
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install black flake8 isort mypy pylint bandit safety
- name: Check code formatting with Black
run: |
echo "::group::Black Format Check"
black --check snapflow tests
echo "::endgroup::"
- name: Check import sorting with isort
run: |
echo "::group::isort Import Check"
isort --check-only --profile black snapflow tests
echo "::endgroup::"
- name: Lint with flake8
run: |
echo "::group::Flake8 Linting"
flake8 snapflow tests --max-line-length=100 --extend-ignore=E203,W503 --statistics
echo "::endgroup::"
- name: Type check with mypy
run: |
echo "::group::MyPy Type Checking"
mypy snapflow --ignore-missing-imports --no-strict-optional
echo "::endgroup::"
continue-on-error: true
- name: Lint with pylint
run: |
echo "::group::Pylint Analysis"
pylint snapflow --max-line-length=100 --disable=C0111,C0103,R0903 || true
echo "::endgroup::"
continue-on-error: true
- name: Security check with Bandit
run: |
echo "::group::Bandit Security Scan"
bandit -r snapflow -f json -o bandit-report.json || true
bandit -r snapflow
echo "::endgroup::"
continue-on-error: true
- name: Check dependencies for vulnerabilities
run: |
echo "::group::Safety Dependency Check"
safety check --json || true
echo "::endgroup::"
continue-on-error: true
# Job 2: Unit Tests
test:
name: Test on ${{ matrix.os }} - Python ${{ matrix.python-version }}
runs-on: ${{ matrix.os }}
needs: code-quality
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
exclude:
# Exclude some combinations to reduce CI time
- os: macos-latest
python-version: '3.8'
- os: macos-latest
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 }}
cache: 'pip'
- name: Display Python and pip info
run: |
python --version
python -m pip --version
python -m pip list
shell: bash
- name: Install dependencies
run: |
echo "Installing pip..."
python -m pip install --upgrade pip || exit 1
echo "Installing requirements-dev.txt..."
python -m pip install -r requirements-dev.txt || exit 1
echo "Installing package in editable mode..."
python -m pip install -e . || exit 1
echo "Installation complete!"
shell: bash
- name: Install database drivers (Unix)
if: runner.os != 'Windows'
run: |
echo "Installing database drivers for Unix..."
python -m pip install psycopg2-binary>=2.9.0 PyMySQL>=1.0.0
shell: bash
- name: Install database drivers (Windows)
if: runner.os == 'Windows'
run: |
echo "Installing database drivers for Windows..."
python -m pip install PyMySQL>=1.0.0
echo "Skipping psycopg2-binary on Windows (not needed for tests)"
shell: bash
- name: Verify pytest installation
run: |
echo "Verifying pytest installation..."
python -m pip show pytest
python -c "import pytest; print(f'pytest version: {pytest.__version__}')"
shell: bash
- name: Run tests with pytest
run: |
python -m pytest -v --cov=snapflow --cov-report=xml --cov-report=term-missing --cov-report=html
shell: bash
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.11'
with:
file: ./coverage.xml
flags: unittests
name: snapflow-${{ matrix.os }}-${{ matrix.python-version }}
fail_ci_if_error: false
- name: Upload test results
uses: actions/upload-artifact@v4
if: always()
with:
name: test-results-${{ matrix.os }}-${{ matrix.python-version }}
path: |
htmlcov/
coverage.xml
retention-days: 30
# Job 3: Build Package
build:
name: Build Distribution
runs-on: ubuntu-latest
needs: test
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_DEFAULT_VERSION }}
cache: 'pip'
- name: Install build dependencies
run: |
python -m pip install --upgrade pip
pip install build twine wheel
- name: Build package
run: |
python -m build
- name: Check package with twine
run: |
twine check dist/*
- name: Upload distribution artifacts
uses: actions/upload-artifact@v4
with:
name: python-packages
path: dist/
retention-days: 30
# Job 4: Documentation Check
docs:
name: Documentation
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_DEFAULT_VERSION }}
- name: Check README renders properly
run: |
pip install 'readme-renderer[md]'
python -m readme_renderer README.md > /dev/null
continue-on-error: true
- name: Check links in documentation
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
# Job 5: Security Audit
security:
name: Security Audit
runs-on: ubuntu-latest
needs: code-quality
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'
continue-on-error: true
- name: Upload Trivy results to GitHub Security
uses: github/codeql-action/upload-sarif@v3
if: always()
with:
sarif_file: 'trivy-results.sarif'
continue-on-error: true
# Job 6: Release (only on tags)
release:
name: Release to PyPI
runs-on: ubuntu-latest
needs: [test, build]
if: startsWith(github.ref, 'refs/tags/v')
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_DEFAULT_VERSION }}
- name: Download distribution artifacts
uses: actions/download-artifact@v4
with:
name: python-packages
path: dist/
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
skip-existing: true
continue-on-error: true
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
files: dist/*
generate_release_notes: true
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Job 7: Performance Benchmarking
benchmark:
name: Performance Benchmark
runs-on: ubuntu-latest
needs: test
if: github.event_name == 'pull_request'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_DEFAULT_VERSION }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e .
pip install pytest-benchmark
- name: Run benchmark tests
run: |
echo "Benchmark tests would run here"
echo "python -m pytest tests/benchmark/ --benchmark-only"
continue-on-error: true
# Job 8: Notification
notify:
name: Notify Build Status
runs-on: ubuntu-latest
needs: [code-quality, test, build, docs, security]
if: always()
steps:
- name: Check build status
run: |
echo "Build completed!"
echo "Code Quality: ${{ needs.code-quality.result }}"
echo "Tests: ${{ needs.test.result }}"
echo "Build: ${{ needs.build.result }}"
echo "Docs: ${{ needs.docs.result }}"
echo "Security: ${{ needs.security.result }}"