diff --git a/.circleci/config.yml b/.circleci/config.yml index 8cd34c674..92df67265 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -56,6 +56,7 @@ jobs: - go-mod-v1-{{ checksum "go.sum" }} - run: make lint - run: ./hack/verify-generate.sh + - run: ./hack/verify-go-clean.sh - save_cache: key: go-mod-v1-{{ checksum "go.sum" }} paths: diff --git a/hack/verify-go-clean.sh b/hack/verify-go-clean.sh new file mode 100755 index 000000000..f5f50b1f7 --- /dev/null +++ b/hack/verify-go-clean.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash + +##### +# Used to ensure that running `go mod tidy` results in a non-dirty repository. +# Used to verify that dependency changes have been cleaned +##### + +set -o nounset +set -o pipefail +# intentionally not setting 'set -o errexit' because we want to print custom error messages + +# versions of tools +echo "$(go version)" + +# make sure make generate can be invoked +go mod tidy +RETVAL=$? +if [[ ${RETVAL} != 0 ]]; then + echo "Invoking 'go mod tidy' ends with non-zero exit code." + exit 1 +fi + +git diff --exit-code --quiet +RETVAL=$? + +if [[ ${RETVAL} != 0 ]]; then + echo "Running 'go mod tidy' produces changes to the current git status. Maybe you forgot to clean go.mod after changing dependencies?" + echo "The current diff:" + git diff + exit 1 +fi + +echo "Verifying 'go mod tidy' was successful! ヽ(•‿•)ノ" +exit 0