-
Notifications
You must be signed in to change notification settings - Fork 0
301 lines (273 loc) · 9.93 KB
/
Copy pathbenchmarks.yml
File metadata and controls
301 lines (273 loc) · 9.93 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
name: Benchmarks
on:
push:
branches: [main, develop]
pull_request:
branches: [main, develop]
schedule:
# Run daily at 2AM UTC for nightly benchmarks
- cron: '0 2 * * *'
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
jobs:
benchmarks:
name: ${{ matrix.name }}
runs-on: ubuntu-latest
timeout-minutes: 25
strategy:
fail-fast: false
matrix:
include:
- bench: write_bench
name: Write
- bench: read_bench
name: Read
- bench: scan_bench
name: Scan
- bench: mixed_bench
name: Mixed
- bench: stress_bench
name: Stress
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Cache cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
key: ${{ runner.os }}-bench-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-bench-
- name: Build benchmark
run: cargo build --bench ${{ matrix.bench }} --release
- name: Run benchmark (CI mode)
run: |
cargo bench --bench ${{ matrix.bench }} -- --noplot 2>&1 | tee bench_output.txt
exit "${PIPESTATUS[0]}"
continue-on-error: true
env:
CI: true
- name: Upload results artifact
run: |
cp bench_output.txt "bench_output_${{ matrix.bench }}.txt"
shell: bash
- name: Upload results artifact
uses: actions/upload-artifact@v4
with:
name: bench-results-${{ matrix.bench }}
path: bench_output_${{ matrix.bench }}.txt
retention-days: 30
lint:
name: Lint & Format
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: clippy, rustfmt
- uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
key: ${{ runner.os }}-bench-lint-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-bench-lint-
- name: Run clippy
run: cargo clippy --all-targets -- -D warnings
- name: Format check
run: cargo fmt --all -- --check
update-readme:
name: Update README with results
if: github.event_name != 'pull_request'
needs: [benchmarks]
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Install OpenCode CLI
id: install_opencode
run: |
if command -v opencode &>/dev/null; then
echo "OpenCode already installed at $(which opencode)"
echo "cache-hit=true" >> "$GITHUB_OUTPUT"
else
echo "Installing OpenCode..."
curl -fsSL https://raw.githubusercontent.com/opencode-ai/opencode/main/install.sh | bash
if [ -f "$HOME/.opencode/bin/opencode" ]; then
echo "$HOME/.opencode/bin" >> "$GITHUB_PATH"
elif [ -f "/usr/local/bin/opencode" ]; then
: # already in PATH
fi
echo "cache-hit=false" >> "$GITHUB_OUTPUT"
fi
- name: Download all benchmark results
uses: actions/download-artifact@v4
with:
pattern: bench-results-*
merge-multiple: true
- name: Combine benchmark outputs
run: |
# Each matrix runner produces bench_output_<bench>.txt; combine them in order
for f in \
bench_output_write_bench.txt \
bench_output_read_bench.txt \
bench_output_scan_bench.txt \
bench_output_mixed_bench.txt \
bench_output_stress_bench.txt; do
if [ -f "$f" ]; then
SECTION="=== $(echo "$f" | sed 's/bench_output_//; s/.txt//') ==="
{
echo "$SECTION"
cat "$f"
echo ""
} >> bench_combined.txt
fi
done
cp bench_combined.txt bench_output.txt
echo "--- Combined output ---"
wc -l bench_output.txt
- name: Generate benchmark summary
run: |
DATE=$(date -u '+%Y-%m-%d %H:%M UTC')
RUN_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
if [ ! -s bench_output.txt ]; then
{
echo "<!-- BENCHMARK_RESULTS_START -->"
echo "> ⚠️ CI on **${DATE}** — benchmark produced no results. [View run](${RUN_URL})"
echo ""
echo "<!-- BENCHMARK_RESULTS_END -->"
} > bench_block.txt
perl -i -0pe '
my $block = do { open my $f, "bench_block.txt" or die; local $/; <$f> };
s|<!-- BENCHMARK_RESULTS_START -->.*?<!-- BENCHMARK_RESULTS_END -->|$block|gs;
' README.md
exit 0
fi
FORMAT_OK=false
if python3 scripts/format_bench.py; then
TABLE=$(cat bench_table.txt)
if [ -n "$TABLE" ]; then
{
echo "<!-- BENCHMARK_RESULTS_START -->"
echo "> 🤖 Auto-updated by CI on **${DATE}** — [View run](${RUN_URL})"
echo ""
echo "$TABLE"
echo ""
echo "<!-- BENCHMARK_RESULTS_END -->"
} > bench_block.txt
else
{
echo "<!-- BENCHMARK_RESULTS_START -->"
echo "> 🤖 Auto-updated by CI on **${DATE}** — [View run](${RUN_URL})"
echo ""
echo "*No results parsed — check the [run artifacts](${RUN_URL}).*"
echo ""
echo "<!-- BENCHMARK_RESULTS_END -->"
} > bench_block.txt
fi
FORMAT_OK=true
else
echo "⚠️ Python formatter failed (exit code $?), trying alternatives..." >&2
fi
if [ "$FORMAT_OK" != "true" ] && command -v opencode &>/dev/null; then
echo "Trying direct OpenCode formatting..." >&2
if FORMATTED=$(opencode run --prompt "Format the following benchmark results as a clean Markdown summary table with columns: Benchmark, Metric, Value. Output ONLY the markdown." < bench_output.txt 2>/dev/null); then
echo "✅ OpenCode direct formatting succeeded"
{
echo "<!-- BENCHMARK_RESULTS_START -->"
echo "> 🤖 Auto-formatted by OpenCode AI — **${DATE}** — [View run](${RUN_URL})"
echo ""
echo "$FORMATTED"
echo ""
echo "<!-- BENCHMARK_RESULTS_END -->"
} > bench_block.txt
FORMAT_OK=true
else
echo "⚠️ Direct OpenCode failed, falling back to Perl parser" >&2
fi
fi
if [ "$FORMAT_OK" != "true" ]; then
ROWS=$(perl -ne '
if (/^([a-zA-Z]\S+(?:\/\S+)?)\s*$/) {
$name = $1;
}
elsif (/^([a-zA-Z]\S+(?:\/\S+)?)\s+time:\s+\[([^\]]+)\]/) {
$name = $1;
my @vals = split(/\s+/, $2);
my $median = "$vals[2] $vals[3]";
$median =~ s/^\s+|\s+$//g;
print "| `$name` | $median |\n";
$name = "";
}
elsif ($name && /^\s+time:\s+\[([^\]]+)\]/) {
my @vals = split(/\s+/, $1);
my $median = "$vals[2] $vals[3]";
$median =~ s/^\s+|\s+$//g;
print "| `$name` | $median |\n";
$name = "";
}
' bench_output.txt)
{
echo "<!-- BENCHMARK_RESULTS_START -->"
echo "> 🤖 Auto-updated by CI on **${DATE}** — [View run](${RUN_URL})"
echo ""
if [ -n "$ROWS" ]; then
echo "| Benchmark | Mediana |"
echo "|-----------|--------|"
echo "$ROWS"
else
echo "*Nenhum resultado parseado — verifique os [artefatos do run](${RUN_URL}).*"
fi
echo ""
echo "<!-- BENCHMARK_RESULTS_END -->"
} > bench_block.txt
fi
perl -i -0pe '
my $block = do { open my $f, "bench_block.txt" or die; local $/; <$f> };
s|<!-- BENCHMARK_RESULTS_START -->.*?<!-- BENCHMARK_RESULTS_END -->|$block|gs;
' README.md
- name: Commit updated README
run: |
git config user.name "ElioNeto"
git config user.email "netoo.elio@hotmail.com"
git add README.md
if git diff --staged --quiet; then
echo "No README changes to commit."
exit 0
fi
git commit -m "docs: update benchmark results [skip ci]"
# Integrate remote changes, auto-resolve conflicts in our favor
if ! git pull --rebase -X ours origin main 2>/dev/null; then
echo "Rebase failed — skipping this update."
git rebase --abort 2>/dev/null || true
exit 0
fi
git push origin main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
report-status:
if: always()
needs: [benchmarks, lint]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Report job status
uses: ./.github/actions/ci-issue-manager
with:
workflow_name: "Benchmarks"
job_results: ${{ toJSON(needs) }}
repo_token: ${{ secrets.GITHUB_TOKEN }}
repository: ${{ github.repository }}
server_url: ${{ github.server_url }}
run_id: ${{ github.run_id }}
ref_name: ${{ github.ref_name }}
sha: ${{ github.sha }}