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

Add go mod tidy clean verifier to CI #1689

Merged
merged 2 commits into from
Sep 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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