Makefile 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. GOCMD:=$(shell which go)
  2. GOLINT:=$(shell which golint)
  3. GOIMPORT:=$(shell which goimports)
  4. GOFMT:=$(shell which gofmt)
  5. GOBUILD:=$(GOCMD) build
  6. GOINSTALL:=$(GOCMD) install
  7. GOCLEAN:=$(GOCMD) clean
  8. GOTEST:=$(GOCMD) test
  9. GOGET:=$(GOCMD) get
  10. GOLIST:=$(GOCMD) list
  11. GOVET:=$(GOCMD) vet
  12. GOPATH:=$(shell $(GOCMD) env GOPATH)
  13. u := $(if $(update),-u)
  14. BINARY_NAME:=swag
  15. PACKAGES:=$(shell $(GOLIST) github.com/swaggo/swag github.com/swaggo/swag/cmd/swag github.com/swaggo/swag/gen github.com/swaggo/swag/format)
  16. GOFILES:=$(shell find . -name "*.go" -type f)
  17. export GO111MODULE := on
  18. all: test build
  19. .PHONY: build
  20. build: deps
  21. $(GOBUILD) -o $(BINARY_NAME) ./cmd/swag
  22. .PHONY: install
  23. install: deps
  24. $(GOINSTALL) ./cmd/swag
  25. .PHONY: test
  26. test:
  27. echo "mode: count" > coverage.out
  28. for PKG in $(PACKAGES); do \
  29. $(GOCMD) test -v -covermode=count -coverprofile=profile.out $$PKG > tmp.out; \
  30. cat tmp.out; \
  31. if grep -q "^--- FAIL" tmp.out; then \
  32. rm tmp.out; \
  33. exit 1; \
  34. elif grep -q "build failed" tmp.out; then \
  35. rm tmp.out; \
  36. exit; \
  37. fi; \
  38. if [ -f profile.out ]; then \
  39. cat profile.out | grep -v "mode:" >> coverage.out; \
  40. rm profile.out; \
  41. fi; \
  42. done
  43. .PHONY: clean
  44. clean:
  45. $(GOCLEAN)
  46. rm -f $(BINARY_NAME)
  47. .PHONY: deps
  48. deps:
  49. $(GOGET) github.com/swaggo/cli
  50. $(GOGET) github.com/ghodss/yaml
  51. $(GOGET) github.com/KyleBanks/depth
  52. $(GOGET) github.com/go-openapi/jsonreference
  53. $(GOGET) github.com/go-openapi/spec
  54. $(GOGET) github.com/stretchr/testify/assert
  55. $(GOGET) golang.org/x/tools/go/loader
  56. .PHONY: devel-deps
  57. devel-deps:
  58. GO111MODULE=off $(GOGET) -v -u \
  59. golang.org/x/lint/golint
  60. .PHONY: lint
  61. lint: devel-deps
  62. for PKG in $(PACKAGES); do golint -set_exit_status $$PKG || exit 1; done;
  63. .PHONY: vet
  64. vet: deps devel-deps
  65. $(GOVET) $(PACKAGES)
  66. .PHONY: fmt
  67. fmt:
  68. $(GOFMT) -s -w $(GOFILES)
  69. .PHONY: fmt-check
  70. fmt-check:
  71. @diff=$$($(GOFMT) -s -d $(GOFILES)); \
  72. if [ -n "$$diff" ]; then \
  73. echo "Please run 'make fmt' and commit the result:"; \
  74. echo "$${diff}"; \
  75. exit 1; \
  76. fi;
  77. .PHONY: view-covered
  78. view-covered:
  79. $(GOTEST) -coverprofile=cover.out $(TARGET)
  80. $(GOCMD) tool cover -html=cover.out