-
Notifications
You must be signed in to change notification settings - Fork 0
356 lines (310 loc) · 10.9 KB
/
ci-monorepo.yml
File metadata and controls
356 lines (310 loc) · 10.9 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
name: Monorepo CI Base
on:
workflow_call:
inputs:
package:
description: 'Package to test (async-cassandra or async-cassandra-bulk)'
required: true
type: string
run-integration-tests:
description: 'Run integration tests'
required: false
type: boolean
default: false
run-full-suite:
description: 'Run full test suite'
required: false
type: boolean
default: false
env:
PACKAGE_DIR: libs/${{ inputs.package }}
jobs:
lint:
runs-on: ubuntu-latest
name: Lint ${{ inputs.package }}
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install dependencies
run: |
echo "=== DEBUG: Installing dependencies ==="
echo "Package: ${{ inputs.package }}"
echo "Install path: ./libs/${{ inputs.package }}"
echo "Current directory: $(pwd)"
echo "Checking if path exists:"
ls -la ./libs/${{ inputs.package }}/
echo "=== Running pip install ==="
python -m pip install --upgrade pip
pip install -e "./libs/${{ inputs.package }}[dev]"
- name: Run linting checks
working-directory: libs/${{ inputs.package }}
run: |
echo "=== Running ruff ==="
ruff check src/ tests/
echo "=== Running black ==="
black --check src/ tests/
echo "=== Running isort ==="
isort --check-only src/ tests/
echo "=== Running mypy ==="
mypy src/
security:
runs-on: ubuntu-latest
needs: lint
name: Security ${{ inputs.package }}
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install security tools
run: |
python -m pip install --upgrade pip
pip install bandit[toml] safety pip-audit
- name: Run Bandit security scan
working-directory: libs/${{ inputs.package }}
run: |
echo "=== Running Bandit security scan ==="
# Run bandit with config file and capture exit code
bandit -c ../../.bandit -r src/ -f json -o bandit-report.json || BANDIT_EXIT=$?
# Show the detailed issues found
echo "=== Bandit Detailed Results ==="
bandit -c ../../.bandit -r src/ -v || true
# For low severity issues, we'll just warn but not fail
if [ "${BANDIT_EXIT:-0}" -eq 1 ]; then
echo "⚠️ Bandit found low-severity issues (see above)"
# Check if there are medium or high severity issues
if bandit -c ../../.bandit -r src/ -lll &>/dev/null; then
echo "✅ No medium or high severity issues found - continuing"
exit 0
else
echo "❌ Medium or high severity issues found - failing"
exit 1
fi
fi
exit ${BANDIT_EXIT:-0}
- name: Check dependencies with Safety
run: |
echo "=== Checking dependencies with Safety ==="
pip install -e "./libs/${{ inputs.package }}[dev,test]"
# Using the new 'scan' command as 'check' is deprecated
safety scan --json || SAFETY_EXIT=$?
# Safety scan exits with 64 if vulnerabilities found
if [ "${SAFETY_EXIT:-0}" -eq 64 ]; then
echo "❌ Vulnerabilities found in dependencies"
exit 1
fi
- name: Run pip-audit
run: |
cd libs/${{ inputs.package }}
echo "=== Running pip-audit ==="
# Skip the local package as it's not on PyPI yet
pip-audit --skip-editable
- name: Upload security reports
uses: actions/upload-artifact@v4
if: always()
with:
name: security-reports-${{ inputs.package }}
path: |
${{ env.PACKAGE_DIR }}/bandit-report.json
unit-tests:
runs-on: ubuntu-latest
needs: lint
name: Unit Tests ${{ inputs.package }}
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e "./libs/${{ inputs.package }}[test]"
- name: Run unit tests with coverage
run: |
cd libs/${{ inputs.package }}
pytest tests/unit/ -v --cov=${{ inputs.package == 'async-cassandra' && 'async_cassandra' || 'async_cassandra_bulk' }} --cov-report=html --cov-report=xml || echo "No unit tests found (expected for new packages)"
build:
runs-on: ubuntu-latest
needs: [lint, security, unit-tests]
name: Build ${{ inputs.package }}
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install build dependencies
run: |
python -m pip install --upgrade pip
pip install build twine
- name: Build package
run: |
cd libs/${{ inputs.package }}
echo "=== Building package ==="
python -m build
echo "=== Package contents ==="
ls -la dist/
- name: Check package with twine
run: |
cd libs/${{ inputs.package }}
echo "=== Checking package metadata ==="
twine check dist/*
- name: Display package info
run: |
cd libs/${{ inputs.package }}
echo "=== Wheel contents ==="
python -m zipfile -l dist/*.whl | head -20
echo "=== Package metadata ==="
pip show --verbose ${{ inputs.package }} || true
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: python-package-distributions-${{ inputs.package }}
path: ${{ env.PACKAGE_DIR }}/dist/
retention-days: 7
integration-tests:
runs-on: ubuntu-latest
needs: [lint, security, unit-tests]
if: ${{ inputs.package == 'async-cassandra' && (inputs.run-integration-tests || inputs.run-full-suite) }}
name: Integration Tests ${{ inputs.package }}
strategy:
fail-fast: false
matrix:
test-suite:
- name: "Integration Tests"
command: "pytest tests/integration -v -m 'not stress'"
- name: "FastAPI Integration"
command: "pytest tests/fastapi_integration -v"
- name: "BDD Tests"
command: "pytest tests/bdd -v"
- name: "Example App"
command: "cd examples/fastapi_app && pytest tests/ -v"
services:
cassandra:
image: cassandra:5
ports:
- 9042:9042
options: >-
--health-cmd "nodetool status"
--health-interval 30s
--health-timeout 10s
--health-retries 10
--memory=4g
--memory-reservation=4g
env:
CASSANDRA_CLUSTER_NAME: TestCluster
CASSANDRA_DC: datacenter1
CASSANDRA_ENDPOINT_SNITCH: GossipingPropertyFileSnitch
HEAP_NEWSIZE: 512M
MAX_HEAP_SIZE: 3G
JVM_OPTS: "-XX:+UseG1GC -XX:G1RSetUpdatingPauseTimePercent=5 -XX:MaxGCPauseMillis=300"
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e "./libs/${{ inputs.package }}[test,dev]"
- name: Verify Cassandra is ready
run: |
echo "Installing cqlsh to verify Cassandra..."
pip install cqlsh
echo "Testing Cassandra connection..."
cqlsh localhost 9042 -e "DESC CLUSTER" | head -10
echo "✅ Cassandra is ready and responding to CQL"
- name: Run ${{ matrix.test-suite.name }}
env:
CASSANDRA_HOST: localhost
CASSANDRA_PORT: 9042
run: |
cd libs/${{ inputs.package }}
echo "=== Running ${{ matrix.test-suite.name }} ==="
${{ matrix.test-suite.command }}
stress-tests:
runs-on: ubuntu-latest
needs: [lint, security, unit-tests]
if: ${{ inputs.package == 'async-cassandra' && inputs.run-full-suite }}
name: Stress Tests ${{ inputs.package }}
strategy:
fail-fast: false
matrix:
test-suite:
- name: "Stress Tests"
command: "pytest tests/integration -v -m stress"
services:
cassandra:
image: cassandra:5
ports:
- 9042:9042
options: >-
--health-cmd "nodetool status"
--health-interval 30s
--health-timeout 10s
--health-retries 10
--memory=4g
--memory-reservation=4g
env:
CASSANDRA_CLUSTER_NAME: TestCluster
CASSANDRA_DC: datacenter1
CASSANDRA_ENDPOINT_SNITCH: GossipingPropertyFileSnitch
HEAP_NEWSIZE: 512M
MAX_HEAP_SIZE: 3G
JVM_OPTS: "-XX:+UseG1GC -XX:G1RSetUpdatingPauseTimePercent=5 -XX:MaxGCPauseMillis=300"
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e "./libs/${{ inputs.package }}[test,dev]"
- name: Verify Cassandra is ready
run: |
echo "Installing cqlsh to verify Cassandra..."
pip install cqlsh
echo "Testing Cassandra connection..."
cqlsh localhost 9042 -e "DESC CLUSTER" | head -10
echo "✅ Cassandra is ready and responding to CQL"
- name: Run ${{ matrix.test-suite.name }}
env:
CASSANDRA_HOST: localhost
CASSANDRA_PORT: 9042
run: |
cd libs/${{ inputs.package }}
echo "=== Running ${{ matrix.test-suite.name }} ==="
${{ matrix.test-suite.command }}
test-summary:
name: Test Summary ${{ inputs.package }}
runs-on: ubuntu-latest
needs: [lint, security, unit-tests, build]
if: always()
steps:
- name: Summary
run: |
echo "## Test Results Summary for ${{ inputs.package }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Core Tests" >> $GITHUB_STEP_SUMMARY
echo "- Lint: ${{ needs.lint.result }}" >> $GITHUB_STEP_SUMMARY
echo "- Security: ${{ needs.security.result }}" >> $GITHUB_STEP_SUMMARY
echo "- Unit Tests: ${{ needs.unit-tests.result }}" >> $GITHUB_STEP_SUMMARY
echo "- Build: ${{ needs.build.result }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [ "${{ needs.lint.result }}" != "success" ] || \
[ "${{ needs.security.result }}" != "success" ] || \
[ "${{ needs.unit-tests.result }}" != "success" ] || \
[ "${{ needs.build.result }}" != "success" ]; then
echo "❌ Some tests failed" >> $GITHUB_STEP_SUMMARY
exit 1
else
echo "✅ All tests passed" >> $GITHUB_STEP_SUMMARY
fi