Makefile 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. GO ?= go
  2. GOFMT ?= gofmt "-s"
  3. PACKAGES ?= $(shell $(GO) list ./... | grep -v /vendor/)
  4. VETPACKAGES ?= $(shell $(GO) list ./... | grep -v /vendor/ | grep -v /examples/)
  5. GOFILES := $(shell find . -name "*.go" -type f -not -path "./vendor/*")
  6. TESTFOLDER := $(shell $(GO) list ./... | grep -E 'gin$$|binding$$|render$$' | grep -v examples)
  7. all: install
  8. install: deps
  9. govendor sync
  10. .PHONY: test
  11. test:
  12. echo "mode: count" > coverage.out
  13. for d in $(TESTFOLDER); do \
  14. $(GO) test -v -covermode=count -coverprofile=profile.out $$d > tmp.out; \
  15. cat tmp.out; \
  16. if grep -q "^--- FAIL" tmp.out; then \
  17. rm tmp.out; \
  18. exit 1; \
  19. elif grep -q "build failed" tmp.out; then \
  20. rm tmp.out; \
  21. exit; \
  22. fi; \
  23. if [ -f profile.out ]; then \
  24. cat profile.out | grep -v "mode:" >> coverage.out; \
  25. rm profile.out; \
  26. fi; \
  27. done
  28. .PHONY: fmt
  29. fmt:
  30. $(GOFMT) -w $(GOFILES)
  31. .PHONY: fmt-check
  32. fmt-check:
  33. @diff=$$($(GOFMT) -d $(GOFILES)); \
  34. if [ -n "$$diff" ]; then \
  35. echo "Please run 'make fmt' and commit the result:"; \
  36. echo "$${diff}"; \
  37. exit 1; \
  38. fi;
  39. vet:
  40. $(GO) vet $(VETPACKAGES)
  41. deps:
  42. @hash govendor > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  43. $(GO) get -u github.com/kardianos/govendor; \
  44. fi
  45. @hash embedmd > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  46. $(GO) get -u github.com/campoy/embedmd; \
  47. fi
  48. embedmd:
  49. embedmd -d *.md
  50. .PHONY: lint
  51. lint:
  52. @hash golint > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  53. $(GO) get -u golang.org/x/lint/golint; \
  54. fi
  55. for PKG in $(PACKAGES); do golint -set_exit_status $$PKG || exit 1; done;
  56. .PHONY: misspell-check
  57. misspell-check:
  58. @hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  59. $(GO) get -u github.com/client9/misspell/cmd/misspell; \
  60. fi
  61. misspell -error $(GOFILES)
  62. .PHONY: misspell
  63. misspell:
  64. @hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  65. $(GO) get -u github.com/client9/misspell/cmd/misspell; \
  66. fi
  67. misspell -w $(GOFILES)
  68. .PHONY: tools
  69. tools:
  70. go install golang.org/x/lint/golint; \
  71. go install github.com/client9/misspell/cmd/misspell; \
  72. go install github.com/campoy/embedmd;