-
Notifications
You must be signed in to change notification settings - Fork 2
282 lines (252 loc) · 9.53 KB
/
ci.yml
File metadata and controls
282 lines (252 loc) · 9.53 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
# GitHub Actions configuration **EXAMPLE**,
# MODIFY IT ACCORDING TO YOUR NEEDS!
# Reference: https://docs.github.com/en/actions
name: tests
on:
push:
# Avoid using all the resources/limits available by checking only
# relevant branches and tags. Other branches can be checked via PRs.
branches: [main]
tags: ['v[0-9]*', '[0-9]+.[0-9]+*'] # Match tags that resemble a version
pull_request: # Run in every PR
workflow_dispatch: # Allow manually triggering the workflow
schedule:
# Run roughly every 15 days at 00:00 UTC
# (useful to check if updates on dependencies break the package)
- cron: '0 0 1,16 * *'
permissions:
contents: read
concurrency:
group: >-
${{ github.workflow }}-${{ github.ref_type }}-
${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: true
jobs:
prepare:
runs-on: ubuntu-latest
outputs:
wheel-distribution: ${{ steps.wheel-distribution.outputs.path }}
steps:
- uses: actions/checkout@v3
with: {fetch-depth: 0} # deep clone for setuptools-scm
- uses: actions/setup-python@v4
id: setup-python
with: {python-version: "3.11"}
- name: Run static analysis and format checkers
run: pipx run pre-commit run --all-files --show-diff-on-failure
- name: Build package distribution files
run: >-
pipx run --python '${{ steps.setup-python.outputs.python-path }}'
tox -e clean,build
- name: Record the path of wheel distribution
id: wheel-distribution
run: echo "path=$(ls dist/*.whl)" >> $GITHUB_OUTPUT
- name: Store the distribution files for use in other stages
# `tests` and `publish` will use the same pre-built distributions,
# so we make sure to release the exact same package that was tested
uses: actions/upload-artifact@v4
with:
name: python-distribution-files
path: dist/
retention-days: 1
test:
needs: prepare
strategy:
matrix:
python:
- "3.10" # oldest Python supported by PSF
- "3.13" # newest Python that is stable
platform:
- ubuntu-latest
- macos-latest
- windows-latest
permissions:
contents: read
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
id: setup-python
with:
python-version: ${{ matrix.python }}
- name: Retrieve pre-built distribution files
uses: actions/download-artifact@v4
with: {name: python-distribution-files, path: dist/}
- name: Run tests
run: >-
pipx run --python '${{ steps.setup-python.outputs.python-path }}'
tox -e test --installpkg '${{ needs.prepare.outputs.wheel-distribution }}'
-- -rFEx --durations 10 --color yes # pytest args
- name: Generate coverage report
run: pipx run coverage lcov -o coverage.lcov
- name: Upload partial coverage report
uses: coverallsapp/github-action@master
with:
path-to-lcov: coverage.lcov
github-token: ${{ secrets.GITHUB_TOKEN }}
flag-name: ${{ matrix.platform }} - py${{ matrix.python }}
parallel: true
benchmark:
needs: prepare
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Need history for comparison
- uses: actions/setup-python@v4
id: setup-python
with:
python-version: "3.11"
- name: Retrieve pre-built distribution files
uses: actions/download-artifact@v4
with: {name: python-distribution-files, path: dist/}
# Run current benchmarks
- name: Run benchmark tests
run: >-
pipx run --python '${{ steps.setup-python.outputs.python-path }}'
tox -e benchmark --installpkg '${{ needs.prepare.outputs.wheel-distribution }}'
continue-on-error: true
# Save current results before switching branches
- name: Save current benchmark results
if: github.event_name == 'pull_request'
run: |
if [ -f benchmark_results.json ]; then
cp benchmark_results.json current_benchmark.json
echo "✓ Saved current benchmark results"
else
echo "⚠️ No benchmark_results.json found"
ls -la
fi
# Try to get baseline from main branch
- name: Get baseline benchmarks
if: github.event_name == 'pull_request'
run: |
git fetch origin main:main || true
git checkout main || exit 0
# Install from source (no --installpkg) to match checked-out main branch code
# This prevents wheel/source mismatch where PR wheel is used with main branch tests
pipx run --python '${{ steps.setup-python.outputs.python-path }}' \
tox -e benchmark || true
if [ -f benchmark_results.json ]; then
mv benchmark_results.json baseline_benchmark.json
echo "✓ Saved baseline benchmark results"
else
echo "⚠️ No baseline benchmarks generated"
fi
git checkout ${{ github.head_ref }}
continue-on-error: true
# Restore current results
- name: Restore current benchmark results
if: github.event_name == 'pull_request'
run: |
if [ -f current_benchmark.json ]; then
mv current_benchmark.json benchmark_results.json
echo "✓ Restored current benchmark results"
fi
echo "Files available for comparison:"
ls -la *.json || echo "No JSON files found"
# Compare benchmarks if baseline exists
- name: Compare with baseline
if: github.event_name == 'pull_request' && hashFiles('baseline_benchmark.json') != ''
run: |
echo "Running benchmark comparison..."
echo "Checking files exist..."
if [ ! -f baseline_benchmark.json ]; then
echo "❌ baseline_benchmark.json not found!"
exit 1
fi
if [ ! -f benchmark_results.json ]; then
echo "❌ benchmark_results.json not found!"
exit 1
fi
echo "✓ Both files exist, running comparison..."
python scripts/compare_benchmarks.py \
baseline_benchmark.json \
benchmark_results.json \
--threshold 1.3 \
--quiet > benchmark_comparison.txt
echo "Comparison output:"
cat benchmark_comparison.txt
continue-on-error: true
# Comment on PR with results
- name: Post benchmark results to PR
if: github.event_name == 'pull_request' && hashFiles('baseline_benchmark.json') != ''
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
let comparison = 'No comparison data available';
try {
if (fs.existsSync('benchmark_comparison.txt')) {
comparison = fs.readFileSync('benchmark_comparison.txt', 'utf8').trim();
if (!comparison) {
comparison = 'Comparison file is empty - check workflow logs for details';
}
}
} catch (e) {
comparison = `Error reading comparison: ${e.message}`;
console.error('Error:', e);
}
const body = `## 📊 Benchmark Results
<details>
<summary>Click to see benchmark comparison</summary>
\`\`\`
${comparison}
\`\`\`
</details>
**Threshold:** 1.3x (30% slower triggers a regression warning)
**Note:** Benchmarks are informational only and won't fail the build.
<sub>💡 Tip: Download the \`benchmark-results\` artifact for detailed JSON data</sub>
`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: body
});
continue-on-error: true
# Upload benchmark artifacts
- name: Upload benchmark results
uses: actions/upload-artifact@v4
if: always()
with:
name: benchmark-results
path: |
benchmark_results.json
baseline_benchmark.json
.benchmarks/
retention-days: 30
finalize:
needs: test
runs-on: ubuntu-latest
steps:
- name: Finalize coverage report
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
parallel-finished: true
publish:
needs: finalize
if: ${{ github.event_name == 'push' && contains(github.ref, 'refs/tags/') }}
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with: {python-version: "3.11"}
- name: Retrieve pre-built distribution files
uses: actions/download-artifact@v4
with: {name: python-distribution-files, path: dist/}
- name: Publish Package
env:
# TODO: Set your PYPI_TOKEN as a secret using GitHub UI
# - https://pypi.org/help/#apitoken
# - https://docs.github.com/en/actions/security-guides/encrypted-secrets
TWINE_REPOSITORY: pypi
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
run: pipx run tox -e publish