1
+ name : CI/CD Pipeline
2
+
3
+ on :
4
+ push :
5
+ branches : [ main, master, develop ]
6
+ pull_request :
7
+ branches : [ main, master ]
8
+ release :
9
+ types : [ published ]
10
+
11
+ env :
12
+ PYTHON_VERSION : " 3.9"
13
+ PYTHON_VERSION_MATRIX : |
14
+ [
15
+ 3.8,
16
+ 3.9,
17
+ "3.10",
18
+ "3.11",
19
+ "3.12"
20
+ ]
21
+
22
+ jobs :
23
+ # Lint and format check
24
+ lint :
25
+ name : Lint and Format Check
26
+ runs-on : ubuntu-latest
27
+
28
+ steps :
29
+ - name : Checkout code
30
+ uses : actions/checkout@v4
31
+
32
+ - name : Set up Python ${{ env.PYTHON_VERSION }}
33
+ uses : actions/setup-python@v4
34
+ with :
35
+ python-version : ${{ env.PYTHON_VERSION }}
36
+
37
+ - name : Install dependencies
38
+ run : |
39
+ python -m pip install --upgrade pip
40
+ pip install flake8 black isort mypy pre-commit
41
+ pip install -e .
42
+
43
+ - name : Run pre-commit hooks
44
+ run : |
45
+ pre-commit run --all-files
46
+
47
+ - name : Run linting checks
48
+ run : |
49
+ flake8 src/ tests/ --max-line-length=88 --extend-ignore=E203,W503
50
+ black --check src/ tests/
51
+ isort --check-only src/ tests/
52
+ mypy src/ --ignore-missing-imports
53
+
54
+ # Test across multiple Python versions
55
+ test :
56
+ name : Test Python ${{ matrix.python-version }}
57
+ runs-on : ubuntu-latest
58
+ strategy :
59
+ matrix :
60
+ python-version : ${{ fromJson(env.PYTHON_VERSION_MATRIX) }}
61
+
62
+ steps :
63
+ - name : Checkout code
64
+ uses : actions/checkout@v4
65
+
66
+ - name : Set up Python ${{ matrix.python-version }}
67
+ uses : actions/setup-python@v4
68
+ with :
69
+ python-version : ${{ matrix.python-version }}
70
+
71
+ - name : Install dependencies
72
+ run : |
73
+ python -m pip install --upgrade pip
74
+ pip install pytest pytest-cov pytest-mock pytest-asyncio
75
+ pip install -e .
76
+
77
+ - name : Run tests with coverage
78
+ run : |
79
+ pytest tests/ -v --cov=src/api_mocker --cov-report=xml --cov-report=html
80
+
81
+ - name : Upload coverage to Codecov
82
+ uses : codecov/codecov-action@v3
83
+ with :
84
+ file : ./coverage.xml
85
+ flags : unittests
86
+ name : codecov-umbrella
87
+ fail_ci_if_error : false
88
+
89
+ # Integration tests
90
+ integration :
91
+ name : Integration Tests
92
+ runs-on : ubuntu-latest
93
+ needs : test
94
+
95
+ steps :
96
+ - name : Checkout code
97
+ uses : actions/checkout@v4
98
+
99
+ - name : Set up Python ${{ env.PYTHON_VERSION }}
100
+ uses : actions/setup-python@v4
101
+ with :
102
+ python-version : ${{ env.PYTHON_VERSION }}
103
+
104
+ - name : Install dependencies
105
+ run : |
106
+ python -m pip install --upgrade pip
107
+ pip install pytest httpx
108
+ pip install -e .
109
+
110
+ - name : Run integration tests
111
+ run : |
112
+ pytest tests/test_integration.py -v --tb=short
113
+
114
+ - name : Test CLI functionality
115
+ run : |
116
+ api-mocker --help
117
+ api-mocker start --help
118
+ api-mocker scenarios --help
119
+ api-mocker smart-matching --help
120
+ api-mocker enhanced-analytics --help
121
+
122
+ # Security scan
123
+ security :
124
+ name : Security Scan
125
+ runs-on : ubuntu-latest
126
+
127
+ steps :
128
+ - name : Checkout code
129
+ uses : actions/checkout@v4
130
+
131
+ - name : Run Bandit security scan
132
+ uses : python-security/bandit-action@v1
133
+ with :
134
+ path : src/
135
+ level : low
136
+ confidence : medium
137
+
138
+ - name : Run Safety check
139
+ run : |
140
+ pip install safety
141
+ safety check
142
+
143
+ # Build and test package
144
+ build :
145
+ name : Build Package
146
+ runs-on : ubuntu-latest
147
+ needs : [test, integration, security]
148
+
149
+ steps :
150
+ - name : Checkout code
151
+ uses : actions/checkout@v4
152
+
153
+ - name : Set up Python ${{ env.PYTHON_VERSION }}
154
+ uses : actions/setup-python@v4
155
+ with :
156
+ python-version : ${{ env.PYTHON_VERSION }}
157
+
158
+ - name : Install build dependencies
159
+ run : |
160
+ python -m pip install --upgrade pip
161
+ pip install build twine
162
+
163
+ - name : Build package
164
+ run : |
165
+ python -m build
166
+
167
+ - name : Check package
168
+ run : |
169
+ twine check dist/*
170
+
171
+ - name : Upload build artifacts
172
+ uses : actions/upload-artifact@v3
173
+ with :
174
+ name : dist
175
+ path : dist/
176
+
177
+ # Deploy to PyPI (only on release)
178
+ deploy :
179
+ name : Deploy to PyPI
180
+ runs-on : ubuntu-latest
181
+ needs : build
182
+ if : github.event_name == 'release'
183
+
184
+ steps :
185
+ - name : Checkout code
186
+ uses : actions/checkout@v4
187
+
188
+ - name : Set up Python ${{ env.PYTHON_VERSION }}
189
+ uses : actions/setup-python@v4
190
+ with :
191
+ python-version : ${{ env.PYTHON_VERSION }}
192
+
193
+ - name : Download build artifacts
194
+ uses : actions/download-artifact@v3
195
+ with :
196
+ name : dist
197
+ path : dist/
198
+
199
+ - name : Install twine
200
+ run : |
201
+ python -m pip install --upgrade pip
202
+ pip install twine
203
+
204
+ - name : Deploy to PyPI
205
+ env :
206
+ TWINE_USERNAME : __token__
207
+ TWINE_PASSWORD : ${{ secrets.PYPI_API_TOKEN }}
208
+ run : |
209
+ twine upload dist/*
210
+
211
+ - name : Create GitHub release
212
+ uses : actions/create-release@v1
213
+ env :
214
+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
215
+ with :
216
+ tag_name : ${{ github.ref }}
217
+ release_name : Release ${{ github.ref }}
218
+ body : |
219
+ ## What's New
220
+
221
+ ### Features
222
+ - Enhanced mock response management
223
+ - Comprehensive testing framework
224
+ - Advanced analytics and insights
225
+ - Scenario-based mocking
226
+ - Smart response matching
227
+
228
+ ### Improvements
229
+ - Better error handling
230
+ - Performance optimizations
231
+ - Enhanced documentation
232
+
233
+ ### Bug Fixes
234
+ - Fixed various edge cases
235
+ - Improved compatibility
236
+
237
+ ## Installation
238
+
239
+ ```bash
240
+ pip install api-mocker
241
+ ```
242
+
243
+ ## Documentation
244
+
245
+ See the [README](https://github.com/${{ github.repository }}) for detailed usage instructions.
246
+ draft : false
247
+ prerelease : false
248
+
249
+ # Documentation deployment
250
+ docs :
251
+ name : Deploy Documentation
252
+ runs-on : ubuntu-latest
253
+ needs : build
254
+ if : github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master'
255
+
256
+ steps :
257
+ - name : Checkout code
258
+ uses : actions/checkout@v4
259
+
260
+ - name : Set up Python ${{ env.PYTHON_VERSION }}
261
+ uses : actions/setup-python@v4
262
+ with :
263
+ python-version : ${{ env.PYTHON_VERSION }}
264
+
265
+ - name : Install documentation dependencies
266
+ run : |
267
+ python -m pip install --upgrade pip
268
+ pip install mkdocs mkdocs-material pymdown-extensions
269
+
270
+ - name : Build documentation
271
+ run : |
272
+ mkdocs build
273
+
274
+ - name : Deploy to GitHub Pages
275
+ uses : peaceiris/actions-gh-pages@v3
276
+ with :
277
+ github_token : ${{ secrets.GITHUB_TOKEN }}
278
+ publish_dir : ./site
279
+
280
+ # Performance testing
281
+ performance :
282
+ name : Performance Tests
283
+ runs-on : ubuntu-latest
284
+ needs : test
285
+
286
+ steps :
287
+ - name : Checkout code
288
+ uses : actions/checkout@v4
289
+
290
+ - name : Set up Python ${{ env.PYTHON_VERSION }}
291
+ uses : actions/setup-python@v4
292
+ with :
293
+ python-version : ${{ env.PYTHON_VERSION }}
294
+
295
+ - name : Install dependencies
296
+ run : |
297
+ python -m pip install --upgrade pip
298
+ pip install pytest-benchmark
299
+ pip install -e .
300
+
301
+ - name : Run performance benchmarks
302
+ run : |
303
+ pytest tests/test_performance.py --benchmark-only
304
+
305
+ - name : Upload benchmark results
306
+ uses : actions/upload-artifact@v3
307
+ with :
308
+ name : benchmark-results
309
+ path : .benchmarks/
310
+
311
+ # Dependency updates
312
+ dependabot :
313
+ name : Dependency Updates
314
+ runs-on : ubuntu-latest
315
+ if : github.actor == 'dependabot[bot]'
316
+
317
+ steps :
318
+ - name : Checkout code
319
+ uses : actions/checkout@v4
320
+
321
+ - name : Set up Python ${{ env.PYTHON_VERSION }}
322
+ uses : actions/setup-python@v4
323
+ with :
324
+ python-version : ${{ env.PYTHON_VERSION }}
325
+
326
+ - name : Install dependencies
327
+ run : |
328
+ python -m pip install --upgrade pip
329
+ pip install -e .
330
+
331
+ - name : Run tests with updated dependencies
332
+ run : |
333
+ pytest tests/ -v
334
+
335
+ - name : Comment on PR
336
+ uses : actions/github-script@v6
337
+ with :
338
+ script : |
339
+ github.rest.issues.createComment({
340
+ issue_number: context.issue.number,
341
+ owner: context.repo.owner,
342
+ repo: context.repo.repo,
343
+ body: 'β
All tests passed with updated dependencies!'
344
+ })
0 commit comments