feat: add isValid, fitsEncoded helpers and fix ceil overflow #47
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Gas Badges | |
| on: | |
| push: | |
| branches: [main] | |
| permissions: | |
| contents: write | |
| jobs: | |
| gas-badges: | |
| name: Generate gas savings badges | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install Foundry | |
| uses: foundry-rs/foundry-toolchain@v1 | |
| with: | |
| cache: true | |
| - name: Install dependencies | |
| run: forge soldeer install | |
| - name: Run showcase gas benchmark | |
| run: | | |
| set -o pipefail | |
| forge test --match-path test/showcase/ShowcaseGas.t.sol --gas-report -vv | tee gas_report.txt | |
| - name: Generate badge endpoint JSON | |
| run: | | |
| set -euo pipefail | |
| raw_staking=$(grep -A 20 'RawETHStakingShowcase Contract' gas_report.txt | grep '| stake ' | awk -F'|' '{gsub(/ /,"",$3); print $3}' | head -n 1) | |
| quant_staking=$(grep -A 20 'QuantizedETHStakingShowcase Contract' gas_report.txt | grep '| stake ' | awk -F'|' '{gsub(/ /,"",$3); print $3}' | head -n 1) | |
| raw_extreme=$(grep -A 20 'RawExtremePackingShowcase Contract' gas_report.txt | grep '| setExtremeRaw ' | awk -F'|' '{gsub(/ /,"",$3); print $3}' | head -n 1) | |
| quant_extreme=$(grep -A 20 'QuantizedExtremePackingShowcase Contract' gas_report.txt | grep '| setExtremeFloor ' | awk -F'|' '{gsub(/ /,"",$3); print $3}' | head -n 1) | |
| for value in "$raw_staking" "$quant_staking" "$raw_extreme" "$quant_extreme"; do | |
| [[ "$value" =~ ^[0-9]+$ ]] || { echo "Failed to parse gas report value: '$value'"; exit 1; } | |
| done | |
| (( raw_staking > 0 && raw_extreme > 0 )) || { echo "Raw gas values must be greater than zero."; exit 1; } | |
| staking_pct=$(awk -v raw="$raw_staking" -v quant="$quant_staking" 'BEGIN { printf "%.1f", (1 - quant / raw) * 100 }') | |
| extreme_pct=$(awk -v raw="$raw_extreme" -v quant="$quant_extreme" 'BEGIN { printf "%.1f", (1 - quant / raw) * 100 }') | |
| mkdir -p .badges | |
| cat > .badges/staking-savings.json <<EOF | |
| { | |
| "schemaVersion": 1, | |
| "label": "staking case: gas usage reduction", | |
| "message": "${staking_pct}%", | |
| "color": "brightgreen" | |
| } | |
| EOF | |
| cat > .badges/extreme-savings.json <<EOF | |
| { | |
| "schemaVersion": 1, | |
| "label": "extreme case: gas usage reduction", | |
| "message": "${extreme_pct}%", | |
| "color": "brightgreen" | |
| } | |
| EOF | |
| - name: Push badge data to gh-badges branch | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| rm -rf /tmp/gh-badges | |
| mkdir -p /tmp/gh-badges/.badges | |
| cp .badges/*.json /tmp/gh-badges/.badges/ | |
| cd /tmp/gh-badges | |
| git init | |
| git checkout --orphan gh-badges | |
| git add .badges/*.json | |
| git -c user.name='github-actions[bot]' -c user.email='41898282+github-actions[bot]@users.noreply.github.com' commit -m "Update gas savings badges" | |
| git remote add origin "https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" | |
| git push --force origin gh-badges:gh-badges |