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

chore: pre-commit hook to warn of constant.nr change #11507

Merged
merged 3 commits into from
Jan 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ hooks_dir=$(git rev-parse --git-path hooks)
echo "(cd barretenberg/cpp && ./format.sh staged)" >$hooks_dir/pre-commit
echo "./yarn-project/precommit.sh" >>$hooks_dir/pre-commit
echo "./noir-projects/precommit.sh" >>$hooks_dir/pre-commit
echo "./yarn-project/circuits.js/precommit.sh" >>$hooks_dir/pre-commit
chmod +x $hooks_dir/pre-commit

github_group "pull submodules"
Expand Down
32 changes: 32 additions & 0 deletions yarn-project/circuits.js/precommit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash

# Precommit hook simply to warn the user that they've staged a change to constants.nr.
# Longer-term, there might be a more-robust solution, but the goal of this script is
# simply to warn devs, so that they don't forget to regenerate the constants.
# Lots of hours lost to people forgetting to regenerate all the downstream constants.
# This script DOES NOT regenerate the constants, because there's too much to build.
# In the case where they've already generated and staged all the constant files of
# this commit, they'll have to cope with this small bit of noise.

#!/bin/bash
set -euo pipefail # Fail on errors, unset variables, and pipeline failures

cd "$(dirname "$0")" # Change to the script's directory

export FORCE_COLOR=true

FILE_TO_WATCH="noir-projects/noir-protocol-circuits/crates/types/src/constants.nr"

# Check if constants.nr is staged for commit
if git diff --cached --name-only | grep -Fxq "$FILE_TO_WATCH"; then
echo "It looks like you changed $FILE_TO_WATCH."
echo ""
echo -e "\033[33mPlease remember to regenerate the other constants files. If you've already regenerated the constants, please ignore this message.\033[0m"
echo ""
echo "Depending on the constants you've changed, these might include: constants.gen.ts, ConstantsGen.sol, constants_gen.pil, aztec_constants.hpp."
echo ""
echo -e "You can regenerate these by running: '\033[33myarn remake-constants\033[0m' from the 'yarn-project/circuits.js' dir. If you have changed tree sizes, also run ./yarn-project/update-snapshots.sh."
echo ""
echo "We don't automatically regenerate them for you in this git hook, because you'll likely need to also re-build components of the repo. End."
echo ""
fi
Loading