-
Notifications
You must be signed in to change notification settings - Fork 0
79 lines (64 loc) · 2.38 KB
/
Copy pathgas-badges.yml
File metadata and controls
79 lines (64 loc) · 2.38 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
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 -vv | tee gas_output.txt
- name: Generate badge endpoint JSON
run: |
set -euo pipefail
extract() { grep "$1" gas_output.txt | awk '{print $NF}'; }
staking_bps=$(extract "staking strict savings bps")
extreme_bps=$(extract "extreme strict savings bps")
for value in "$staking_bps" "$extreme_bps"; do
[[ "$value" =~ ^[0-9]+$ ]] || { echo "Failed to parse: '$value'"; exit 1; }
done
staking_pct=$(awk -v bps="$staking_bps" 'BEGIN { printf "%.1f", bps / 100 }')
extreme_pct=$(awk -v bps="$extreme_bps" 'BEGIN { printf "%.1f", bps / 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