| 1 | export GOBIN ?= $(shell pwd)/bin |
| 2 | |
| 3 | GO_FILES := $(shell \ |
| 4 | find . '(' -path '*/.*' -o -path './vendor' ')' -prune \ |
| 5 | -o -name '*.go' -print | cut -b3-) |
| 6 | |
| 7 | GOLINT = $(GOBIN)/golint |
| 8 | STATICCHECK = $(GOBIN)/staticcheck |
| 9 | |
| 10 | .PHONY: build |
| 11 | build: |
| 12 | go build ./... |
| 13 | |
| 14 | .PHONY: install |
| 15 | install: |
| 16 | go mod download |
| 17 | |
| 18 | .PHONY: test |
| 19 | test: |
| 20 | go test -race ./... |
| 21 | |
| 22 | .PHONY: cover |
| 23 | cover: |
| 24 | go test -coverprofile=cover.out -covermode=atomic -coverpkg=./... ./... |
| 25 | go tool cover -html=cover.out -o cover.html |
| 26 | |
| 27 | $(GOLINT): tools/go.mod |
| 28 | cd tools && go install golang.org/x/lint/golint |
| 29 | |
| 30 | $(STATICCHECK): tools/go.mod |
| 31 | cd tools && go install honnef.co/go/tools/cmd/[email protected] |
| 32 | |
| 33 | .PHONY: lint |
| 34 | lint: $(GOLINT) $(STATICCHECK) |
| 35 | @rm -rf lint.log |
| 36 | @echo "Checking gofmt" |
| 37 | @gofmt -d -s $(GO_FILES) 2>&1 | tee lint.log |
| 38 | @echo "Checking go vet" |
| 39 | @go vet ./... 2>&1 | tee -a lint.log |
| 40 | @echo "Checking golint" |
| 41 | @$(GOLINT) ./... | tee -a lint.log |
| 42 | @echo "Checking staticcheck" |
| 43 | @$(STATICCHECK) ./... 2>&1 | tee -a lint.log |
| 44 | @echo "Checking for license headers..." |
| 45 | @./.build/check_license.sh | tee -a lint.log |
| 46 | @[ ! -s lint.log ] |