name: Benchmark Regression Gate on: pull_request: branches: [main] push: branches: [main] jobs: benchmark: name: RPS Regression Check runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: fetch-depth: 0 - name: Install Rust uses: dtolnay/rust-toolchain@stable - name: Cache cargo registry uses: actions/cache@v4 with: path: | ~/.cargo/registry ~/.cargo/git target key: ${{ runner.os }}-cargo-bench-${{ hashFiles('**/Cargo.lock') }} - name: Run Regression Check run: | # 1. Build and run on PR branch cargo build --release -p justapi-bench --bin justapi-bench cargo run --release -p justapi-bench --bin justapi-bench -- --duration 10 > pr_bench.txt PR_RPS=$(grep -oP '\K[0-9]+(?= ops/sec)' pr_bench.txt || echo "0") # 2. Checkout main branch and run git checkout main cargo build --release -p justapi-bench --bin justapi-bench cargo run --release -p justapi-bench --bin justapi-bench -- --duration 10 > main_bench.txt MAIN_RPS=$(grep -oP '\K[0-9]+(?= ops/sec)' main_bench.txt || echo "0") echo "Main RPS: $MAIN_RPS" echo "PR RPS: $PR_RPS" if [ "$MAIN_RPS" -eq 0 ]; then echo "Failed to extract main RPS" exit 1 fi # 3. Compare (Fail if PR_RPS < 0.95 * MAIN_RPS) THRESHOLD=$(echo "$MAIN_RPS * 0.95" | bc | cut -d. -f1) if [ "$PR_RPS" -lt "$THRESHOLD" ]; then echo "RPS dropped by >5%! Expected at least $THRESHOLD, got $PR_RPS" exit 1 else echo "RPS is within acceptable bounds." fi