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

feat: add pre commit hook that checks if make proto-all should be run #6678

Closed
wants to merge 8 commits into from

Conversation

PanGan21
Copy link
Contributor

@PanGan21 PanGan21 commented Jun 24, 2024

Description

Adds pre commit hook that checks if make proto-all should be run.

closes: #6668


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against the correct branch (see CONTRIBUTING.md).
  • Linked to GitHub issue with discussion and accepted design, OR link to spec that describes this work.
  • Code follows the module structure standards and Go style guide.
  • Wrote unit and integration tests.
  • Updated relevant documentation (docs/).
  • Added relevant godoc comments.
  • Provide a conventional commit message to follow the repository standards.
  • Include a descriptive changelog entry when appropriate. This may be left to the discretion of the PR reviewers. (e.g. chores should be omitted from changelog)
  • Re-reviewed Files changed in the GitHub PR explorer.
  • Review SonarCloud Report in the comment section below once CI passes.

echo "Error: Please run 'make proto-all' and commit the updated files."

# Revert the changes made by make proto-all
for file in $changed_files; do
Copy link
Contributor Author

Choose a reason for hiding this comment

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

A drawback I can see with this approach is that the pre commit hook becomes quite slower.
I was thinking of the approach to just check if any .proto file is changed but this doesn't guarantee whether the command should be run

Copy link
Contributor

Choose a reason for hiding this comment

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

yea, pretty sure this would make it very frustrating for folks. I'd be fine with doing a check on if any protos have been modified, run it, else just leave as is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refactored. Now the script checks in the unstaged .proto files. If it finds a change it runs make proto-all and logs the files that were changed. If it doesn't find a change in protos then it just exits

local after_files=$(git status --porcelain | awk '{print $2}')
local changed_files=$(comm -13 <(echo "$before_files" | sort) <(echo "$after_files" | sort))
if [[ -n "$changed_files" ]]; then
echo "Error: Please run 'make proto-all' and commit the updated files."
Copy link
Contributor

Choose a reason for hiding this comment

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

Hm, thinking the idea here was to automatically just invoke it if proto changes have been made? @bznein

Copy link
Contributor

Choose a reason for hiding this comment

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

That was my idea, yeah. This is still better than what we have now, but having it ran automatically would be ideal to me

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the review!
I changed the script to run make proto-all and do git add to the generated files. Le me know what you think :)

@bznein
Copy link
Contributor

bznein commented Jul 8, 2024

hi @PanGan21, unfortunately we realized that a pre-commit would be very time-consuming and disrupting for the dev workflow and we decided to abandon this issue. Thanks for taking to time to work on it, really appreciated!

@bznein bznein closed this Jul 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Add pre-commit hook to run make proto-all
3 participants