You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+38-3Lines changed: 38 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,8 +2,20 @@
2
2
3
3
Easily generate & compare gas reports automatically generated by Foundry on each of your Pull Requests!
4
4
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
+
5
15
## Live Example
6
16
17
+
---
18
+
7
19
### Changes to gas costs
8
20
9
21
#### 🧾 Summary
@@ -26,6 +38,8 @@ Easily generate & compare gas reports automatically generated by Foundry on each
26
38
27
39
</details>
28
40
41
+
---
42
+
29
43
## Getting started
30
44
31
45
### Automatically generate a gas report diff on every PR
@@ -42,15 +56,24 @@ on:
42
56
pull_request:
43
57
# Optionally configure to run only for specific files. For example:
44
58
# paths:
45
-
# - "src/**"
59
+
# - src/**
46
60
47
61
jobs:
48
62
compare_gas_reports:
49
63
runs-on: ubuntu-latest
50
64
steps:
51
65
- uses: actions/checkout@v3
52
66
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:
54
77
- run: forge test --gas-report > gasreport.ansi
55
78
56
79
- name: Compare gas reports
@@ -68,6 +91,10 @@ jobs:
68
91
message: ${{ steps.gas_diff.outputs.markdown }}
69
92
```
70
93
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
+
71
98
## Options
72
99
73
100
### `workflowId` _{string}_ (required)
@@ -78,7 +105,7 @@ thus it should correspond to the ID of the workflow this action is defined in: `
78
105
79
106
### `token` _{string}_
80
107
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.
82
109
83
110
_Defaults to: `${{ github.token }}`_
84
111
@@ -121,6 +148,14 @@ This allows to only display gas diff of specific contracts.
121
148
122
149
_No default assigned: optional opt-in_
123
150
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.
0 commit comments