@@ -206,4 +206,81 @@ jobs:
206
206
207
207
if [ $FAILED -eq 1 ]; then
208
208
exit 1
209
- fi
209
+ fi
210
+
211
+ # -----------------------------------------------------------------------
212
+ # Forge Size Diff
213
+ # -----------------------------------------------------------------------
214
+
215
+ compare-contract-sizes :
216
+ name : Size Diff
217
+ runs-on : ubuntu-latest
218
+ steps :
219
+ # Check out repository with all submodules for complete codebase access.
220
+ - uses : actions/checkout@v4
221
+ with :
222
+ submodules : recursive
223
+
224
+ # Install the Foundry toolchain.
225
+ - name : " Install Foundry"
226
+ uses : foundry-rs/foundry-toolchain@v1
227
+ with :
228
+ version : stable
229
+
230
+ - name : Build contracts on PR branch
231
+ run : |
232
+ forge build --json --sizes | jq '.' > pr_sizes.json
233
+
234
+ - name : Checkout target branch
235
+ run : |
236
+ git fetch origin ${{ github.base_ref }}
237
+ git checkout ${{ github.base_ref }}
238
+
239
+ - name : Build contracts on target branch
240
+ run : |
241
+ forge build --json --sizes | jq '.' > target_sizes.json
242
+
243
+ - name : Compare contract sizes using Bash
244
+ run : |
245
+ # Extract contract names
246
+ contracts=$(jq -r 'keys[]' pr_sizes.json)
247
+
248
+ # Track if there are any differences
249
+ has_differences=0
250
+
251
+ echo -e "\nπ \033[1;34mContract Size Comparison Report\033[0m π\n"
252
+
253
+ # Iterate through contracts and compare sizes
254
+ for contract in $contracts; do
255
+ pr_runtime=$(jq -r --arg contract "$contract" '.[$contract].runtime_size // 0' pr_sizes.json)
256
+ pr_init=$(jq -r --arg contract "$contract" '.[$contract].init_size // 0' pr_sizes.json)
257
+
258
+ target_runtime=$(jq -r --arg contract "$contract" '.[$contract].runtime_size // 0' target_sizes.json)
259
+ target_init=$(jq -r --arg contract "$contract" '.[$contract].init_size // 0' target_sizes.json)
260
+
261
+ runtime_diff=$((pr_runtime - target_runtime))
262
+ init_diff=$((pr_init - target_init))
263
+
264
+ if [ "$runtime_diff" -ne 0 ] || [ "$init_diff" -ne 0 ]; then
265
+ echo -e "\033[1;36mπ $contract:\033[0m"
266
+ if [ "$runtime_diff" -ne 0 ]; then
267
+ if [ "$runtime_diff" -gt 0 ]; then
268
+ echo -e " Runtime: \033[1;31m+$runtime_diff bytes\033[0m π"
269
+ else
270
+ echo -e " Runtime: \033[1;32m$runtime_diff bytes\033[0m π"
271
+ fi
272
+ fi
273
+ if [ "$init_diff" -ne 0 ]; then
274
+ if [ "$init_diff" -gt 0 ]; then
275
+ echo -e " Init: \033[1;31m+$init_diff bytes\033[0m π"
276
+ else
277
+ echo -e " Init: \033[1;32m$init_diff bytes\033[0m π"
278
+ fi
279
+ fi
280
+ has_differences=1
281
+ fi
282
+ done
283
+
284
+ if [ "$has_differences" -eq 0 ]; then
285
+ echo -e "\033[1;32mβ¨ No contract size changes detected β¨\033[0m"
286
+ fi
0 commit comments