-
Notifications
You must be signed in to change notification settings - Fork 1
364 lines (312 loc) · 11.7 KB
/
python-tests.yml
File metadata and controls
364 lines (312 loc) · 11.7 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
name: Python Tests
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]
schedule:
# Run integration tests daily at 6 AM UTC to catch AWS API changes
- cron: '0 6 * * *'
workflow_dispatch: # Allow manual triggering
workflow_call: # Allow this workflow to be called by other workflows
env:
POETRY_VERSION: "1.7.1"
PYTHON_DEFAULT_VERSION: "3.11"
jobs:
unit-tests:
runs-on: ubuntu-latest
strategy:
fail-fast: false # Don't cancel other jobs if one fails
matrix:
python-version: ['3.9', '3.10', '3.11', '3.12']
name: Unit Tests Python ${{ matrix.python-version }}
steps:
- uses: actions/checkout@v4
- name: Install Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install poetry
uses: abatilo/actions-poetry@v2
with:
poetry-version: ${{ env.POETRY_VERSION }}
- name: Configure poetry
run: |
poetry config virtualenvs.create true
poetry config virtualenvs.in-project true
- name: Cache poetry dependencies
uses: actions/cache@v3
with:
path: .venv
key: venv-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('**/poetry.lock') }}
restore-keys: |
venv-${{ runner.os }}-${{ matrix.python-version }}-
- name: Install the project dependencies
run: make install
- name: Run unit tests
run: make test-unit
- name: Upload unit test results
uses: actions/upload-artifact@v4
if: always()
with:
name: unit-test-results-${{ matrix.python-version }}
path: |
.coverage
htmlcov/
retention-days: 7
integration-tests:
runs-on: ubuntu-latest
name: Integration Tests
timeout-minutes: 15 # Set overall job timeout
strategy:
fail-fast: false
matrix:
test-config:
- name: "standard"
python-version: "3.11"
extra-args: ""
- name: "python-3.9"
python-version: "3.9"
extra-args: ""
steps:
- uses: actions/checkout@v4
- name: Install Python ${{ matrix.test-config.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.test-config.python-version }}
- name: Install poetry
uses: abatilo/actions-poetry@v2
with:
poetry-version: ${{ env.POETRY_VERSION }}
- name: Configure poetry
run: |
poetry config virtualenvs.create true
poetry config virtualenvs.in-project true
- name: Cache poetry dependencies
uses: actions/cache@v3
with:
path: .venv
key: venv-${{ runner.os }}-${{ matrix.test-config.python-version }}-${{ hashFiles('**/poetry.lock') }}
restore-keys: |
venv-${{ runner.os }}-${{ matrix.test-config.python-version }}-
- name: Install the project dependencies
run: make install
- name: Run integration tests
run: make test-integration
env:
CI: true
PYTEST_TIMEOUT: 600 # 10 minute timeout for individual tests
SPOT_OPTIMIZER_DEBUG: 1
continue-on-error: false
timeout-minutes: 12 # Step timeout
- name: Upload integration test results
uses: actions/upload-artifact@v4
if: always()
with:
name: integration-test-results-${{ matrix.test-config.name }}
path: |
tests/test_integration.py
*.log
.coverage
retention-days: 7
- name: Create integration test report
if: always()
run: |
echo "## Integration Test Results (${{ matrix.test-config.name }})" >> $GITHUB_STEP_SUMMARY
echo "Python Version: ${{ matrix.test-config.python-version }}" >> $GITHUB_STEP_SUMMARY
echo "Test Configuration: ${{ matrix.test-config.name }}" >> $GITHUB_STEP_SUMMARY
if [ $? -eq 0 ]; then
echo "✅ Integration tests passed" >> $GITHUB_STEP_SUMMARY
else
echo "❌ Integration tests failed" >> $GITHUB_STEP_SUMMARY
fi
coverage:
needs: [unit-tests]
runs-on: ubuntu-latest
name: Coverage Report
steps:
- uses: actions/checkout@v4
- name: Install Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_DEFAULT_VERSION }}
- name: Install poetry
uses: abatilo/actions-poetry@v2
with:
poetry-version: ${{ env.POETRY_VERSION }}
- name: Configure poetry
run: |
poetry config virtualenvs.create true
poetry config virtualenvs.in-project true
- name: Cache poetry dependencies
uses: actions/cache@v3
with:
path: .venv
key: venv-${{ runner.os }}-${{ env.PYTHON_DEFAULT_VERSION }}-${{ hashFiles('**/poetry.lock') }}
restore-keys: |
venv-${{ runner.os }}-${{ env.PYTHON_DEFAULT_VERSION }}-
- name: Install the project dependencies
run: make install
- name: Check coverage
run: make coverage
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v5
if: github.event_name != 'schedule' # Skip for scheduled runs
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: false # Don't fail CI if codecov upload fails
- name: Generate coverage report summary
if: always()
run: |
echo "## Coverage Report" >> $GITHUB_STEP_SUMMARY
if [ -f .coverage ]; then
poetry run coverage report --format=markdown >> $GITHUB_STEP_SUMMARY || echo "Coverage report generation failed" >> $GITHUB_STEP_SUMMARY
else
echo "No coverage data found" >> $GITHUB_STEP_SUMMARY
fi
# Comprehensive scheduled tests to catch AWS API changes
scheduled-integration:
runs-on: ubuntu-latest
name: Scheduled Integration Tests
if: github.event_name == 'schedule'
timeout-minutes: 20
steps:
- uses: actions/checkout@v4
- name: Install Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_DEFAULT_VERSION }}
- name: Install poetry
uses: abatilo/actions-poetry@v2
with:
poetry-version: ${{ env.POETRY_VERSION }}
- name: Configure poetry
run: |
poetry config virtualenvs.create true
poetry config virtualenvs.in-project true
- name: Install the project dependencies
run: make install
- name: Run comprehensive integration tests
run: make test-integration
env:
CI: true
SPOT_OPTIMIZER_DEBUG: 1
continue-on-error: true # Don't fail immediately, we want to create issue
id: integration-tests
- name: Create detailed test report
if: always()
run: |
echo "## Scheduled Integration Test Report" > test-report.md
echo "Date: $(date)" >> test-report.md
echo "Python Version: ${{ env.PYTHON_DEFAULT_VERSION }}" >> test-report.md
echo "" >> test-report.md
if [ "${{ steps.integration-tests.outcome }}" = "success" ]; then
echo "✅ All integration tests passed" >> test-report.md
else
echo "❌ Some integration tests failed" >> test-report.md
echo "" >> test-report.md
echo "This might indicate:" >> test-report.md
echo "- Changes in AWS APIs" >> test-report.md
echo "- Service availability issues" >> test-report.md
echo "- Network connectivity problems" >> test-report.md
echo "- Changes in instance availability" >> test-report.md
fi
- name: Upload scheduled test results
uses: actions/upload-artifact@v4
if: always()
with:
name: scheduled-integration-results
path: |
test-report.md
*.log
retention-days: 30
- name: Notify on failure
if: failure() || steps.integration-tests.outcome == 'failure'
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
let body = 'The scheduled integration tests have failed. This might indicate changes in AWS APIs or service availability.';
try {
if (fs.existsSync('test-report.md')) {
const report = fs.readFileSync('test-report.md', 'utf8');
body = report;
}
} catch (error) {
console.log('Could not read test report:', error);
}
github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: `Scheduled Integration Tests Failed - ${new Date().toISOString().split('T')[0]}`,
body: body,
labels: ['bug', 'integration-test', 'scheduled-failure']
})
# Security and dependency scanning
security-scan:
runs-on: ubuntu-latest
name: Security Scan
if: github.event_name != 'schedule' # Skip for scheduled runs
steps:
- uses: actions/checkout@v4
- name: Install Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_DEFAULT_VERSION }}
- name: Install poetry
uses: abatilo/actions-poetry@v2
with:
poetry-version: ${{ env.POETRY_VERSION }}
- name: Install dependencies
run: make install
- name: Run security scan
run: |
poetry run pip install safety bandit
poetry run safety check --json || true
poetry run bandit -r spot_optimizer/ -f json || true
continue-on-error: true # Don't fail CI for security issues, just report
- name: Upload security scan results
uses: actions/upload-artifact@v4
if: always()
with:
name: security-scan-results
path: |
safety-report.json
bandit-report.json
retention-days: 30
# Build verification
build-verification:
needs: [unit-tests]
runs-on: ubuntu-latest
name: Build Verification
if: github.event_name != 'schedule'
steps:
- uses: actions/checkout@v4
- name: Install Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_DEFAULT_VERSION }}
- name: Install poetry
uses: abatilo/actions-poetry@v2
with:
poetry-version: ${{ env.POETRY_VERSION }}
- name: Install dependencies
run: make install
- name: Build package
run: make build
- name: Verify package contents
run: |
# Create a fresh virtual environment to test package installation
python -m venv test_env
source test_env/bin/activate
# Install the wheel package
pip install dist/*.whl
# Verify the package can be imported and used
python -c "import spot_optimizer; print('Package installed successfully')"
python -c "from spot_optimizer import optimize, Mode; print('Imports working')"
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: build-artifacts
path: dist/
retention-days: 7