Skip to content

Commit

Permalink
lint: Check that 'go mod tidy' was run
Browse files Browse the repository at this point in the history
In #948, we noticed that some `go.sum` files were outdated. To avoid
this in the future, add a `lint` check that verifies that `go mod tidy`
does not cause any changes.

This will fail with a dirty working tree as well, but in CI, we don't
expect that.
  • Loading branch information
abhinav committed May 25, 2021
1 parent dedcdad commit a2fca9d
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ lint: $(GOLINT) $(STATICCHECK)
@echo "Checking for license headers..."
@./checklicense.sh | tee -a lint.log
@[ ! -s lint.log ]
@echo "Checking 'go mod tidy'..."
@make tidy
@if ! git diff --quiet; then \
echo "'go mod tidy' resulted in changes or working tree is dirty:"; \
git --no-pager diff; \
fi

$(GOLINT):
cd tools && go install golang.org/x/lint/golint
Expand Down Expand Up @@ -61,3 +67,7 @@ bench:
updatereadme:
rm -f README.md
cat .readme.tmpl | go run internal/readme/readme.go > README.md

.PHONY: tidy
tidy:
@$(foreach dir,$(MODULE_DIRS),(cd $(dir) && go mod tidy) &&) true

0 comments on commit a2fca9d

Please sign in to comment.