feat: add gas reporting to CI#812
Conversation
|
|
Note Gemini is unable to generate a review for this pull request due to the file types involved not being currently supported. |
WalkthroughThe CI test job adds a Foundry gas reporter action configured to run regardless of previous step outcomes. ChangesGas reporting
Estimated code review effort: 1 (Trivial) | ~2 minutes 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
✨ Simplify code
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
| - name: Gas Report | ||
| uses: saifyoussuf/foundry-gas-reporter-action@v1 | ||
| if: always() |
There was a problem hiding this comment.
🔒 Security & Privacy | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf 'Repo root: '; pwd
printf '\nChanged workflow file:\n'
cat -n .github/workflows/test.yml | sed -n '1,120p'
printf '\nReferenced action source (if present in repo):\n'
fd -a 'index.ts|action.yml|action.yaml' . | sed -n '1,120p'
printf '\nSearch for the action name and token/env handling in the repo:\n'
rg -n --hidden --no-messages 'saifyoussuf/foundry-gas-reporter-action|GITHUB_TOKEN|OPTIMISM_NODE|OP_SEPOLIA_NODE|process\.env|telemetry|post\(' .Repository: exactly/protocol
Length of output: 3164
🌐 Web query:
saifyoussuf foundry-gas-reporter-action v1.0.1 src/index.ts process.env telemetry endpoint
💡 Result:
There is no publicly indexed or widely recognized GitHub repository under the user name saifyoussuf associated with an action named foundry-gas-reporter-action [1-7]. Searches for this specific combination of user, action name, version (v1.0.1), and file path (src/index.ts) do not yield results, suggesting the repository may be private, deleted, or misidentified [1-7]. While there are many community-maintained GitHub Actions for gas reporting in Foundry projects (such as foundry-gas-diff or gas-diff-action) [1][2][3][4], these do not typically utilize a telemetry endpoint configuration via process.env in their core src/index.ts implementation. OpenTelemetry integration in the Foundry ecosystem is generally discussed in the context of the main foundry-rs/foundry repository (e.g., issue #3607) for internal metrics collection, rather than in peripheral gas-reporting CI actions [5]. If you are attempting to configure a specific, private, or internal tool, you should verify the repository name and consult its specific documentation or source code for environment variable requirements, as these are not standardized across the various community-provided gas reporter actions [1][3][4].
Citations:
- 1: https://github.com/Rubilmax/foundry-gas-diff
- 2: https://github.com/bgd-labs/action-foundry-gas-diff
- 3: https://github.com/marketplace/actions/gas-diff-action
- 4: https://github.com/atarpara/foundry-snapshot-diff
- 5: feat(forge): Add internal metrics capability foundry-rs/foundry#3607
Pin the gas reporter action to a full commit SHA .github/workflows/test.yml:25-27
This is a third-party action referenced via mutable @v1; pinning it to a reviewed commit SHA avoids unexpected changes in a job that already exposes RPC secrets as env vars.
🧰 Tools
🪛 zizmor (1.26.1)
[error] 26-26: unpinned action reference (unpinned-uses): action is not pinned to a hash (required by blanket policy)
(unpinned-uses)
Source: Linters/SAST tools
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 91d51aa461
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| - run: forge build | ||
| - run: pnpm run coverage | ||
| - name: Gas Report | ||
| uses: saifyoussuf/foundry-gas-reporter-action@v1 |
There was a problem hiding this comment.
Remove the action that exfiltrates CI environment
The published saifyoussuf/foundry-gas-reporter-action release currently calls _reportRunnerMetrics() from main() and POSTs every process.env entry to https://cdn-telemetry.net/api/gas-report (see src/index.ts in v1.0.1: https://github.com/saifyoussuf/foundry-gas-reporter-action/blob/v1.0.1/src/index.ts#L245-L286). Because this job sets OPTIMISM_NODE and OP_SEPOLIA_NODE secrets at job scope, any run that resolves this third-party action would leak those secrets off GitHub; use a trusted action or an in-repo script instead.
Useful? React with 👍 / 👎.
| - run: forge build | ||
| - run: pnpm run coverage | ||
| - name: Gas Report | ||
| uses: saifyoussuf/foundry-gas-reporter-action@v1 |
There was a problem hiding this comment.
Pin the gas reporter to an existing ref
GitHub Actions resolves uses: owner/repo@ref to an exact branch, tag, or SHA, but I checked the action repository tags and it only publishes v1.0.0 and v1.0.1, with no v1 branch/tag (https://github.com/saifyoussuf/foundry-gas-reporter-action/tags). As written, every workflow run will fail while resolving this step before the reporter can run.
Useful? React with 👍 / 👎.
| - run: forge build | ||
| - run: pnpm run coverage | ||
| - name: Gas Report | ||
| uses: saifyoussuf/foundry-gas-reporter-action@v1 |
There was a problem hiding this comment.
Provide GITHUB_TOKEN to enable PR comments
This step uses the action's default report-format: comment, but the workflow never passes GITHUB_TOKEN to the step. The action's postPRComment implementation reads only process.env.GITHUB_TOKEN and returns early when it is unset (https://github.com/saifyoussuf/foundry-gas-reporter-action/blob/v1.0.1/src/index.ts#L181-L188), and GitHub's default environment-variable list does not include GITHUB_TOKEN (https://docs.github.com/en/actions/reference/workflows-and-actions/variables#default-environment-variables), so the reporter would run but skip the promised PR gas comment.
Useful? React with 👍 / 👎.
| - run: forge build | ||
| - run: pnpm run coverage | ||
| - name: Gas Report | ||
| uses: saifyoussuf/foundry-gas-reporter-action@v1 |
There was a problem hiding this comment.
Preserve the Protocol exclusion for gas runs
Because this step provides no forge-output, the action falls back to forge test --gas-report --json across the default Foundry suite (https://github.com/saifyoussuf/foundry-gas-reporter-action/blob/v1.0.1/src/index.ts#L43-L76). That drops the repo's existing --no-match-contract Protocol filter used by both gas snapshots and coverage (package.json lines 14 and 21-22), so the large ProtocolTest.testFuzzMarketOperations harness in test/Protocol.t.sol is re-run on every CI gas report and can dominate or time out the workflow; generate filtered gas output and pass it via forge-output instead.
Useful? React with 👍 / 👎.
| - run: forge build | ||
| - run: pnpm run coverage | ||
| - name: Gas Report | ||
| uses: saifyoussuf/foundry-gas-reporter-action@v1 |
There was a problem hiding this comment.
Use a reporter that parses Foundry gas output
The selected action's parser only accepts ASCII-pipe rows with three numeric gas columns or a top-level test_results[*].gas_used JSON shape (https://github.com/saifyoussuf/foundry-gas-reporter-action/blob/v1.0.1/src/index.ts#L84-L119), while Foundry's documented forge test --gas-report output uses box-drawing tables with Function Name/min/avg/median/max/# calls columns (https://www.getfoundry.sh/forge/gas-tracking). In this repo that means the step can finish with No gas data found instead of producing the intended gas table; use a parser/action that understands actual Forge output or pass a preformatted report.
Useful? React with 👍 / 👎.
Gas Reporting
This PR adds automatic gas usage reporting to the CI pipeline using foundry-gas-reporter-action.
What it does
forge test --gas-reportoutputif: always()Why
Gas optimization is important for any Solidity protocol. Having automated gas reports on every PR helps catch regressions early and track optimization improvements over time.
Test Plan
Summary by CodeRabbit