-
Notifications
You must be signed in to change notification settings - Fork 2
245 lines (204 loc) · 8.65 KB
/
benchmarks.yml
File metadata and controls
245 lines (204 loc) · 8.65 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
name: Benchmarks
on:
# Run weekly on Monday at 00:00 UTC
schedule:
- cron: '0 0 * * 1'
# Manual trigger
workflow_dispatch:
inputs:
create_snapshot:
description: 'Create version snapshot (e.g., v0.2.0)'
required: false
type: string
# Run on release tags
push:
tags:
- 'v*'
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
permissions:
contents: write # Needed to push benchmark result branches
pull-requests: write # Needed to open PRs
jobs:
benchmark:
name: Run Benchmarks and Generate Docs
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
fetch-depth: 0 # Full history for git metadata
- name: Setup Rust toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
cache: true
- name: Install dependencies
run: |
# Install any system dependencies if needed
sudo apt-get update
sudo apt-get install -y build-essential
- name: Build benchmarks
run: |
cargo build --release --benches
- name: Run benchmark suite
run: |
echo "::group::Running benchmarks"
cargo bench --bench runner --quiet
echo "::endgroup::"
- name: Find latest results
id: find_results
run: |
LATEST_JSON=$(find target/benchmarks -name "results.json" -type f | sort -r | head -n 1)
if [ -z "$LATEST_JSON" ]; then
echo "❌ No benchmark results found"
exit 1
fi
echo "results_path=$LATEST_JSON" >> $GITHUB_OUTPUT
echo "✅ Found results: $LATEST_JSON"
- name: Generate documentation
run: |
echo "::group::Generating docs"
cargo run --release --package bench-support --bin render_docs -- \
"${{ steps.find_results.outputs.results_path }}" \
docs/benchmarks/latest
echo "::endgroup::"
- name: Create version snapshot (if tag or manual)
if: startsWith(github.ref, 'refs/tags/v') || inputs.create_snapshot != ''
run: |
# Determine version
if [ "${{ github.ref_type }}" = "tag" ]; then
VERSION=${GITHUB_REF#refs/tags/}
else
VERSION="${{ inputs.create_snapshot }}"
fi
if [ -n "$VERSION" ]; then
echo "::group::Creating snapshot for $VERSION"
cargo run --release --package bench-support --bin render_docs -- \
"${{ steps.find_results.outputs.results_path }}" \
"docs/benchmarks/$VERSION"
echo "✅ Created snapshot: docs/benchmarks/$VERSION"
echo "::endgroup::"
fi
- name: Display benchmark summary
run: |
echo "### 📊 Benchmark Results" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Files Generated:**" >> $GITHUB_STEP_SUMMARY
echo "- \`docs/benchmarks/latest/index.md\`" >> $GITHUB_STEP_SUMMARY
echo "- \`docs/benchmarks/latest/charts.html\`" >> $GITHUB_STEP_SUMMARY
echo "- \`docs/benchmarks/latest/results.json\`" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
# Show git info
echo "**Environment:**" >> $GITHUB_STEP_SUMMARY
echo "- Commit: \`$(git rev-parse --short HEAD)\`" >> $GITHUB_STEP_SUMMARY
echo "- Branch: \`$(git rev-parse --abbrev-ref HEAD)\`" >> $GITHUB_STEP_SUMMARY
echo "- Rustc: \`$(rustc --version)\`" >> $GITHUB_STEP_SUMMARY
echo "- Runner: \`${{ runner.os }}\`" >> $GITHUB_STEP_SUMMARY
- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Commit results to a new branch and open PR
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Determine branch name and PR title
if [ "${{ github.ref_type }}" = "tag" ]; then
VERSION="${GITHUB_REF#refs/tags/}"
BRANCH="benchmark-results/${VERSION}"
PR_TITLE="benchmark: update results for ${VERSION}"
COMMIT_MSG="benchmark: update results for ${VERSION} [skip ci]"
else
BRANCH="benchmark-results/$(date -u +%Y-%m-%d)-${{ github.run_id }}"
PR_TITLE="benchmark: update results ($(date -u +%Y-%m-%d))"
COMMIT_MSG="benchmark: update results [skip ci]"
fi
# Create and switch to the new branch from the current HEAD
git checkout -b "$BRANCH"
# Add generated files (force add since they're in .gitignore)
git add -f docs/benchmarks/latest/
# Add version snapshot if it exists
if [ -n "$(find docs/benchmarks -maxdepth 1 -name 'v*' -type d 2>/dev/null)" ]; then
git add -f docs/benchmarks/v*/
fi
# Check if there are changes to commit
if git diff --staged --quiet; then
echo "ℹ️ No changes to commit — skipping PR creation"
exit 0
fi
git commit -m "$COMMIT_MSG"
git push origin "$BRANCH"
echo "✅ Pushed branch: $BRANCH"
# Determine base branch (main by default, or the tag's base branch)
BASE_BRANCH="${{ github.event.repository.default_branch }}"
# Open a PR
gh pr create \
--base "$BASE_BRANCH" \
--head "$BRANCH" \
--title "$PR_TITLE" \
--body "$(cat <<'EOF'
## 📊 Benchmark Results
This PR was automatically generated by the [Benchmarks workflow](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}).
**Files updated:**
- `docs/benchmarks/latest/index.md`
- `docs/benchmarks/latest/charts.html`
- `docs/benchmarks/latest/results.json`
> ⚠️ **Note:** Benchmark results may vary on CI runners. For consistent measurements, use a dedicated benchmark machine.
EOF
)"
echo "✅ PR opened"
- name: Create benchmark summary
if: always()
run: |
echo "### 📈 Quick Stats" >> $GITHUB_STEP_SUMMARY
# Extract and display some key metrics from results.json
if [ -f "docs/benchmarks/latest/results.json" ]; then
echo "" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`json" >> $GITHUB_STEP_SUMMARY
jq -r '.metadata | {timestamp, git_commit, rustc_version, cpu_model}' \
docs/benchmarks/latest/results.json >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
# Count benchmarks
TOTAL=$(jq '.results | length' docs/benchmarks/latest/results.json)
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Total benchmarks:** $TOTAL" >> $GITHUB_STEP_SUMMARY
fi
- name: Upload benchmark artifacts
uses: actions/upload-artifact@v7
if: always()
with:
name: benchmark-results-${{ github.sha }}
path: |
docs/benchmarks/latest/
target/benchmarks/
retention-days: 30
- name: Comment on PR (if applicable)
if: github.event_name == 'pull_request'
uses: actions/github-script@v9
with:
script: |
const fs = require('fs');
const resultsPath = 'docs/benchmarks/latest/results.json';
if (!fs.existsSync(resultsPath)) {
console.log('No results to comment');
return;
}
const results = JSON.parse(fs.readFileSync(resultsPath, 'utf8'));
const timestamp = results.metadata.timestamp;
const benchCount = results.results.length;
const body = `## 📊 Benchmark Results
**Generated:** ${timestamp}
**Benchmarks Run:** ${benchCount}
📈 [View Charts](https://github.com/${{ github.repository }}/blob/${{ github.sha }}/docs/benchmarks/latest/charts.html)
📄 [View Report](https://github.com/${{ github.repository }}/blob/${{ github.sha }}/docs/benchmarks/latest/index.md)
📁 [Download Artifacts](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})
> ⚠️ **Note:** Benchmark results may vary on CI runners. For consistent measurements, use a dedicated benchmark machine.
`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: body
});