Skip to content

Commit

Permalink
alter pre-commit to fix go install for addlicense and add step to ins…
Browse files Browse the repository at this point in the history
…tall buildifier if not present. (#972)

- `go get -u` command used to install `addlicense` tool in L51 is deprecated since Go 1.17. Replace it with go install.
- Add similar function to install `buildifier` if not already installed. This is used to fix Bazel format.
  • Loading branch information
zhumin8 authored Mar 22, 2022
1 parent e5803e5 commit 0277fc1
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion .githooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,29 @@ function header_check_preparation {
if [ $? -ne 0 ];
then
echo_status "addlicense tool is not yet installed, downloading it now."
go get -u github.com/google/addlicense
go install github.com/google/addlicense@latest
fi
fi
}

function buildifier_preparation {
echo_status "Setting up tool to fix Bazel format"
export GOPATH=$(go env GOPATH)
if [ $? -ne 0 ];
then
echo_status "Please install Go first, instructions can be found here: https://golang.org/doc/install."
else
export ENV_PATH=$(echo $PATH)
if [[ $ENV_PATH != *$GOPATH* ]];
then
echo_status "GOPATH is not in the system path, adding it now."
export PATH=$GOPATH/bin:$PATH
fi
which addlicense
if [ $? -ne 0 ];
then
echo_status "buildifier tool is not yet installed, downloading it now."
go install github.com/bazelbuild/buildtools/buildifier@latest
fi
fi
}
Expand Down Expand Up @@ -123,6 +145,7 @@ fi
# Check and fix Bazel format.
if [ $NUM_BAZEL_FILES_CHANGED -gt 0 ]
then
buildifier_preparation
for FILE in $(find ./ -name BUILD.bazel)
do
buildifier --lint=fix $FILE
Expand Down

0 comments on commit 0277fc1

Please sign in to comment.