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 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. DIST := dist
  2. IMPORT := code.gitea.io/gitea
  3. GO ?= go
  4. SED_INPLACE := sed -i
  5. ifeq ($(OS), Windows_NT)
  6. EXECUTABLE := gitea.exe
  7. else
  8. EXECUTABLE := gitea
  9. UNAME_S := $(shell uname -s)
  10. ifeq ($(UNAME_S),Darwin)
  11. SED_INPLACE := sed -i ''
  12. endif
  13. endif
  14. BINDATA := modules/{options,public,templates}/bindata.go
  15. STYLESHEETS := $(wildcard public/less/index.less public/less/_*.less)
  16. DOCKER_TAG := gitea/gitea:latest
  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. LDFLAGS := -X "main.Version=$(shell git describe --tags --always | sed 's/-/+/' | sed 's/^v//')" -X "main.Tags=$(TAGS)"
  22. PACKAGES ?= $(filter-out code.gitea.io/gitea/integrations,$(shell $(GO) list ./... | grep -v /vendor/))
  23. SOURCES ?= $(shell find . -name "*.go" -type f)
  24. TAGS ?=
  25. TMPDIR := $(shell mktemp -d 2>/dev/null || mktemp -d -t 'gitea-temp')
  26. ifeq ($(OS), Windows_NT)
  27. EXECUTABLE := gitea.exe
  28. else
  29. EXECUTABLE := gitea
  30. endif
  31. ifneq ($(DRONE_TAG),)
  32. VERSION ?= $(subst v,,$(DRONE_TAG))
  33. else
  34. ifneq ($(DRONE_BRANCH),)
  35. VERSION ?= $(subst release/v,,$(DRONE_BRANCH))
  36. else
  37. VERSION ?= master
  38. endif
  39. endif
  40. .PHONY: all
  41. all: build
  42. .PHONY: clean
  43. clean:
  44. $(GO) clean -i ./...
  45. rm -rf $(EXECUTABLE) $(DIST) $(BINDATA) integrations*.test
  46. required-gofmt-version:
  47. @$(GO) version | grep -q '\(1.7\|1.8\)' || { echo "We require go version 1.7 or 1.8 to format code" >&2 && exit 1; }
  48. .PHONY: fmt
  49. fmt: required-gofmt-version
  50. $(GOFMT) -w $(GOFILES)
  51. .PHONY: vet
  52. vet:
  53. $(GO) vet $(PACKAGES)
  54. .PHONY: generate
  55. generate:
  56. @hash go-bindata > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  57. $(GO) get -u github.com/jteeuwen/go-bindata/...; \
  58. fi
  59. $(GO) generate $(PACKAGES)
  60. .PHONY: generate-swagger
  61. generate-swagger:
  62. @hash swagger > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  63. $(GO) get -u github.com/go-swagger/go-swagger/cmd/swagger; \
  64. fi
  65. swagger generate spec -o ./public/swagger.v1.json
  66. $(SED_INPLACE) "s;\".ref\": \"#/definitions/GPGKey\";\"type\": \"object\";g" ./public/swagger.v1.json
  67. $(SED_INPLACE) "s;^ \".ref\": \"#/definitions/Repository\"; \"type\": \"object\";g" ./public/swagger.v1.json
  68. .PHONY: errcheck
  69. errcheck:
  70. @hash errcheck > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  71. $(GO) get -u github.com/kisielk/errcheck; \
  72. fi
  73. errcheck $(PACKAGES)
  74. .PHONY: lint
  75. lint:
  76. @hash golint > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  77. $(GO) get -u github.com/golang/lint/golint; \
  78. fi
  79. for PKG in $(PACKAGES); do golint -set_exit_status $$PKG || exit 1; done;
  80. .PHONY: misspell-check
  81. misspell-check:
  82. @hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  83. $(GO) get -u github.com/client9/misspell/cmd/misspell; \
  84. fi
  85. misspell -error -i unknwon $(GOFILES)
  86. .PHONY: misspell
  87. misspell:
  88. @hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  89. $(GO) get -u github.com/client9/misspell/cmd/misspell; \
  90. fi
  91. misspell -w -i unknwon $(GOFILES)
  92. .PHONY: fmt-check
  93. fmt-check: required-gofmt-version
  94. # get all go files and run go fmt on them
  95. @diff=$$($(GOFMT) -d $(GOFILES)); \
  96. if [ -n "$$diff" ]; then \
  97. echo "Please run 'make fmt' and commit the result:"; \
  98. echo "$${diff}"; \
  99. exit 1; \
  100. fi;
  101. .PHONY: test
  102. test: fmt-check
  103. $(GO) test $(PACKAGES)
  104. .PHONY: test-coverage
  105. test-coverage: unit-test-coverage integration-test-coverage
  106. @hash gocovmerge > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  107. $(GO) get -u github.com/wadey/gocovmerge; \
  108. fi
  109. for PKG in $(PACKAGES); do\
  110. touch $$GOPATH/src/$$PKG/coverage.out;\
  111. egrep "$$PKG[^/]*\.go" integration.coverage.out > int.coverage.out;\
  112. gocovmerge $$GOPATH/src/$$PKG/coverage.out int.coverage.out > pkg.coverage.out;\
  113. mv pkg.coverage.out $$GOPATH/src/$$PKG/coverage.out;\
  114. rm int.coverage.out;\
  115. done;
  116. .PHONY: unit-test-coverage
  117. unit-test-coverage:
  118. for PKG in $(PACKAGES); do $(GO) test -cover -coverprofile $$GOPATH/src/$$PKG/coverage.out $$PKG || exit 1; done;
  119. .PHONY: test-vendor
  120. test-vendor:
  121. @hash govendor > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  122. $(GO) get -u github.com/kardianos/govendor; \
  123. fi
  124. govendor list +unused | tee "$(TMPDIR)/wc-gitea-unused"
  125. [ $$(cat "$(TMPDIR)/wc-gitea-unused" | wc -l) -eq 0 ] || echo "Warning: /!\\ Some vendor are not used /!\\"
  126. govendor list +outside | tee "$(TMPDIR)/wc-gitea-outside"
  127. [ $$(cat "$(TMPDIR)/wc-gitea-outside" | wc -l) -eq 0 ] || exit 1
  128. govendor status || exit 1
  129. .PHONY: test-sqlite
  130. test-sqlite: integrations.sqlite.test
  131. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/sqlite.ini ./integrations.sqlite.test
  132. .PHONY: test-mysql
  133. test-mysql: integrations.test
  134. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql.ini ./integrations.test
  135. .PHONY: test-pgsql
  136. test-pgsql: integrations.test
  137. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/pgsql.ini ./integrations.test
  138. .PHONY: bench-sqlite
  139. bench-sqlite: integrations.sqlite.test
  140. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/sqlite.ini ./integrations.sqlite.test -test.bench .
  141. .PHONY: bench-mysql
  142. bench-mysql: integrations.test
  143. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql.ini ./integrations.test -test.bench .
  144. .PHONY: bench-pgsql
  145. bench-pgsql: integrations.test
  146. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/pgsql.ini ./integrations.test -test.bench .
  147. .PHONY: integration-test-coverage
  148. integration-test-coverage: integrations.cover.test
  149. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql.ini ./integrations.cover.test -test.coverprofile=integration.coverage.out
  150. integrations.test: $(SOURCES)
  151. $(GO) test -c code.gitea.io/gitea/integrations
  152. integrations.sqlite.test: $(SOURCES)
  153. $(GO) test -c code.gitea.io/gitea/integrations -o integrations.sqlite.test -tags 'sqlite'
  154. integrations.cover.test: $(SOURCES)
  155. $(GO) test -c code.gitea.io/gitea/integrations -coverpkg $(shell echo $(PACKAGES) | tr ' ' ',') -o integrations.cover.test
  156. .PHONY: check
  157. check: test
  158. .PHONY: install
  159. install: $(wildcard *.go)
  160. $(GO) install -v -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)'
  161. .PHONY: build
  162. build: $(EXECUTABLE)
  163. $(EXECUTABLE): $(SOURCES)
  164. $(GO) build $(GOFLAGS) $(EXTRA_GOFLAGS) -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)' -o $@
  165. .PHONY: docker
  166. docker:
  167. docker run -ti --rm -v $(CURDIR):/srv/app/src/code.gitea.io/gitea -w /srv/app/src/code.gitea.io/gitea -e TAGS="bindata $(TAGS)" webhippie/golang:edge make clean generate build
  168. docker build -t $(DOCKER_TAG) .
  169. .PHONY: release
  170. release: release-dirs release-windows release-linux release-darwin release-copy release-check
  171. .PHONY: release-dirs
  172. release-dirs:
  173. mkdir -p $(DIST)/binaries $(DIST)/release
  174. .PHONY: release-windows
  175. release-windows:
  176. @hash xgo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  177. $(GO) get -u github.com/karalabe/xgo; \
  178. fi
  179. xgo -dest $(DIST)/binaries -tags 'netgo $(TAGS)' -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -targets 'windows/*' -out gitea-$(VERSION) .
  180. ifeq ($(CI),drone)
  181. mv /build/* $(DIST)/binaries
  182. endif
  183. .PHONY: release-linux
  184. release-linux:
  185. @hash xgo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  186. $(GO) get -u github.com/karalabe/xgo; \
  187. fi
  188. xgo -dest $(DIST)/binaries -tags 'netgo $(TAGS)' -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -targets 'linux/*' -out gitea-$(VERSION) .
  189. ifeq ($(CI),drone)
  190. mv /build/* $(DIST)/binaries
  191. endif
  192. .PHONY: release-darwin
  193. release-darwin:
  194. @hash xgo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  195. $(GO) get -u github.com/karalabe/xgo; \
  196. fi
  197. xgo -dest $(DIST)/binaries -tags 'netgo $(TAGS)' -ldflags '$(LDFLAGS)' -targets 'darwin/*' -out gitea-$(VERSION) .
  198. ifeq ($(CI),drone)
  199. mv /build/* $(DIST)/binaries
  200. endif
  201. .PHONY: release-copy
  202. release-copy:
  203. $(foreach file,$(wildcard $(DIST)/binaries/$(EXECUTABLE)-*),cp $(file) $(DIST)/release/$(notdir $(file));)
  204. .PHONY: release-check
  205. release-check:
  206. cd $(DIST)/release; $(foreach file,$(wildcard $(DIST)/release/$(EXECUTABLE)-*),sha256sum $(notdir $(file)) > $(notdir $(file)).sha256;)
  207. .PHONY: javascripts
  208. javascripts: public/js/index.js
  209. .IGNORE: public/js/index.js
  210. public/js/index.js: $(JAVASCRIPTS)
  211. cat $< >| $@
  212. .PHONY: stylesheets-check
  213. stylesheets-check: stylesheets
  214. @diff=$$(git diff public/css/index.css); \
  215. if [ -n "$$diff" ]; then \
  216. echo "Please run 'make stylesheets' and commit the result:"; \
  217. echo "$${diff}"; \
  218. exit 1; \
  219. fi;
  220. .PHONY: stylesheets
  221. stylesheets: public/css/index.css
  222. .IGNORE: public/css/index.css
  223. public/css/index.css: $(STYLESHEETS)
  224. @which lessc > /dev/null; if [ $$? -ne 0 ]; then \
  225. $(GO) get -u github.com/kib357/less-go/lessc; \
  226. fi
  227. lessc -i $< -o $@
  228. .PHONY: swagger-ui
  229. swagger-ui:
  230. rm -Rf public/vendor/assets/swagger-ui
  231. git clone --depth=10 -b v3.0.7 --single-branch https://github.com/swagger-api/swagger-ui.git $(TMPDIR)/swagger-ui
  232. mv $(TMPDIR)/swagger-ui/dist public/vendor/assets/swagger-ui
  233. rm -Rf $(TMPDIR)/swagger-ui
  234. $(SED_INPLACE) "s;http://petstore.swagger.io/v2/swagger.json;../../swagger.v1.json;g" public/assets/swagger-ui/index.html
  235. .PHONY: update-translations
  236. update-translations:
  237. mkdir -p ./translations
  238. cd ./translations && curl -L https://crowdin.com/download/project/gitea.zip > gitea.zip && unzip gitea.zip
  239. rm ./translations/gitea.zip
  240. $(SED_INPLACE) -e 's/="/=/g' -e 's/"$$//g' ./translations/*.ini
  241. $(SED_INPLACE) -e 's/\\"/"/g' ./translations/*.ini
  242. mv ./translations/*.ini ./options/locale/
  243. rmdir ./translations
  244. .PHONY: generate-images
  245. generate-images:
  246. mkdir -p $(TMPDIR)/images
  247. inkscape -f $(PWD)/assets/logo.svg -w 880 -h 880 -e $(PWD)/public/img/gitea-lg.png
  248. inkscape -f $(PWD)/assets/logo.svg -w 120 -h 120 -jC -i layer1 -e $(TMPDIR)/images/sm-1.png
  249. inkscape -f $(PWD)/assets/logo.svg -w 120 -h 120 -jC -i layer2 -e $(TMPDIR)/images/sm-2.png
  250. composite -compose atop $(TMPDIR)/images/sm-2.png $(TMPDIR)/images/sm-1.png $(PWD)/public/img/gitea-sm.png
  251. inkscape -f $(PWD)/assets/logo.svg -w 200 -h 200 -e $(PWD)/public/img/avatar_default.png
  252. inkscape -f $(PWD)/assets/logo.svg -w 180 -h 180 -e $(PWD)/public/img/favicon.png
  253. inkscape -f $(PWD)/assets/logo.svg -w 128 -h 128 -e $(TMPDIR)/images/128-raw.png
  254. inkscape -f $(PWD)/assets/logo.svg -w 64 -h 64 -e $(TMPDIR)/images/64-raw.png
  255. inkscape -f $(PWD)/assets/logo.svg -w 32 -h 32 -jC -i layer1 -e $(TMPDIR)/images/32-1.png
  256. inkscape -f $(PWD)/assets/logo.svg -w 32 -h 32 -jC -i layer2 -e $(TMPDIR)/images/32-2.png
  257. composite -compose atop $(TMPDIR)/images/32-2.png $(TMPDIR)/images/32-1.png $(TMPDIR)/images/32-raw.png
  258. inkscape -f $(PWD)/assets/logo.svg -w 16 -h 16 -jC -i layer1 -e $(TMPDIR)/images/16-raw.png
  259. zopflipng $(TMPDIR)/images/128-raw.png $(TMPDIR)/images/128.png
  260. zopflipng $(TMPDIR)/images/64-raw.png $(TMPDIR)/images/64.png
  261. zopflipng $(TMPDIR)/images/32-raw.png $(TMPDIR)/images/32.png
  262. zopflipng $(TMPDIR)/images/16-raw.png $(TMPDIR)/images/16.png
  263. rm -f $(TMPDIR)/images/*-*.png
  264. convert $(TMPDIR)/images/16.png $(TMPDIR)/images/32.png \
  265. $(TMPDIR)/images/64.png $(TMPDIR)/images/128.png \
  266. $(PWD)/public/img/favicon.ico
  267. rm -rf $(TMPDIR)/images