Skip to content

merge: resolve conflicts for PR #299 #218

merge: resolve conflicts for PR #299

merge: resolve conflicts for PR #299 #218

name: Gas Benchmark Suite
on:
push:
branches: ["main", "dev"]
paths:
- "stellar-lend/contracts/**"
- "stellar-lend/benchmarks/**"
- "scripts/gas_benchmark_report.py"
- ".github/workflows/gas-benchmarks.yml"
pull_request:
branches: ["main", "dev"]
paths:
- "stellar-lend/contracts/**"
- "stellar-lend/benchmarks/**"
- "scripts/gas_benchmark_report.py"
- ".github/workflows/gas-benchmarks.yml"
workflow_dispatch:
inputs:
compare_baseline:
description: "Compare against baseline and enforce the 10% regression gate"
required: false
default: "true"
=======

Check failure on line 24 in .github/workflows/gas-benchmarks.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/gas-benchmarks.yml

Invalid workflow file

You have an error in your yaml syntax on line 24
on: workflow_dispatch
>>>>>>> main
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
gas-benchmarks:
name: Gas Benchmarks
runs-on: ubuntu-latest
timeout-minutes: 30
env:
CARGO_TERM_COLOR: always
BENCHMARK_RESULTS: stellar-lend/benchmark-results.json
BENCHMARK_DASHBOARD: stellar-lend/benchmark-dashboard.md
BENCHMARK_HISTORY: stellar-lend/benchmark-history.jsonl
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
- name: Cache cargo registry and build artifacts
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
stellar-lend/target
key: ${{ runner.os }}-cargo-bench-${{ hashFiles('stellar-lend/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-bench-
${{ runner.os }}-cargo-
- name: Build benchmark suite
run: |
cd stellar-lend
cargo build -p stellarlend-benchmarks --release 2>&1 | tee benchmark-build.log
- name: Run gas benchmarks
run: |
cd stellar-lend
cargo run -p stellarlend-benchmarks --bin run_benchmarks --release -- \
--output benchmark-results.json \
2>&1 | tee benchmark-output.log
- name: Generate dashboard and enforce gates
env:
COMPARE_BASELINE: ${{ inputs.compare_baseline || 'true' }}
run: |
EXTRA_ARGS=""
if [ "$COMPARE_BASELINE" = "true" ]; then
EXTRA_ARGS="--baseline stellar-lend/benchmarks/baseline.json --fail-on-regression"
fi
python3 scripts/gas_benchmark_report.py \
--results "$BENCHMARK_RESULTS" \
--coverage stellar-lend/benchmarks/public-functions.json \
--dashboard "$BENCHMARK_DASHBOARD" \
--history stellar-lend/benchmarks/history.jsonl \
--history-out "$BENCHMARK_HISTORY" \
--max-regression-pct 10 \
$EXTRA_ARGS
- name: Publish benchmark dashboard
if: always()
run: |
if [ -f "$BENCHMARK_DASHBOARD" ]; then
cat "$BENCHMARK_DASHBOARD" >> "$GITHUB_STEP_SUMMARY"
fi
cd stellar-lend
if [ -f benchmark-results.json ]; then
echo "## Gas Benchmark Results" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Contract | Operations | Max Instructions | Avg Instructions | Over Budget |" >> $GITHUB_STEP_SUMMARY
echo "|----------|-----------|-----------------|-----------------|-------------|" >> $GITHUB_STEP_SUMMARY
python3 - <<'EOF'
import json, os
with open("benchmark-results.json") as f:
report = json.load(f)
summary = report.get("summary_by_contract", {})
with open(os.environ["GITHUB_STEP_SUMMARY"], "a") as out:
for contract, s in sorted(summary.items()):
over = s.get("over_budget_count", 0)
status = "✗" if over > 0 else "✓"
out.write(
f"| {contract} | {s['total_operations']} | "
f"{s['max_instructions']:,} | {s['avg_instructions']:,} | "
f"{status} {over} |\n"
)
total = report["total_benchmarks"]
passed = report["passed"]
failed = report["failed"]
out.write(f"\n**Total:** {total} | **Passed:** {passed} | **Failed:** {failed}\n")
EOF
# Also append markdown report to summary if available
if [ -f benchmark-results.md ]; then
echo "" >> $GITHUB_STEP_SUMMARY
echo "---" >> $GITHUB_STEP_SUMMARY
cat benchmark-results.md >> $GITHUB_STEP_SUMMARY
fi
fi
- name: Upload benchmark artifacts
if: always()
uses: actions/upload-artifact@v4
with:
name: gas-benchmark-results-${{ github.sha }}
path: |
stellar-lend/benchmark-results.json
stellar-lend/benchmark-dashboard.md
stellar-lend/benchmark-history.jsonl
stellar-lend/benchmark-results.md
stellar-lend/benchmarks/history.json
stellar-lend/benchmark-output.log
stellar-lend/benchmark-build.log
if-no-files-found: warn
retention-days: 90