A command line tool to interact with Gitea servers
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.
 
 
 
 

193 lines
5.1 KiB

  1. DIST := dist
  2. IMPORT := code.gitea.io/tea
  3. export GO111MODULE=on
  4. GO ?= go
  5. SED_INPLACE := sed -i
  6. SHASUM ?= shasum -a 256
  7. export PATH := $($(GO) env GOPATH)/bin:$(PATH)
  8. ifeq ($(OS), Windows_NT)
  9. EXECUTABLE := tea.exe
  10. else
  11. EXECUTABLE := tea
  12. UNAME_S := $(shell uname -s)
  13. ifeq ($(UNAME_S),Darwin)
  14. SED_INPLACE := sed -i ''
  15. endif
  16. endif
  17. GOFILES := $(shell find . -name "*.go" -type f ! -path "./vendor/*" ! -path "*/bindata.go")
  18. GOFMT ?= gofmt -s
  19. GOFLAGS := -i -v
  20. EXTRA_GOFLAGS ?=
  21. MAKE_VERSION := $(shell make -v | head -n 1)
  22. ifneq ($(DRONE_TAG),)
  23. VERSION ?= $(subst v,,$(DRONE_TAG))
  24. TEA_VERSION ?= $(VERSION)
  25. else
  26. ifneq ($(DRONE_BRANCH),)
  27. VERSION ?= $(subst release/v,,$(DRONE_BRANCH))
  28. else
  29. VERSION ?= master
  30. endif
  31. TEA_VERSION ?= $(shell git describe --tags --always | sed 's/-/+/' | sed 's/^v//')
  32. endif
  33. LDFLAGS := -X "main.Version=$(TEA_VERSION)" -X "main.Tags=$(TAGS)"
  34. PACKAGES ?= $(shell $(GO) list ./... | grep -v /vendor/)
  35. SOURCES ?= $(shell find . -name "*.go" -type f)
  36. TAGS ?=
  37. ifeq ($(OS), Windows_NT)
  38. EXECUTABLE := tea.exe
  39. else
  40. EXECUTABLE := tea
  41. endif
  42. # $(call strip-suffix,filename)
  43. strip-suffix = $(firstword $(subst ., ,$(1)))
  44. .PHONY: all
  45. all: build
  46. .PHONY: clean
  47. clean:
  48. $(GO) clean -mod=vendor -i ./...
  49. rm -rf $(EXECUTABLE) $(DIST)
  50. .PHONY: fmt
  51. fmt:
  52. $(GOFMT) -w $(GOFILES)
  53. .PHONY: vet
  54. vet:
  55. # Default vet
  56. $(GO) vet -mod=vendor $(PACKAGES)
  57. # Custom vet
  58. $(GO) build -mod=vendor gitea.com/jolheiser/gitea-vet
  59. $(GO) vet -vettool=gitea-vet $(PACKAGES)
  60. .PHONY: lint
  61. lint:
  62. @hash revive > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  63. cd /tmp && $(GO) get -u github.com/mgechev/revive; \
  64. fi
  65. revive -config .revive.toml -exclude=./vendor/... ./... || exit 1
  66. .PHONY: misspell-check
  67. misspell-check:
  68. @hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  69. cd /tmp && $(GO) get -u github.com/client9/misspell/cmd/misspell; \
  70. fi
  71. misspell -error -i unknwon,destory $(GOFILES)
  72. .PHONY: misspell
  73. misspell:
  74. @hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  75. cd /tmp && $(GO) get -u github.com/client9/misspell/cmd/misspell; \
  76. fi
  77. misspell -w -i unknwon $(GOFILES)
  78. .PHONY: fmt-check
  79. fmt-check:
  80. # get all go files and run go fmt on them
  81. @diff=$$($(GOFMT) -d $(GOFILES)); \
  82. if [ -n "$$diff" ]; then \
  83. echo "Please run 'make fmt' and commit the result:"; \
  84. echo "$${diff}"; \
  85. exit 1; \
  86. fi;
  87. .PHONY: test
  88. test:
  89. $(GO) test -mod=vendor -tags='sqlite sqlite_unlock_notify' $(PACKAGES)
  90. .PHONY: unit-test-coverage
  91. unit-test-coverage:
  92. $(GO) test -mod=vendor -tags='sqlite sqlite_unlock_notify' -cover -coverprofile coverage.out $(PACKAGES) && echo "\n==>\033[32m Ok\033[m\n" || exit 1
  93. .PHONY: vendor
  94. vendor:
  95. $(GO) mod tidy && $(GO) mod vendor
  96. .PHONY: test-vendor
  97. test-vendor: vendor
  98. @diff=$$(git diff vendor/); \
  99. if [ -n "$$diff" ]; then \
  100. echo "Please run 'make vendor' and commit the result:"; \
  101. echo "$${diff}"; \
  102. exit 1; \
  103. fi;
  104. .PHONY: check
  105. check: test
  106. .PHONY: install
  107. install: $(wildcard *.go)
  108. $(GO) install -v -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)'
  109. .PHONY: build
  110. build: $(EXECUTABLE)
  111. $(EXECUTABLE): $(SOURCES)
  112. $(GO) build -mod=vendor $(GOFLAGS) $(EXTRA_GOFLAGS) -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)' -o $@
  113. .PHONY: release
  114. release: release-dirs release-windows release-linux release-darwin release-copy release-compress release-check
  115. .PHONY: release-dirs
  116. release-dirs:
  117. mkdir -p $(DIST)/binaries $(DIST)/release
  118. .PHONY: release-windows
  119. release-windows:
  120. @hash xgo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  121. cd /tmp && $(GO) get -u src.techknowlogick.com/xgo; \
  122. fi
  123. GO111MODULE=off xgo -dest $(DIST)/binaries -tags 'netgo $(TAGS)' -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -targets 'windows/*' -out tea-$(VERSION) .
  124. ifeq ($(CI),drone)
  125. cp /build/* $(DIST)/binaries
  126. endif
  127. .PHONY: release-linux
  128. release-linux:
  129. @hash xgo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  130. cd /tmp && $(GO) get -u src.techknowlogick.com/xgo; \
  131. fi
  132. GO111MODULE=off xgo -dest $(DIST)/binaries -tags 'netgo $(TAGS)' -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -targets 'linux/amd64,linux/386,linux/arm-5,linux/arm-6,linux/arm64,linux/mips64le,linux/mips,linux/mipsle' -out tea-$(VERSION) .
  133. ifeq ($(CI),drone)
  134. cp /build/* $(DIST)/binaries
  135. endif
  136. .PHONY: release-darwin
  137. release-darwin:
  138. @hash xgo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  139. cd /tmp && $(GO) get -u src.techknowlogick.com/xgo; \
  140. fi
  141. GO111MODULE=off xgo -dest $(DIST)/binaries -tags 'netgo $(TAGS)' -ldflags '$(LDFLAGS)' -targets 'darwin/*' -out tea-$(VERSION) .
  142. ifeq ($(CI),drone)
  143. cp /build/* $(DIST)/binaries
  144. endif
  145. .PHONY: release-copy
  146. release-copy:
  147. cd $(DIST); for file in `find /build -type f -name "*"`; do cp $${file} ./release/; done;
  148. .PHONY: release-compress
  149. release-compress:
  150. @hash gxz > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  151. GO111MODULE=off $(GO) get -u github.com/ulikunitz/xz/cmd/gxz; \
  152. fi
  153. cd $(DIST)/release/; for file in `find . -type f -name "*"`; do echo "compressing $${file}" && gxz -k -9 $${file}; done;
  154. .PHONY: release-check
  155. release-check:
  156. cd $(DIST)/release/; for file in `find . -type f -name "*"`; do echo "checksumming $${file}" && $(SHASUM) `echo $${file} | sed 's/^..//'` > $${file}.sha256; done;