-
Notifications
You must be signed in to change notification settings - Fork 2
254 lines (219 loc) · 8.74 KB
/
Copy pathmain.yml
File metadata and controls
254 lines (219 loc) · 8.74 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
name: Main
on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
workflow_dispatch:
jobs:
quality:
runs-on: ubuntu-latest
steps:
- name: Check out
uses: actions/checkout@v4
- uses: actions/cache@v4
with:
path: ~/.cache/pre-commit
key: pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}
- name: Set up the environment
uses: ./.github/actions/setup-python-env
- name: Run checks
run: make check
tests-and-type-check:
runs-on: ${{ matrix.platform }}
strategy:
matrix:
platform: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
fail-fast: false
defaults:
run:
shell: bash
steps:
- name: Check out
uses: actions/checkout@v4
- name: Set up the environment
uses: ./.github/actions/setup-python-env
with:
python-version: ${{ matrix.python-version }}
- name: Run tests
run: uv run python -m pytest tests --cov --cov-config=pyproject.toml --cov-report=xml
- name: Check typing
run: uv run ty check
- name: Upload coverage reports to Codecov on Ubuntu / Python 3.11
uses: codecov/codecov-action@v4
if: ${{ matrix.platform == 'ubuntu-latest' && matrix.python-version == '3.11' }}
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
check-docs:
runs-on: ubuntu-latest
steps:
- name: Check out
uses: actions/checkout@v4
- name: Set up the environment
uses: ./.github/actions/setup-python-env
- name: Check if documentation can be built
run: uv run zensical build -s
version-preview:
# Show contributors what a merge would release, based on the conventional
# commits on the branch. Pull requests only; informational.
if: github.event_name == 'pull_request' && github.event.pull_request.draft == false
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- name: Check out
uses: actions/checkout@v4
with:
fetch-depth: 0 # PSR needs full history + tags to compute the bump
ref: ${{ github.event.pull_request.head.sha }}
- name: Set up the environment
uses: ./.github/actions/setup-python-env
- name: Compute release preview
id: preview
run: |
# PSR only computes a release on the main branch; name the checked-out
# PR head 'main' so the preview reflects what a merge would release.
git checkout -B main >/dev/null 2>&1 || true
current=$(uv version --short 2>/dev/null || echo "unknown")
next=$(uv run semantic-release version --print 2>/dev/null || echo "")
if [ -n "$next" ] && [ "$next" != "$current" ]; then
echo "released=true" >> "$GITHUB_OUTPUT"
else
echo "released=false" >> "$GITHUB_OUTPUT"
fi
echo "current=$current" >> "$GITHUB_OUTPUT"
echo "next=$next" >> "$GITHUB_OUTPUT"
# Stamp the upcoming changelog section locally (no commit/tag/push/build)
# so the preview shows the notes this merge would add.
if [ -n "$next" ] && [ "$next" != "$current" ]; then
uv run semantic-release version --no-commit --no-tag --no-push --no-vcs-release --skip-build >/dev/null 2>&1 || true
fi
{
echo "changelog<<PSR_EOF"
git --no-pager diff HEAD -- CHANGELOG.md | awk '/^\+/ && !/^\+\+\+/ {sub(/^\+/,""); print}' | head -80
echo "PSR_EOF"
} >> "$GITHUB_OUTPUT"
- name: Post release preview comment
uses: marocchino/sticky-pull-request-comment@v2
with:
header: version-preview
message: |
## Release preview
${{ steps.preview.outputs.released == 'true' && format('Merging this PR would release **v{0}** (current: `v{1}`).', steps.preview.outputs.next, steps.preview.outputs.current) || format('No version bump from the current commits (stays at `v{0}`). Use conventional commit types (`feat`, `fix`, ...) to trigger a release.', steps.preview.outputs.current) }}
<details><summary>Changelog preview (truncated)</summary>
```markdown
${{ steps.preview.outputs.changelog }}
```
</details>
<sub>Preview via python-semantic-release and conventional commits.</sub>
benchmark:
runs-on: ubuntu-latest
if: github.event.pull_request.draft == false
permissions:
contents: read
pull-requests: write
steps:
- name: Check out
uses: actions/checkout@v4
with:
fetch-depth: 0 # need history for baseline comparison
- name: Set up the environment
uses: ./.github/actions/setup-python-env
# Run current benchmarks
- name: Run benchmark tests
run: >-
uv run python -m pytest -c pytest.benchmark.ini
--benchmark-only --benchmark-autosave
--benchmark-json=benchmark_results.json
continue-on-error: true
# Try to get baseline from main branch via worktree (avoids switching branches
# in the main workspace, which would delete action files not yet on main)
- name: Get baseline benchmarks
if: github.event_name == 'pull_request'
run: |
git worktree add /tmp/baseline main 2>/dev/null || {
echo "⚠️ Could not create worktree for main, skipping baseline"
exit 0
}
cd /tmp/baseline
uv run python -m pytest -c pytest.benchmark.ini \
--benchmark-only --benchmark-autosave \
--benchmark-json="$GITHUB_WORKSPACE/baseline_benchmark.json" || true
if [ -f "$GITHUB_WORKSPACE/baseline_benchmark.json" ]; then
echo "✓ Saved baseline benchmark results"
else
echo "⚠️ No baseline benchmarks generated"
fi
git -C "$GITHUB_WORKSPACE" worktree remove /tmp/baseline --force || true
continue-on-error: true
# Compare benchmarks if baseline exists
- name: Compare with baseline
if: github.event_name == 'pull_request' && hashFiles('baseline_benchmark.json') != ''
run: |
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
uv run 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