Skip to content

Commit 2f0c381

Browse files
authored
BM-309: Add gas-comparison workflow (#125)
1 parent 00d50a5 commit 2f0c381

File tree

3 files changed

+99
-1
lines changed

3 files changed

+99
-1
lines changed

.github/workflows/gas-comparison.yml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
name: Gas comparison
2+
3+
on:
4+
pull_request:
5+
branches: [main]
6+
workflow_dispatch:
7+
8+
concurrency:
9+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
10+
cancel-in-progress: true
11+
12+
permissions:
13+
contents: read
14+
pull-requests: write
15+
16+
env:
17+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
18+
19+
jobs:
20+
files-changed:
21+
runs-on: ubuntu-latest
22+
outputs:
23+
contracts: ${{ steps.changes.outputs.contracts }}
24+
steps:
25+
- name: checkout code
26+
uses: actions/checkout@v4
27+
28+
- uses: dorny/[email protected]
29+
id: changes
30+
with:
31+
filters: |
32+
src:
33+
- 'contracts/src/**'
34+
- 'foundry.toml'
35+
36+
gas-comparison:
37+
runs-on: [self-hosted, Linux, X64, prod, cpu]
38+
needs: files-changed
39+
if: needs.files-changed.outputs.contracts == 'true'
40+
steps:
41+
- name: checkout code
42+
uses: actions/checkout@v4
43+
with:
44+
submodules: recursive
45+
46+
- name: install foundry
47+
uses: foundry-rs/foundry-toolchain@v1
48+
49+
- name: Run gas report on PR branch
50+
run: |
51+
forge test --gas-report | grep "|" > pr-gas-report.txt
52+
53+
- name: Upload PR Gas Report
54+
uses: actions/upload-artifact@v3
55+
with:
56+
name: pr-gas-report
57+
path: pr-gas-report.txt
58+
59+
- name: checkout code
60+
uses: actions/checkout@v4
61+
with:
62+
ref: main
63+
submodules: recursive
64+
65+
- name: Run gas report on main branch
66+
run: |
67+
forge test --gas-report | grep "|" > main-gas-report.txt
68+
69+
- name: Download PR Gas Report
70+
uses: actions/download-artifact@v3
71+
with:
72+
name: pr-gas-report
73+
path: .
74+
75+
- name: Compare Gas Reports
76+
run: |
77+
echo "# Gas Cost Comparison for `${GITHUB_HEAD_REF}` vs `main`" > gas-comparison.md
78+
echo "" >> gas-comparison.md
79+
echo '```diff' >> gas-comparison.md
80+
81+
# Use diff to capture changes in gas costs
82+
diff -u main-gas-report.txt pr-gas-report.txt >> gas-comparison.md || true
83+
84+
echo '```' >> gas-comparison.md
85+
echo "" >> gas-comparison.md
86+
cat gas-comparison.md
87+
88+
- name: Post Comment on Pull Request
89+
run: |
90+
COMMENT_BODY=$(cat gas-comparison.md)
91+
COMMENT_PAYLOAD=$(jq -n --arg body "$COMMENT_BODY" '{body: $body}')
92+
PR_NUMBER=${{ github.event.pull_request.number }}
93+
curl -s -H "Authorization: token $GITHUB_TOKEN" \
94+
-H "Content-Type: application/json" \
95+
-X POST \
96+
-d "$COMMENT_PAYLOAD" \
97+
"https://api.github.com/repos/${{ github.repository }}/issues/$PR_NUMBER/comments"

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,4 +315,4 @@ jobs:
315315
run: docker buildx create --driver docker-container --use
316316

317317
- name: docker compose build
318-
run: docker compose --profile broker --env-file ./.env-compose -f compose.yml -f ./dockerfiles/compose.ci.yml build
318+
run: docker compose --profile broker --env-file ./.env-compose -f compose.yml -f ./dockerfiles/compose.ci.yml build

foundry.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ optimizer_runs = 10000
1414
ast = true
1515
build_info = true
1616
extra_output = ["storageLayout"]
17+
gas_reports = ["ProofMarket"]
1718

1819
# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options
1920

0 commit comments

Comments
 (0)