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

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