Skip to content

Commit ef2545e

Browse files
committed
✨ Added summary diff report
1 parent f6dadaf commit ef2545e

File tree

6 files changed

+168
-79
lines changed

6 files changed

+168
-79
lines changed

Diff for: β€ŽREADME.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
- run: forge test --gas-report > gasreport.ansi
3535

3636
- name: Compare gas reports
37-
uses: Rubilmax/foundry-gas-report@v3.1
37+
uses: Rubilmax/foundry-gas-report@v3.2
3838
with:
3939
workflowId: foundry-gas-report.yml # must be the name of the workflow file
4040
ignore: test/**/* # optionally filter out gas reports from specific paths

Diff for: β€Ždist/index.js

+71-33
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ const center = (text, length) => text.padStart((text.length + length) / 2).padEn
2222
const formatShellCell = (cell) => {
2323
const format = colors_1.default[cell.delta > 0 ? "red" : cell.delta < 0 ? "green" : "reset"];
2424
return [
25-
format((isNaN(cell.value) ? "-" : cell.value.toLocaleString()).padStart(10)),
26-
format((isNaN(cell.delta) ? "-" : plusSign(cell.delta) + cell.delta.toLocaleString()).padStart(10)),
27-
colors_1.default.bold(format((isNaN(cell.prcnt) ? "-" : plusSign(cell.prcnt) + cell.prcnt.toFixed(2) + "%").padStart(8))),
25+
format(cell.value.toLocaleString().padStart(10)),
26+
format((plusSign(cell.delta) + cell.delta.toLocaleString()).padStart(10)),
27+
colors_1.default.bold(format((plusSign(cell.prcnt) + cell.prcnt.toFixed(2) + "%").padStart(8))),
2828
];
2929
};
3030
exports.formatShellCell = formatShellCell;
@@ -82,55 +82,93 @@ const alignPattern = (align = TextAlign.LEFT) => {
8282
return ":-:";
8383
}
8484
};
85-
const formatMarkdownCell = (rows) => [
86-
rows.map((row) => (isNaN(row.value) ? "-" : row.value.toLocaleString())).join("<br />"),
85+
const formatMarkdownSummaryCell = (rows) => [
8786
rows
88-
.map((row) => (isNaN(row.delta) ? "-" : plusSign(row.delta) + row.delta.toLocaleString()) +
87+
.map((row) => plusSign(row.delta) +
88+
row.delta.toLocaleString() +
8989
(row.delta > 0 ? "❌" : row.delta < 0 ? "βœ…" : "βž–"))
9090
.join("<br />"),
91+
rows.map((row) => "**" + plusSign(row.prcnt) + row.prcnt.toFixed(2) + "%**").join("<br />"),
92+
];
93+
const formatMarkdownFullCell = (rows) => [
9194
rows
92-
.map((row) => "**" + (isNaN(row.prcnt) ? "-" : plusSign(row.prcnt) + row.prcnt.toFixed(2) + "%") + "**")
95+
.map((row) => row.value.toLocaleString() +
96+
"&nbsp;(" +
97+
plusSign(row.delta) +
98+
row.delta.toLocaleString() +
99+
(row.delta > 0 ? "❌" : row.delta < 0 ? "βœ…" : "βž–") +
100+
")")
93101
.join("<br />"),
102+
rows.map((row) => "**" + plusSign(row.prcnt) + row.prcnt.toFixed(2) + "%**").join("<br />"),
103+
];
104+
const MARKDOWN_SUMMARY_COLS = [
105+
{ txt: "" },
106+
{ txt: "Contract", align: TextAlign.LEFT },
107+
{ txt: "Method", align: TextAlign.LEFT },
108+
{ txt: "Avg (+/-)", align: TextAlign.RIGHT },
109+
{ txt: "%", align: TextAlign.RIGHT },
110+
{ txt: "" },
111+
];
112+
const MARKDOWN_DIFF_COLS = [
113+
{ txt: "" },
114+
{ txt: "Contract", align: TextAlign.LEFT },
115+
{ txt: "Method", align: TextAlign.LEFT },
116+
{ txt: "Min", align: TextAlign.RIGHT },
117+
{ txt: "%", align: TextAlign.RIGHT },
118+
{ txt: "Avg", align: TextAlign.RIGHT },
119+
{ txt: "%", align: TextAlign.RIGHT },
120+
{ txt: "Median", align: TextAlign.RIGHT },
121+
{ txt: "%", align: TextAlign.RIGHT },
122+
{ txt: "Max", align: TextAlign.RIGHT },
123+
{ txt: "%", align: TextAlign.RIGHT },
124+
{ txt: "" },
94125
];
95126
const formatMarkdownDiff = (title, diffs) => {
96-
const COLS = [
97-
{ txt: "" },
98-
{ txt: "Contract", align: TextAlign.LEFT },
99-
{ txt: "Method", align: TextAlign.LEFT },
100-
{ txt: "Min", align: TextAlign.RIGHT },
101-
{ txt: "(+/-)", align: TextAlign.RIGHT },
102-
{ txt: "%", align: TextAlign.RIGHT },
103-
{ txt: "Avg", align: TextAlign.RIGHT },
104-
{ txt: "(+/-)", align: TextAlign.RIGHT },
105-
{ txt: "%", align: TextAlign.RIGHT },
106-
{ txt: "Median", align: TextAlign.RIGHT },
107-
{ txt: "(+/-)", align: TextAlign.RIGHT },
108-
{ txt: "%", align: TextAlign.RIGHT },
109-
{ txt: "Max", align: TextAlign.RIGHT },
110-
{ txt: "(+/-)", align: TextAlign.RIGHT },
111-
{ txt: "%", align: TextAlign.RIGHT },
112-
{ txt: "" },
113-
];
114-
const header = COLS.map((entry) => entry.txt)
127+
const summaryHeader = MARKDOWN_SUMMARY_COLS.map((entry) => entry.txt)
128+
.join(" | ")
129+
.trim();
130+
const summaryHeaderSeparator = MARKDOWN_SUMMARY_COLS.map((entry) => entry.txt ? alignPattern(entry.align) : "")
131+
.join("|")
132+
.trim();
133+
const diffHeader = MARKDOWN_DIFF_COLS.map((entry) => entry.txt)
115134
.join(" | ")
116135
.trim();
117-
const contractSeparator = COLS.map((entry) => (entry.txt ? alignPattern(entry.align) : ""))
136+
const diffHeaderSeparator = MARKDOWN_DIFF_COLS.map((entry) => entry.txt ? alignPattern(entry.align) : "")
118137
.join("|")
119138
.trim();
120139
return [
121140
"# " + title,
122141
"",
123-
header,
124-
contractSeparator,
142+
"## Summary",
143+
"",
144+
summaryHeader,
145+
summaryHeaderSeparator,
146+
diffs
147+
.flatMap((diff) => [
148+
"",
149+
`**${diff.name}**`,
150+
diff.methods.map((method) => `_${method.name}_`).join("<br />"),
151+
...formatMarkdownSummaryCell(diff.methods.map((method) => method.avg)),
152+
"",
153+
]
154+
.join(" | ")
155+
.trim())
156+
.join("\n"),
157+
"---",
158+
"",
159+
"## Full diff report",
160+
"",
161+
diffHeader,
162+
diffHeaderSeparator,
125163
diffs
126164
.flatMap((diff) => [
127165
"",
128166
`**${diff.name}**`,
129167
diff.methods.map((method) => `_${method.name}_`).join("<br />"),
130-
...formatMarkdownCell(diff.methods.map((method) => method.min)),
131-
...formatMarkdownCell(diff.methods.map((method) => method.avg)),
132-
...formatMarkdownCell(diff.methods.map((method) => method.median)),
133-
...formatMarkdownCell(diff.methods.map((method) => method.max)),
168+
...formatMarkdownFullCell(diff.methods.map((method) => method.min)),
169+
...formatMarkdownFullCell(diff.methods.map((method) => method.avg)),
170+
...formatMarkdownFullCell(diff.methods.map((method) => method.median)),
171+
...formatMarkdownFullCell(diff.methods.map((method) => method.max)),
134172
"",
135173
]
136174
.join(" | ")

Diff for: β€Ždist/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: β€Žpackage.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "foundry-gas-report",
3-
"version": "3.1.0",
3+
"version": "3.2.0",
44
"description": "Github Action reporting gas diff from Foundry reports",
55
"author": "Romain Milon (Rubilmax) <[email protected]>",
66
"license": "UNLICENSED",

Diff for: β€Žsrc/format.ts

+80-39
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,9 @@ export const formatShellCell = (cell: DiffCell) => {
1515
const format = colors[cell.delta > 0 ? "red" : cell.delta < 0 ? "green" : "reset"];
1616

1717
return [
18-
format((isNaN(cell.value) ? "-" : cell.value.toLocaleString()).padStart(10)),
19-
format(
20-
(isNaN(cell.delta) ? "-" : plusSign(cell.delta) + cell.delta.toLocaleString()).padStart(10)
21-
),
22-
colors.bold(
23-
format(
24-
(isNaN(cell.prcnt) ? "-" : plusSign(cell.prcnt) + cell.prcnt.toFixed(2) + "%").padStart(8)
25-
)
26-
),
18+
format(cell.value.toLocaleString().padStart(10)),
19+
format((plusSign(cell.delta) + cell.delta.toLocaleString()).padStart(10)),
20+
colors.bold(format((plusSign(cell.prcnt) + cell.prcnt.toFixed(2) + "%").padStart(8))),
2721
];
2822
};
2923

@@ -94,65 +88,112 @@ const alignPattern = (align = TextAlign.LEFT) => {
9488
}
9589
};
9690

97-
const formatMarkdownCell = (rows: DiffCell[]) => [
98-
rows.map((row) => (isNaN(row.value) ? "-" : row.value.toLocaleString())).join("<br />"),
91+
const formatMarkdownSummaryCell = (rows: DiffCell[]) => [
9992
rows
10093
.map(
10194
(row) =>
102-
(isNaN(row.delta) ? "-" : plusSign(row.delta) + row.delta.toLocaleString()) +
95+
plusSign(row.delta) +
96+
row.delta.toLocaleString() +
10397
(row.delta > 0 ? "❌" : row.delta < 0 ? "βœ…" : "βž–")
10498
)
10599
.join("<br />"),
100+
rows.map((row) => "**" + plusSign(row.prcnt) + row.prcnt.toFixed(2) + "%**").join("<br />"),
101+
];
102+
103+
const formatMarkdownFullCell = (rows: DiffCell[]) => [
106104
rows
107105
.map(
108106
(row) =>
109-
"**" + (isNaN(row.prcnt) ? "-" : plusSign(row.prcnt) + row.prcnt.toFixed(2) + "%") + "**"
107+
row.value.toLocaleString() +
108+
"&nbsp;(" +
109+
plusSign(row.delta) +
110+
row.delta.toLocaleString() +
111+
(row.delta > 0 ? "❌" : row.delta < 0 ? "βœ…" : "βž–") +
112+
")"
110113
)
111114
.join("<br />"),
115+
rows.map((row) => "**" + plusSign(row.prcnt) + row.prcnt.toFixed(2) + "%**").join("<br />"),
116+
];
117+
118+
const MARKDOWN_SUMMARY_COLS = [
119+
{ txt: "" },
120+
{ txt: "Contract", align: TextAlign.LEFT },
121+
{ txt: "Method", align: TextAlign.LEFT },
122+
{ txt: "Avg (+/-)", align: TextAlign.RIGHT },
123+
{ txt: "%", align: TextAlign.RIGHT },
124+
{ txt: "" },
125+
];
126+
127+
const MARKDOWN_DIFF_COLS = [
128+
{ txt: "" },
129+
{ txt: "Contract", align: TextAlign.LEFT },
130+
{ txt: "Method", align: TextAlign.LEFT },
131+
{ txt: "Min", align: TextAlign.RIGHT },
132+
{ txt: "%", align: TextAlign.RIGHT },
133+
{ txt: "Avg", align: TextAlign.RIGHT },
134+
{ txt: "%", align: TextAlign.RIGHT },
135+
{ txt: "Median", align: TextAlign.RIGHT },
136+
{ txt: "%", align: TextAlign.RIGHT },
137+
{ txt: "Max", align: TextAlign.RIGHT },
138+
{ txt: "%", align: TextAlign.RIGHT },
139+
{ txt: "" },
112140
];
113141

114142
export const formatMarkdownDiff = (title: string, diffs: DiffReport[]) => {
115-
const COLS = [
116-
{ txt: "" },
117-
{ txt: "Contract", align: TextAlign.LEFT },
118-
{ txt: "Method", align: TextAlign.LEFT },
119-
{ txt: "Min", align: TextAlign.RIGHT },
120-
{ txt: "(+/-)", align: TextAlign.RIGHT },
121-
{ txt: "%", align: TextAlign.RIGHT },
122-
{ txt: "Avg", align: TextAlign.RIGHT },
123-
{ txt: "(+/-)", align: TextAlign.RIGHT },
124-
{ txt: "%", align: TextAlign.RIGHT },
125-
{ txt: "Median", align: TextAlign.RIGHT },
126-
{ txt: "(+/-)", align: TextAlign.RIGHT },
127-
{ txt: "%", align: TextAlign.RIGHT },
128-
{ txt: "Max", align: TextAlign.RIGHT },
129-
{ txt: "(+/-)", align: TextAlign.RIGHT },
130-
{ txt: "%", align: TextAlign.RIGHT },
131-
{ txt: "" },
132-
];
143+
const summaryHeader = MARKDOWN_SUMMARY_COLS.map((entry) => entry.txt)
144+
.join(" | ")
145+
.trim();
146+
const summaryHeaderSeparator = MARKDOWN_SUMMARY_COLS.map((entry) =>
147+
entry.txt ? alignPattern(entry.align) : ""
148+
)
149+
.join("|")
150+
.trim();
133151

134-
const header = COLS.map((entry) => entry.txt)
152+
const diffHeader = MARKDOWN_DIFF_COLS.map((entry) => entry.txt)
135153
.join(" | ")
136154
.trim();
137-
const contractSeparator = COLS.map((entry) => (entry.txt ? alignPattern(entry.align) : ""))
155+
const diffHeaderSeparator = MARKDOWN_DIFF_COLS.map((entry) =>
156+
entry.txt ? alignPattern(entry.align) : ""
157+
)
138158
.join("|")
139159
.trim();
140160

141161
return [
142162
"# " + title,
143163
"",
144-
header,
145-
contractSeparator,
164+
"## Summary",
165+
"",
166+
summaryHeader,
167+
summaryHeaderSeparator,
168+
diffs
169+
.flatMap((diff) =>
170+
[
171+
"",
172+
`**${diff.name}**`,
173+
diff.methods.map((method) => `_${method.name}_`).join("<br />"),
174+
...formatMarkdownSummaryCell(diff.methods.map((method) => method.avg)),
175+
"",
176+
]
177+
.join(" | ")
178+
.trim()
179+
)
180+
.join("\n"),
181+
"---",
182+
"",
183+
"## Full diff report",
184+
"",
185+
diffHeader,
186+
diffHeaderSeparator,
146187
diffs
147188
.flatMap((diff) =>
148189
[
149190
"",
150191
`**${diff.name}**`,
151192
diff.methods.map((method) => `_${method.name}_`).join("<br />"),
152-
...formatMarkdownCell(diff.methods.map((method) => method.min)),
153-
...formatMarkdownCell(diff.methods.map((method) => method.avg)),
154-
...formatMarkdownCell(diff.methods.map((method) => method.median)),
155-
...formatMarkdownCell(diff.methods.map((method) => method.max)),
193+
...formatMarkdownFullCell(diff.methods.map((method) => method.min)),
194+
...formatMarkdownFullCell(diff.methods.map((method) => method.avg)),
195+
...formatMarkdownFullCell(diff.methods.map((method) => method.median)),
196+
...formatMarkdownFullCell(diff.methods.map((method) => method.max)),
156197
"",
157198
]
158199
.join(" | ")

Diff for: β€Žtests/mocks/output.md

+14-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
# Changes to gas costs
22

3-
| Contract | Method | Min | (+/-) | % | Avg | (+/-) | % | Median | (+/-) | % | Max | (+/-) | % |
4-
|:-|:-|-:|-:|-:|-:|-:|-:|-:|-:|-:|-:|-:|-:|
5-
| **Morpho** | _supply_ | 3,997 | 0βž– | **0.00%** | 371,586 | +809❌ | **+0.23%** | 395,247 | +995❌ | **+0.27%** | 2,125,764 | +304❌ | **+0.01%** |
6-
| **PositionsManager** | _supplyLogic_<br />_borrowLogic_ | 737<br />148,437 | 0βž–<br />0βž– | **0.00%**<br />**0.00%** | 365,894<br />542,977 | +849❌<br />+702❌ | **+0.25%**<br />**+0.13%** | 383,960<br />438,816 | +995❌<br />0βž– | **+0.27%**<br />**0.00%** | 2,121,294<br />1,090,968 | +304❌<br />0βž– | **+0.01%**<br />**0.00%** |
3+
## Summary
4+
5+
| Contract | Method | Avg (+/-) | % |
6+
|:-|:-|-:|-:|
7+
| **Morpho** | _supply_ | +809❌ | **+0.23%** |
8+
| **PositionsManager** | _supplyLogic_<br />_borrowLogic_ | +849❌<br />+702❌ | **+0.25%**<br />**+0.13%** |
9+
---
10+
11+
## Full diff report
12+
13+
| Contract | Method | Min | % | Avg | % | Median | % | Max | % |
14+
|:-|:-|-:|-:|-:|-:|-:|-:|-:|-:|
15+
| **Morpho** | _supply_ | 3,997&nbsp;(0βž–) | **0.00%** | 371,586&nbsp;(+809❌) | **+0.23%** | 395,247&nbsp;(+995❌) | **+0.27%** | 2,125,764&nbsp;(+304❌) | **+0.01%** |
16+
| **PositionsManager** | _supplyLogic_<br />_borrowLogic_ | 737&nbsp;(0βž–)<br />148,437&nbsp;(0βž–) | **0.00%**<br />**0.00%** | 365,894&nbsp;(+849❌)<br />542,977&nbsp;(+702❌) | **+0.25%**<br />**+0.13%** | 383,960&nbsp;(+995❌)<br />438,816&nbsp;(0βž–) | **+0.27%**<br />**0.00%** | 2,121,294&nbsp;(+304❌)<br />1,090,968&nbsp;(0βž–) | **+0.01%**<br />**0.00%** |

0 commit comments

Comments
Β (0)