-
Notifications
You must be signed in to change notification settings - Fork 123
151 lines (135 loc) · 5.16 KB
/
Copy pathgas-benchmarks.yml
File metadata and controls
151 lines (135 loc) · 5.16 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
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"
=======
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