khenaidoo | ac63710 | 2019-01-14 15:44:34 -0500 | [diff] [blame^] | 1 | PACKAGES := $(shell glide nv) |
| 2 | # Many Go tools take file globs or directories as arguments instead of packages. |
| 3 | PACKAGE_FILES ?= *.go |
| 4 | |
| 5 | |
| 6 | # The linting tools evolve with each Go version, so run them only on the latest |
| 7 | # stable release. |
| 8 | GO_VERSION := $(shell go version | cut -d " " -f 3) |
| 9 | GO_MINOR_VERSION := $(word 2,$(subst ., ,$(GO_VERSION))) |
| 10 | LINTABLE_MINOR_VERSIONS := 7 8 |
| 11 | ifneq ($(filter $(LINTABLE_MINOR_VERSIONS),$(GO_MINOR_VERSION)),) |
| 12 | SHOULD_LINT := true |
| 13 | endif |
| 14 | |
| 15 | |
| 16 | export GO15VENDOREXPERIMENT=1 |
| 17 | |
| 18 | |
| 19 | .PHONY: build |
| 20 | build: |
| 21 | go build -i $(PACKAGES) |
| 22 | |
| 23 | |
| 24 | .PHONY: install |
| 25 | install: |
| 26 | glide --version || go get github.com/Masterminds/glide |
| 27 | glide install |
| 28 | |
| 29 | |
| 30 | .PHONY: test |
| 31 | test: |
| 32 | go test -cover -race $(PACKAGES) |
| 33 | |
| 34 | |
| 35 | .PHONY: install_ci |
| 36 | install_ci: install |
| 37 | go get github.com/wadey/gocovmerge |
| 38 | go get github.com/mattn/goveralls |
| 39 | go get golang.org/x/tools/cmd/cover |
| 40 | ifdef SHOULD_LINT |
| 41 | go get github.com/golang/lint/golint |
| 42 | endif |
| 43 | |
| 44 | .PHONY: lint |
| 45 | lint: |
| 46 | ifdef SHOULD_LINT |
| 47 | @rm -rf lint.log |
| 48 | @echo "Checking formatting..." |
| 49 | @gofmt -d -s $(PACKAGE_FILES) 2>&1 | tee lint.log |
| 50 | @echo "Checking vet..." |
| 51 | @$(foreach dir,$(PACKAGE_FILES),go tool vet $(dir) 2>&1 | tee -a lint.log;) |
| 52 | @echo "Checking lint..." |
| 53 | @$(foreach dir,$(PKGS),golint $(dir) 2>&1 | tee -a lint.log;) |
| 54 | @echo "Checking for unresolved FIXMEs..." |
| 55 | @git grep -i fixme | grep -v -e vendor -e Makefile | tee -a lint.log |
| 56 | @[ ! -s lint.log ] |
| 57 | else |
| 58 | @echo "Skipping linters on" $(GO_VERSION) |
| 59 | endif |
| 60 | |
| 61 | |
| 62 | .PHONY: test_ci |
| 63 | test_ci: install_ci build |
| 64 | ./scripts/cover.sh $(shell go list $(PACKAGES)) |