From 50904e5223f7a8218fd8ddc7700664db5b73879b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Federico=20Mart=C3=ADn=20Alconada=20Verzini?= Date: Fri, 5 Jan 2024 09:36:49 -0300 Subject: [PATCH] feat: add gas diff to CI workflow --- .github/workflows/gas-diff.yml | 57 ++++++++++++++++++++++++++++++ .github/workflows/pull_request.yml | 8 ++++- 2 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/gas-diff.yml diff --git a/.github/workflows/gas-diff.yml b/.github/workflows/gas-diff.yml new file mode 100644 index 00000000..c50257ce --- /dev/null +++ b/.github/workflows/gas-diff.yml @@ -0,0 +1,57 @@ +name: Report gas diff + +on: + workflow_call: +# on: +# push: +# branches: +# - main +# pull_request: +# # Optionally configure to run only for changes in specific files. For example: +# # paths: +# # - src/** +# # - test/** +# # - foundry.toml +# # - remappings.txt +# # - .github/workflows/foundry-gas-diff.yml + +jobs: + compare_gas_reports: + name: Compare + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + submodules: recursive + + - uses: ./.github/actions/install + + - name: Build contracts + run: forge build --sizes + + - name: Check gas snapshots + run: forge snapshot --diff + + - name: Run tests + run: forge test --gas-report > gasreport.ansi + env: + # make fuzzing semi-deterministic to avoid noisy gas cost estimation + # due to non-deterministic fuzzing (but still use pseudo-random fuzzing seeds) + FOUNDRY_FUZZ_SEED: 0x${{ github.event.pull_request.base.sha || github.sha }} + + - name: Compare gas reports + uses: Rubilmax/foundry-gas-diff@v3.16 + with: + summaryQuantile: 0.9 # only display the 10% most significant gas diffs in the summary (defaults to 20%) + sortCriteria: avg,max # sort diff rows by criteria + sortOrders: desc,asc # and directions + ignore: test-foundry/**/* # filter out gas reports from specific paths (test/ is included by default) + id: gas_diff + + - name: Add gas diff to sticky comment + if: github.event_name == 'pull_request' || github.event_name == 'pull_request_target' + uses: marocchino/sticky-pull-request-comment@v2 + with: + # delete the comment in case changes no longer impact gas costs + delete: ${{ !steps.gas_diff.outputs.markdown }} + message: ${{ steps.gas_diff.outputs.markdown }} \ No newline at end of file diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 2ac9da86..887092f5 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -22,4 +22,10 @@ jobs: analyse: name: Slither analysis uses: ./.github/workflows/slither.yml - secrets: inherit \ No newline at end of file + secrets: inherit + + gas-diff: + name: Gas diff + uses: ./.github/workflows/gas-diff.yml + secrets: inherit + \ No newline at end of file