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
25 changes: 25 additions & 0 deletions scripts/hooks/pre-commit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,30 @@ function lint_and_add_modified_go_files() {
done
}

function run_proto_all_if_needed() {
local proto_files_modified="$(git diff --name-only --diff-filter=d | grep '\.proto$')"

if [[ -n "$proto_files_modified" ]]; then
echo "Detected changes in .proto files. Running 'make proto-all'."
local before_files=$(git status --porcelain | awk '{print $2}')

# Run make proto-all
make proto-all

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 "Running 'make proto-all' resulted in changes."
echo "The following files have been modified by 'make proto-all':"
for file in $changed_files; do
echo "$file"
done
exit 1
fi
fi
}

check_golangci_lint_version
run_proto_all_if_needed
lint_and_add_modified_go_files
Loading