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

[Proposal] Automate pre-commit and pre-push checks #775

Merged
merged 15 commits into from
May 7, 2024

Conversation

elatoskinas
Copy link
Collaborator

@elatoskinas elatoskinas commented Apr 29, 2024

Motivation

Proposal to automate pre-commit and pre-push contracts development tasks by automatically running the required commands. The benefits of the setup are:

  • Automation of manual tasks that are easy to miss / forget during dev time
  • Better visibility to new developers to familiarise with the required post-dev commands & clean-up
  • Reduced CI failures due to local checks being mandated
  • Ability to skip checks at any time (using --no-verify), making the checks less intrusive
  • Optional suggestions that can be skipped (e.g. snapshot generation)

Solution

  • husky to implement git workflow hooks

  • lint-staged to automatically apply changes on files pre-commit

  • pre-commit hook: runs lint-staged which automatically applies & commits forge fmt changes to all Solidity files

  • pre-push hook: build, test, solhint, optional wrapper / snapshot generation and changeset verification. If any of the commands fail, the pushing is stopped

    • Note: if a snapshot & wrappers are generated, it requires running git push --no-verify again due to a git workflow limitation)

How it works:

  1. After running pnpm i, pnpm prepare is ran automatically, which setups husky
  2. On git commit, husky intercepts the pre-commit event, and runs .husky/pre-commit, which then runs lint-staged on all detected files
  3. On git push, husky intercepts the pre-push event, and runs .husky/pre-push, which executes all commands in the script

Additional features:

  • Hooks are opt-in via .env file configurations
  • The hooks work on GUI git solutions, by making use of the .env file

TODOs

  • Add changeset check
  • Git desktop compatibility
  • Opt-in hooks
  • Implement changes to skip pre-commit & pre-push hooks when a subdirectory did not change (see SO)
  • CI compatibility fixes (skip husky prepare)
  • Documentation and README

Copy link
Contributor

github-actions bot commented May 1, 2024

Go solidity wrappers are out-of-date, regenerate them via the make wrappers-all command

Copy link
Contributor

github-actions bot commented May 1, 2024

Go solidity wrappers are out-of-date, regenerate them via the make wrappers-all command

Copy link
Contributor

github-actions bot commented May 2, 2024

Go solidity wrappers are out-of-date, regenerate them via the make wrappers-all command

Copy link
Contributor

github-actions bot commented May 2, 2024

Go solidity wrappers are out-of-date, regenerate them via the make wrappers-all command

1 similar comment
Copy link
Contributor

github-actions bot commented May 2, 2024

Go solidity wrappers are out-of-date, regenerate them via the make wrappers-all command

@elatoskinas elatoskinas force-pushed the setup-husky-hooks branch from 7445ae2 to 6f330aa Compare May 2, 2024 17:28
@elatoskinas elatoskinas marked this pull request as ready for review May 3, 2024 11:44
if [ "$snapshot_answer" != "${snapshot_answer#[Yy]}" ] ;then
# Create gas snapshot & commit gas snapshot
make snapshot
make wrappers
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Note: there's a great solution that was recently implemented in core - generating wrappers on CI - which I would love to pull in from the next PR.

This could be adopted to also generate snapshots and (possibly) apply formatting changes.

However, there are still some actions that benefit from a pre-push check (build, test, solhint and changeset verification) - since these require manual intervention.

Copy link
Contributor

github-actions bot commented May 3, 2024

LCOV of commit ca70fc4 during Solidity Foundry #4033

Summary coverage rate:
  lines......: 98.8% (1037 of 1050 lines)
  functions..: 96.1% (221 of 230 functions)
  branches...: 91.2% (405 of 444 branches)

Files changed coverage rate: n/a

@@ -1,1061 +1,56 @@
lockfileVersion: '9.0'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ahh this one uses pnpm 9 and the other <9.... we need to align on a single version for all lockfiles. Ideally whatever we have from chainlink

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Seems like it's 6.0 in chainlink

@elatoskinas elatoskinas merged commit a6466bd into ccip-develop May 7, 2024
85 checks passed
@elatoskinas elatoskinas deleted the setup-husky-hooks branch May 7, 2024 10:23
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