THIS IS A TEST INSTANCE ONLY! REPOSITORIES CAN BE DELETED AT ANY TIME!

A command line tool to interact with Gitea servers, moved to https://gitea.com/gitea/tea
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.

189 lines
4.8KB

  1. DIST := dist
  2. IMPORT := code.gitea.io/tea
  3. export GO111MODULE=off
  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 -i ./...
  49. rm -rf $(EXECUTABLE) $(DIST)
  50. .PHONY: fmt
  51. fmt:
  52. $(GOFMT) -w $(GOFILES)
  53. .PHONY: vet
  54. vet:
  55. $(GO) vet $(PACKAGES)
  56. .PHONY: lint
  57. lint:
  58. @hash revive > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  59. $(GO) get -u github.com/mgechev/revive; \
  60. fi
  61. revive -config .revive.toml -exclude=./vendor/... ./... || exit 1
  62. .PHONY: misspell-check
  63. misspell-check:
  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 -error -i unknwon,destory $(GOFILES)
  68. .PHONY: misspell
  69. misspell:
  70. @hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  71. $(GO) get -u github.com/client9/misspell/cmd/misspell; \
  72. fi
  73. misspell -w -i unknwon $(GOFILES)
  74. .PHONY: fmt-check
  75. fmt-check:
  76. # get all go files and run go fmt on them
  77. @diff=$$($(GOFMT) -d $(GOFILES)); \
  78. if [ -n "$$diff" ]; then \
  79. echo "Please run 'make fmt' and commit the result:"; \
  80. echo "$${diff}"; \
  81. exit 1; \
  82. fi;
  83. .PHONY: test
  84. test:
  85. GO111MODULE=on $(GO) test -mod=vendor -tags='sqlite sqlite_unlock_notify' $(PACKAGES)
  86. .PHONY: unit-test-coverage
  87. unit-test-coverage:
  88. $(GO) test -tags='sqlite sqlite_unlock_notify' -cover -coverprofile coverage.out $(PACKAGES) && echo "\n==>\033[32m Ok\033[m\n" || exit 1
  89. .PHONY: vendor
  90. vendor:
  91. GO111MODULE=on $(GO) mod tidy && GO111MODULE=on $(GO) mod vendor
  92. .PHONY: test-vendor
  93. test-vendor: vendor
  94. @diff=$$(git diff vendor/); \
  95. if [ -n "$$diff" ]; then \
  96. echo "Please run 'make vendor' and commit the result:"; \
  97. echo "$${diff}"; \
  98. exit 1; \
  99. fi;
  100. .PHONY: check
  101. check: test
  102. .PHONY: install
  103. install: $(wildcard *.go)
  104. $(GO) install -v -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)'
  105. .PHONY: build
  106. build: $(EXECUTABLE)
  107. $(EXECUTABLE): $(SOURCES)
  108. GO111MODULE=on $(GO) build -mod=vendor $(GOFLAGS) $(EXTRA_GOFLAGS) -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)' -o $@
  109. .PHONY: release
  110. release: release-dirs release-windows release-linux release-darwin release-copy release-compress release-check
  111. .PHONY: release-dirs
  112. release-dirs:
  113. mkdir -p $(DIST)/binaries $(DIST)/release
  114. .PHONY: release-windows
  115. release-windows:
  116. @hash xgo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  117. $(GO) get -u src.techknowlogick.com/xgo; \
  118. fi
  119. xgo -dest $(DIST)/binaries -tags 'netgo $(TAGS)' -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -targets 'windows/*' -out tea-$(VERSION) .
  120. ifeq ($(CI),drone)
  121. cp /build/* $(DIST)/binaries
  122. endif
  123. .PHONY: release-linux
  124. release-linux:
  125. @hash xgo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  126. $(GO) get -u src.techknowlogick.com/xgo; \
  127. fi
  128. xgo -dest $(DIST)/binaries -tags 'netgo $(TAGS)' -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -targets 'linux/*' -out tea-$(VERSION) .
  129. ifeq ($(CI),drone)
  130. cp /build/* $(DIST)/binaries
  131. endif
  132. .PHONY: release-darwin
  133. release-darwin:
  134. @hash xgo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  135. $(GO) get -u src.techknowlogick.com/xgo; \
  136. fi
  137. xgo -dest $(DIST)/binaries -tags 'netgo $(TAGS)' -ldflags '$(LDFLAGS)' -targets 'darwin/*' -out tea-$(VERSION) .
  138. ifeq ($(CI),drone)
  139. cp /build/* $(DIST)/binaries
  140. endif
  141. .PHONY: release-copy
  142. release-copy:
  143. cd $(DIST); for file in `find /build -type f -name "*"`; do cp $${file} ./release/; done;
  144. .PHONY: release-compress
  145. release-compress:
  146. @hash gxz > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  147. $(GO) get -u github.com/ulikunitz/xz/cmd/gxz; \
  148. fi
  149. cd $(DIST)/release/; for file in `find . -type f -name "*"`; do echo "compressing $${file}" && gxz -k -9 $${file}; done;
  150. .PHONY: release-check
  151. release-check:
  152. cd $(DIST)/release/; for file in `find . -type f -name "*"`; do echo "checksumming $${file}" && $(SHASUM) `echo $${file} | sed 's/^..//'` > $${file}.sha256; done;