You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Makefile 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. GO ?= go
  2. HAS_GO = $(shell hash $(GO) > /dev/null 2>&1 && echo "GO" || echo "NOGO" )
  3. ifeq ($(HAS_GO), GO)
  4. GOPATH ?= $(shell $(GO) env GOPATH)
  5. export PATH := $(GOPATH)/bin:$(PATH)
  6. endif
  7. GOFMT ?= gofmt -s
  8. ifneq ($(RACE_ENABLED),)
  9. GOTESTFLAGS ?= -race
  10. endif
  11. GO_SOURCES := $(wildcard *.go)
  12. GO_SOURCES_OWN := $(filter-out vendor/%, $(GO_SOURCES))
  13. GO_PACKAGES ?= $(shell $(GO) list ./... | grep -v /vendor/)
  14. .PHONY: revive
  15. revive:
  16. @hash revive > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  17. $(GO) get -u github.com/mgechev/revive; \
  18. fi
  19. revive -config .revive.toml -exclude=./vendor/... ./... || exit 1
  20. .PHONY: golangci-lint
  21. golangci-lint:
  22. @hash golangci-lint > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  23. export BINARY="golangci-lint"; \
  24. curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(GOPATH)/bin v1.26.0; \
  25. fi
  26. golangci-lint run --timeout 5m
  27. .PHONY: lint
  28. lint: golangci-lint revive
  29. .PHONY: fmt
  30. fmt:
  31. $(GOFMT) -w $(GO_SOURCES_OWN)
  32. .PHONY: fmt-check
  33. fmt-check:
  34. # get all go files and run go fmt on them
  35. @diff=$$($(GOFMT) -d $(GO_SOURCES_OWN)); \
  36. if [ -n "$$diff" ]; then \
  37. echo "Please run 'make fmt' and commit the result:"; \
  38. echo "$${diff}"; \
  39. exit 1; \
  40. fi;
  41. .PHONY: misspell-check
  42. misspell-check:
  43. @hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  44. $(GO) get -u github.com/client9/misspell/cmd/misspell; \
  45. fi
  46. misspell -error $(GO_SOURCES_OWN)
  47. .PHONY: test
  48. test:
  49. $(GO) test -cover -coverprofile coverage.out $(GOTESTFLAGS) $(GO_PACKAGES)