Skip to content

chore: apply opencode boilerplate #55

chore: apply opencode boilerplate

chore: apply opencode boilerplate #55

Workflow file for this run

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: Run Benchmarks
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: clippy, rustfmt
- name: Cache cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-
- name: Build benchmarks
run: cargo build --benches --release
- name: Run benchmarks (CI mode)
run: |
cargo bench --bench write_bench --bench read_bench --bench scan_bench --bench mixed_bench --bench stress_bench -- --noplot 2>&1 | tee bench_output.txt
exit ${PIPESTATUS[0]}
continue-on-error: true
env:
CI: true
- name: Upload benchmark results
uses: actions/upload-artifact@v4
with:
name: benchmark-results
path: |
bench_output.txt
target/criterion
retention-days: 30
- name: Generate benchmark summary
if: github.event_name != 'pull_request'
run: |
DATE=$(date -u '+%Y-%m-%d %H:%M UTC')
RUN_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
# Guard: abort gracefully if bench_output.txt is missing or empty
if [ ! -s bench_output.txt ]; then
echo "⚠️ bench_output.txt ausente ou vazio — o benchmark pode ter travado ou falhado."
{
echo "<!-- BENCHMARK_RESULTS_START -->"
echo "> ⚠️ CI em **${DATE}** — benchmark não produziu resultados. [Ver 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
# Parse using Perl: handles multi-line Criterion output correctly.
# Criterion format:
# Line 1 (name line): "bench_name/param time: [low median high]"
# OR split across two lines:
# Line 1: "bench_name/param"
# Line 2: " time: [low median high]"
# Strategy: collect name from lines that look like bench names (no leading space,
# contain word chars + optional /param), then extract median from the time: [...] line.
ROWS=$(perl -ne '
# Match standalone benchmark name line (no leading whitespace, ends with word/number)
if (/^([a-zA-Z]\S+(?:\/\S+)?)\s*$/) {
$name = $1;
}
# Match inline: "bench_name/param time: [low median high]"
elsif (/^([a-zA-Z]\S+(?:\/\S+)?)\s+time:\s+\[([^\]]+)\]/) {
$name = $1;
my @vals = split(/\s+/, $2);
# median is index 2 (0=low_val, 1=low_unit, 2=med_val, 3=med_unit)
my $median = "$vals[2] $vals[3]";
$median =~ s/^\s+|\s+$//g;
print "| `$name` | $median |\n";
$name = "";
}
# Match timing on its own line (after name was set)
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)
# Build the full block
{
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
# Inject block into README between markers
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
if: github.event_name != 'pull_request'
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]"
git pull --rebase origin main
git push origin main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Run clippy on benchmarks
run: cargo clippy --all-targets -- -D warnings
- name: Format check
run: cargo fmt --all -- --check