Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: add job to check contract sizes #60

Merged
merged 1 commit into from
Mar 14, 2024
Merged

Conversation

nicopernas
Copy link
Contributor

@nicopernas nicopernas commented Mar 11, 2024

Summary by CodeRabbit

  • New Features
    • Renamed GitHub Actions workflow to "Foundry."
    • Added a step to check contract sizes before running tests.

Copy link

coderabbitai bot commented Mar 11, 2024

Walkthrough

The change involves renaming the GitHub Actions workflow to "Foundry" and adding a step to check contract sizes before running tests. This enhancement aims to improve the workflow's functionality by incorporating a size constraint validation process for smart contracts, ensuring they meet specified limits for efficient resource management.

Changes

File Change Summary
.github/workflows/foundry.yml Changed workflow name to "Foundry" and added contract size check step
check_contracts_size.sh Parses forge build --sizes output to check contract sizes

Poem

🐰✨

In the realm of code, where smart contracts abide,
A rabbit hopped in, with a check to confide.
"Keep your contracts lean," it said with a smile,
For efficiency's sake, let's measure each file."
With actions and scripts, it danced through the night,
Ensuring the code was just perfectly light.
🌟📏🚀

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 7777f17 and 43dd83f.
Files selected for processing (2)
  • .github/workflows/contracts_size.yml (1 hunks)
  • check_contracts_size.sh (1 hunks)
Additional comments: 2
.github/workflows/contracts_size.yml (1)
  • 1-25: The GitHub Actions workflow is well-structured and aligns with the PR objectives to automate the process of contract size verification. It correctly triggers on pull requests and pushes to the main branch, checks out the code including submodules, installs the Foundry toolchain, and checks the contract sizes using the provided shell script. This addition to the CI pipeline is a proactive approach to ensuring that contracts remain within the size limits.
check_contracts_size.sh (1)
  • 1-28: The shell script is well-implemented with clear documentation, appropriate error handling, and a robust regex pattern for parsing the output of forge build --sizes. The logic to determine if a contract exceeds the allowed size limit is correctly implemented, making this script a valuable addition to the CI pipeline for ensuring contracts remain within size constraints.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 7777f17 and 390b0c2.
Files selected for processing (1)
  • .github/workflows/foundry.yml (2 hunks)
Additional comments: 2
.github/workflows/foundry.yml (2)
  • 1-1: The workflow name has been updated from "Tests" to "Foundry" to reflect the broader scope of tasks it now handles, including contract size checks and testing. This change improves clarity and aligns the workflow name with its expanded responsibilities.
  • 27-27: The "Tests" step remains unchanged and correctly positioned after the contract size check. This ordering ensures that contracts are only tested if they meet size constraints, optimizing the CI process by preventing unnecessary test runs on non-compliant contracts.

.github/workflows/foundry.yml Outdated Show resolved Hide resolved
Comment on lines 24 to 27
- name: Check contract sizes
run: forge build --sizes

- name: Tests
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought it would be nice to have "all foundry" commands under the same job, so we install the dependency only once. However, it also means that oversized contracts won't get the tests run... I guess that's ok but maybe someone else has strong opinions about it? @RnkSngh what do you think?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes I was also meaning to ask on if we should just lump everything with the same install dependencies under one job; so i think this is a good idea.

Does the forge build sizes actually throw on if we have contracts that are above the size limit? Is
that what we want here? I think some of the test contracts might be above the size limit as well so wondering if we can somehow exclude those

it also means that oversized contracts won't get the tests run

Wondering if we can have the forge test command go before forge build --sizes if we're worried about this then? I think forge test should build them, and since there are no changes to contracts, forge build--sizes will just use the already compiled contracts so it should be fine to have this go after

Comment on lines 24 to 27
- name: Check contract sizes
run: forge build --sizes

- name: Tests
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes I was also meaning to ask on if we should just lump everything with the same install dependencies under one job; so i think this is a good idea.

Does the forge build sizes actually throw on if we have contracts that are above the size limit? Is
that what we want here? I think some of the test contracts might be above the size limit as well so wondering if we can somehow exclude those

it also means that oversized contracts won't get the tests run

Wondering if we can have the forge test command go before forge build --sizes if we're worried about this then? I think forge test should build them, and since there are no changes to contracts, forge build--sizes will just use the already compiled contracts so it should be fine to have this go after

@@ -21,5 +21,8 @@ jobs:
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1

- name: Test
- name: Check contract sizes
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might also be worth adding forge coverage to the ci as well. right now forge coverage is throwing a compile error, but if we add the line src/=lib/optimism/packages/contracts-bedrock/src/ to remappings.txt file, its hould fix it (looks like it's some bug in the optimism library)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(thanks to @Inkvi for the suggestion)

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between fa7b730 and d29b280.
Files selected for processing (1)
  • .github/workflows/foundry.yml (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/foundry.yml

@nicopernas nicopernas merged commit a8b90f9 into main Mar 14, 2024
2 checks passed
@nicopernas nicopernas deleted the nico/check-contract-sizes branch March 14, 2024 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants