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

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