Skip to content

Commit 2654e7b

Browse files
committed
📝 Improve documentation
1 parent ff6f3a7 commit 2654e7b

File tree

1 file changed

+38
-3
lines changed

1 file changed

+38
-3
lines changed

README.md

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,20 @@
22

33
Easily generate & compare gas reports automatically generated by Foundry on each of your Pull Requests!
44

5+
## How it works
6+
7+
Everytime somebody opens a Pull Request, the action expects [Foundry](https://github.com/foundry-rs/foundry) `forge` to run a test suite, generating a gas report to a temporary file (named `gasreport.ansi` by default).
8+
9+
Once generated, the action will fetch the comparative gas report stored as an artifact from previous runs; parse & compare them, storing the results in the action's outputs as shell and as markdown.
10+
11+
You can then do whatever you want with the results!
12+
13+
> **Our recommandation:** Automatically submit a sticky comment displaying the gas diff!
14+
515
## Live Example
616

17+
---
18+
719
### Changes to gas costs
820

921
#### 🧾 Summary
@@ -26,6 +38,8 @@ Easily generate & compare gas reports automatically generated by Foundry on each
2638

2739
</details>
2840

41+
---
42+
2943
## Getting started
3044

3145
### Automatically generate a gas report diff on every PR
@@ -42,15 +56,24 @@ on:
4256
pull_request:
4357
# Optionally configure to run only for specific files. For example:
4458
# paths:
45-
# - "src/**"
59+
# - src/**
4660

4761
jobs:
4862
compare_gas_reports:
4963
runs-on: ubuntu-latest
5064
steps:
5165
- uses: actions/checkout@v3
5266

53-
# Add any build steps here. For example:
67+
- name: Install Foundry
68+
uses: onbjerg/foundry-toolchain@v1
69+
with:
70+
version: nightly
71+
72+
- name: Install Dependencies
73+
run: forge install
74+
75+
# Add any step generating a gas report to a temporary file named gasreport.ansi (can be changed)
76+
# For example:
5477
- run: forge test --gas-report > gasreport.ansi
5578

5679
- name: Compare gas reports
@@ -68,6 +91,10 @@ jobs:
6891
message: ${{ steps.gas_diff.outputs.markdown }}
6992
```
7093
94+
> :information_source: **An error will appear at first run!**<br/>
95+
> 🔴 <em>**Error:** No workflow run found with an artifact named "main.gasreport.ansi"</em><br/>
96+
> As the action is expecting a comparative file stored on the base branch and cannot find it (because the action never ran on the target branch and thus has never uploaded any gas report)
97+
7198
## Options
7299
73100
### `workflowId` _{string}_ (required)
@@ -78,7 +105,7 @@ thus it should correspond to the ID of the workflow this action is defined in: `
78105

79106
### `token` _{string}_
80107

81-
The github token allowing the action to upload and download gas reports generated by foundry.
108+
The github token allowing the action to upload and download gas reports generated by foundry. You should not need to customize this, as the action already has access to the default Github Action token.
82109

83110
_Defaults to: `${{ github.token }}`_
84111

@@ -121,6 +148,14 @@ This allows to only display gas diff of specific contracts.
121148

122149
_No default assigned: optional opt-in_
123150

151+
## ⚠️ Known limitations
152+
153+
> **Library gas reports**<br/>
154+
> Forge does not generate library gas reports. You need to wrap their usage in a contract calling the library to be able to compare gas costs of calling the library.
155+
156+
> **Average gas cost estimation**<br/>
157+
> Average & median gas costs for each function is estimated based on the test suite, which means they are easily impacted by small changes in the tests. We recommend using a separate, specific test suite, rarily updated, designed to perform accurate gas estimations.
158+
124159
## Status
125160

126161
![Status: Experimental](https://img.shields.io/badge/Status-Experimental-blue)

0 commit comments

Comments
 (0)