Skip to content

Commit

Permalink
Add go mod tidy clean verifier to CI (#1689)
Browse files Browse the repository at this point in the history
Signed-off-by: Ken Sipe <kensipe@gmail.com>
Co-authored-by: Jan Schlicht <jan@d2iq.com>
  • Loading branch information
kensipe and Jan Schlicht committed Sep 24, 2020
1 parent 198260f commit c16c2fc
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
34 changes: 34 additions & 0 deletions hack/verify-go-clean.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit c16c2fc

Please sign in to comment.