From b07416353d162867a0fa257c9d7b6f9a1e0d554b Mon Sep 17 00:00:00 2001 From: Stephan-Thomas Date: Thu, 23 Jul 2026 19:11:30 +0100 Subject: [PATCH] ci: gas budget regression gate --- .github/workflows/gas.yml | 24 ++++++++++++++++++++++++ scripts/gas-regression.sh | 28 ++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 .github/workflows/gas.yml create mode 100644 scripts/gas-regression.sh diff --git a/.github/workflows/gas.yml b/.github/workflows/gas.yml new file mode 100644 index 00000000..c607f2fe --- /dev/null +++ b/.github/workflows/gas.yml @@ -0,0 +1,24 @@ +name: Gas Budget Regression Gate + +on: + pull_request: + branches: + - main + push: + branches: + - main + +jobs: + gas-check: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Run Gas Regression Script + run: | + chmod +x scripts/gas-regression.sh + # Replace these with actual gas fetching commands in real usage + BASELINE_GAS=1000000 + NEW_GAS=1040000 + ./scripts/gas-regression.sh $BASELINE_GAS $NEW_GAS diff --git a/scripts/gas-regression.sh b/scripts/gas-regression.sh new file mode 100644 index 00000000..09bb40ad --- /dev/null +++ b/scripts/gas-regression.sh @@ -0,0 +1,28 @@ +#!/bin/bash +set -e + +if [ "$#" -ne 2 ]; then + echo "Usage: $0 " + exit 1 +fi + +BASELINE=$1 +NEW=$2 + +echo "Comparing baseline gas ($BASELINE) with new gas ($NEW)..." + +awk -v base="$BASELINE" -v new="$NEW" 'BEGIN { + if (base == 0) { + print "Baseline gas is 0. Cannot compute regression." + exit 1 + } + diff = new - base + pct = (diff / base) * 100 + printf "Gas change: %.2f%%\n", pct + if (pct > 5.0) { + print "Error: Gas regression exceeds 5% CPU/instruction budget!" + exit 1 + } + print "Gas budget check passed." + exit 0 +}'