From d5d64fb97ab37525734a030139fc6d6393ba2e2f Mon Sep 17 00:00:00 2001 From: carla Date: Mon, 1 Jun 2020 12:41:36 +0200 Subject: [PATCH] makefile+travis: add mod check and tidy and check modules in travis --- .travis.yml | 2 +- Makefile | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 8ad7c59..bedd772 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,7 +23,7 @@ sudo: required script: - export GO111MODULE=on - - make lint unit build + - make lint unit build mod-check after_script: - echo "Uploading to termbin.com..." && find *.log | xargs -I{} sh -c "cat {} | nc termbin.com 9999 | xargs -r0 printf '{} uploaded to %s'" diff --git a/Makefile b/Makefile index eba506e..3aea970 100644 --- a/Makefile +++ b/Makefile @@ -7,6 +7,7 @@ GOTEST := GO111MODULE=on go test -v GO_BIN := ${GOPATH}/bin GOBUILD := GO111MODULE=on go build -v GOINSTALL := GO111MODULE=on go install -v +GOMOD := GO111MODULE=on go mod COMMIT := $(shell git describe --abbrev=40 --dirty) LDFLAGS := -ldflags "-X $(PKG)/build.Commit=$(COMMIT)" @@ -26,6 +27,12 @@ TEST_FLAGS = -test.timeout=20m UNIT := $(GOLIST) | $(XARGS) env $(GOTEST) $(TEST_FLAGS) +GREEN := "\\033[0;32m" +NC := "\\033[0m" +define print + echo $(GREEN)$1$(NC) +endef + $(LINT_BIN): @$(call print, "Fetching linter") $(DEPGET) $(LINT_PKG)@$(LINT_COMMIT) @@ -42,6 +49,15 @@ lint: $(LINT_BIN) @$(call print, "Linting source.") $(LINT) +mod-tidy: + @$(call print, "Tidying modules.") + $(GOMOD) tidy + +mod-check: + @$(call print, "Checking modules.") + $(GOMOD) tidy + if test -n "$$(git status | grep -e "go.mod\|go.sum")"; then echo "Running go mod tidy changes go.mod/go.sum"; git status; git diff; exit 1; fi + # ============ # INSTALLATION # ============