From 9a2935cff6b57ffb601640977f7b69366dde396e Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Tue, 3 Apr 2018 11:05:28 +0200 Subject: [PATCH] [monitor] update Makefile --- tm-monitor/Makefile | 88 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 78 insertions(+), 10 deletions(-) diff --git a/tm-monitor/Makefile b/tm-monitor/Makefile index 8a6cad8a..3371a0c1 100644 --- a/tm-monitor/Makefile +++ b/tm-monitor/Makefile @@ -1,26 +1,50 @@ DIST_DIRS := find * -type d -exec VERSION := $(shell perl -ne '/^var version.*"([^"]+)".*$$/ && print "v$$1\n"' main.go) GOTOOLS = \ - github.com/mitchellh/gox -PACKAGES=$(shell go list ./... | grep -v '/vendor') + github.com/mitchellh/gox \ + github.com/golang/dep/cmd/dep \ + gopkg.in/alecthomas/gometalinter.v2 +PACKAGES=$(shell go list ./... | grep -v '/vendor/') -tools: - go get $(GOTOOLS) +all: check get_vendor_deps build test install metalinter + +check: check_tools + +######################################## +### Tools & dependencies + +check_tools: + @# https://stackoverflow.com/a/25668869 + @echo "Found tools: $(foreach tool,$(GOTOOLS_CHECK),\ + $(if $(shell which $(tool)),$(tool),$(error "No $(tool) in PATH")))" + +get_tools: + @echo "--> Installing tools" + go get -u -v $(GOTOOLS) + @gometalinter.v2 --install + +update_tools: + @echo "--> Updating tools" + @go get -u $(GOTOOLS) get_vendor_deps: - @hash glide 2>/dev/null || go get github.com/Masterminds/glide - glide install + @rm -rf vendor/ + @echo "--> Running dep ensure" + @dep ensure + +######################################## +### Build build: - go build + @go build install: - go install + @go install test: @go test -race $(PACKAGES) -build-all: tools +build-all: check_tools rm -rf ./dist gox -verbose \ -ldflags "-s -w" \ @@ -36,6 +60,9 @@ dist: build-all shasum -a256 ./*.tar.gz > "./tm-monitor_${VERSION}_SHA256SUMS" && \ cd .. +######################################## +### Docker + build-docker: rm -f ./tm-monitor docker run -it --rm -v "$(PWD):/go/src/github.com/tendermint/tools/tm-monitor" -w "/go/src/github.com/tendermint/tools/tm-monitor" -e "CGO_ENABLED=0" golang:alpine go build -ldflags "-s -w" -o tm-monitor @@ -45,4 +72,45 @@ clean: rm -f ./tm-monitor rm -rf ./dist -.PHONY: tools get_vendor_deps build install test build-all dist clean build-docker +######################################## +### Formatting, linting, and vetting + +fmt: + @go fmt ./... + +metalinter: + @echo "==> Running linter" + gometalinter.v2 --vendor --deadline=600s --disable-all \ + --enable=maligned \ + --enable=deadcode \ + --enable=goconst \ + --enable=goimports \ + --enable=gosimple \ + --enable=ineffassign \ + --enable=megacheck \ + --enable=misspell \ + --enable=staticcheck \ + --enable=safesql \ + --enable=structcheck \ + --enable=unconvert \ + --enable=unused \ + --enable=varcheck \ + --enable=vetshadow \ + ./... + #--enable=gas \ + #--enable=dupl \ + #--enable=errcheck \ + #--enable=gocyclo \ + #--enable=golint \ <== comments on anything exported + #--enable=gotype \ + #--enable=interfacer \ + #--enable=unparam \ + #--enable=vet \ + +metalinter_all: + gometalinter.v2 --vendor --deadline=600s --enable-all --disable=lll ./... + +# To avoid unintended conflicts with file names, always add to .PHONY +# unless there is a reason not to. +# https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html +.PHONY: check check_tools get_tools update_tools get_vendor_deps build install test build-all dist fmt metalinter metalinter_all build-docker clean