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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  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: test-vendor
  129. test-vendor:
  130. @hash govendor > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  131. $(GO) get -u github.com/kardianos/govendor; \
  132. fi
  133. govendor list +unused | tee "$(TMPDIR)/wc-gitea-unused"
  134. [ $$(cat "$(TMPDIR)/wc-gitea-unused" | wc -l) -eq 0 ] || echo "Warning: /!\\ Some vendor are not used /!\\"
  135. govendor list +outside | tee "$(TMPDIR)/wc-gitea-outside"
  136. [ $$(cat "$(TMPDIR)/wc-gitea-outside" | wc -l) -eq 0 ] || exit 1
  137. govendor status || exit 1
  138. .PHONY: test-sqlite
  139. test-sqlite: integrations.sqlite.test
  140. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/sqlite.ini ./integrations.sqlite.test
  141. generate-ini:
  142. sed -e 's|{{TEST_MYSQL_HOST}}|${TEST_MYSQL_HOST}|g' \
  143. -e 's|{{TEST_MYSQL_DBNAME}}|${TEST_MYSQL_DBNAME}|g' \
  144. -e 's|{{TEST_MYSQL_USERNAME}}|${TEST_MYSQL_USERNAME}|g' \
  145. -e 's|{{TEST_MYSQL_PASSWORD}}|${TEST_MYSQL_PASSWORD}|g' \
  146. integrations/mysql.ini.tmpl > integrations/mysql.ini
  147. sed -e 's|{{TEST_PGSQL_HOST}}|${TEST_PGSQL_HOST}|g' \
  148. -e 's|{{TEST_PGSQL_DBNAME}}|${TEST_PGSQL_DBNAME}|g' \
  149. -e 's|{{TEST_PGSQL_USERNAME}}|${TEST_PGSQL_USERNAME}|g' \
  150. -e 's|{{TEST_PGSQL_PASSWORD}}|${TEST_PGSQL_PASSWORD}|g' \
  151. integrations/pgsql.ini.tmpl > integrations/pgsql.ini
  152. .PHONY: test-mysql
  153. test-mysql: integrations.test generate-ini
  154. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql.ini ./integrations.test
  155. .PHONY: test-pgsql
  156. test-pgsql: integrations.test generate-ini
  157. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/pgsql.ini ./integrations.test
  158. .PHONY: bench-sqlite
  159. bench-sqlite: integrations.sqlite.test
  160. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/sqlite.ini ./integrations.sqlite.test -test.cpuprofile=cpu.out -test.run DontRunTests -test.bench .
  161. .PHONY: bench-mysql
  162. bench-mysql: integrations.test generate-ini
  163. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql.ini ./integrations.test -test.cpuprofile=cpu.out -test.run DontRunTests -test.bench .
  164. .PHONY: bench-pgsql
  165. bench-pgsql: integrations.test generate-ini
  166. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/pgsql.ini ./integrations.test -test.cpuprofile=cpu.out -test.run DontRunTests -test.bench .
  167. .PHONY: integration-test-coverage
  168. integration-test-coverage: integrations.cover.test generate-ini
  169. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql.ini ./integrations.cover.test -test.coverprofile=integration.coverage.out
  170. integrations.test: $(SOURCES)
  171. $(GO) test -c code.gitea.io/gitea/integrations -o integrations.test
  172. integrations.sqlite.test: $(SOURCES)
  173. $(GO) test -c code.gitea.io/gitea/integrations -o integrations.sqlite.test -tags 'sqlite'
  174. integrations.cover.test: $(SOURCES)
  175. $(GO) test -c code.gitea.io/gitea/integrations -coverpkg $(shell echo $(PACKAGES) | tr ' ' ',') -o integrations.cover.test
  176. .PHONY: check
  177. check: test
  178. .PHONY: install
  179. install: $(wildcard *.go)
  180. $(GO) install -v -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)'
  181. .PHONY: build
  182. build: $(EXECUTABLE)
  183. $(EXECUTABLE): $(SOURCES)
  184. $(GO) build $(GOFLAGS) $(EXTRA_GOFLAGS) -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)' -o $@
  185. .PHONY: release
  186. release: release-dirs release-windows release-linux release-darwin release-copy release-check
  187. .PHONY: release-dirs
  188. release-dirs:
  189. mkdir -p $(DIST)/binaries $(DIST)/release
  190. .PHONY: release-windows
  191. release-windows:
  192. @hash xgo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  193. $(GO) get -u github.com/karalabe/xgo; \
  194. fi
  195. xgo -dest $(DIST)/binaries -tags 'netgo $(TAGS)' -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -targets 'windows/*' -out gitea-$(VERSION) .
  196. ifeq ($(CI),drone)
  197. mv /build/* $(DIST)/binaries
  198. endif
  199. .PHONY: release-linux
  200. release-linux:
  201. @hash xgo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  202. $(GO) get -u github.com/karalabe/xgo; \
  203. fi
  204. xgo -dest $(DIST)/binaries -tags 'netgo $(TAGS)' -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -targets 'linux/*' -out gitea-$(VERSION) .
  205. ifeq ($(CI),drone)
  206. mv /build/* $(DIST)/binaries
  207. endif
  208. .PHONY: release-darwin
  209. release-darwin:
  210. @hash xgo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  211. $(GO) get -u github.com/karalabe/xgo; \
  212. fi
  213. xgo -dest $(DIST)/binaries -tags 'netgo $(TAGS)' -ldflags '$(LDFLAGS)' -targets 'darwin/*' -out gitea-$(VERSION) .
  214. ifeq ($(CI),drone)
  215. mv /build/* $(DIST)/binaries
  216. endif
  217. .PHONY: release-copy
  218. release-copy:
  219. $(foreach file,$(wildcard $(DIST)/binaries/$(EXECUTABLE)-*),cp $(file) $(DIST)/release/$(notdir $(file));)
  220. .PHONY: release-check
  221. release-check:
  222. cd $(DIST)/release; $(foreach file,$(wildcard $(DIST)/release/$(EXECUTABLE)-*),sha256sum $(notdir $(file)) > $(notdir $(file)).sha256;)
  223. .PHONY: javascripts
  224. javascripts: public/js/index.js
  225. .IGNORE: public/js/index.js
  226. public/js/index.js: $(JAVASCRIPTS)
  227. cat $< >| $@
  228. .PHONY: stylesheets-check
  229. stylesheets-check: generate-stylesheets
  230. @diff=$$(git diff public/css/index.css); \
  231. if [ -n "$$diff" ]; then \
  232. echo "Please run 'make generate-stylesheets' and commit the result:"; \
  233. echo "$${diff}"; \
  234. exit 1; \
  235. fi;
  236. .PHONY: generate-stylesheets
  237. generate-stylesheets:
  238. node_modules/.bin/lessc --no-ie-compat --clean-css public/less/index.less public/css/index.css
  239. .PHONY: swagger-ui
  240. swagger-ui:
  241. rm -Rf public/vendor/assets/swagger-ui
  242. git clone --depth=10 -b v3.13.4 --single-branch https://github.com/swagger-api/swagger-ui.git $(TMPDIR)/swagger-ui
  243. mv $(TMPDIR)/swagger-ui/dist public/vendor/assets/swagger-ui
  244. rm -Rf $(TMPDIR)/swagger-ui
  245. $(SED_INPLACE) "s;http://petstore.swagger.io/v2/swagger.json;../../../swagger.v1.json;g" public/vendor/assets/swagger-ui/index.html
  246. .PHONY: update-translations
  247. update-translations:
  248. mkdir -p ./translations
  249. cd ./translations && curl -L https://crowdin.com/download/project/gitea.zip > gitea.zip && unzip gitea.zip
  250. rm ./translations/gitea.zip
  251. $(SED_INPLACE) -e 's/="/=/g' -e 's/"$$//g' ./translations/*.ini
  252. $(SED_INPLACE) -e 's/\\"/"/g' ./translations/*.ini
  253. mv ./translations/*.ini ./options/locale/
  254. rmdir ./translations
  255. .PHONY: generate-images
  256. generate-images:
  257. mkdir -p $(TMPDIR)/images
  258. inkscape -f $(PWD)/assets/logo.svg -w 880 -h 880 -e $(PWD)/public/img/gitea-lg.png
  259. inkscape -f $(PWD)/assets/logo.svg -w 120 -h 120 -jC -i layer1 -e $(TMPDIR)/images/sm-1.png
  260. inkscape -f $(PWD)/assets/logo.svg -w 120 -h 120 -jC -i layer2 -e $(TMPDIR)/images/sm-2.png
  261. composite -compose atop $(TMPDIR)/images/sm-2.png $(TMPDIR)/images/sm-1.png $(PWD)/public/img/gitea-sm.png
  262. inkscape -f $(PWD)/assets/logo.svg -w 200 -h 200 -e $(PWD)/public/img/avatar_default.png
  263. inkscape -f $(PWD)/assets/logo.svg -w 180 -h 180 -e $(PWD)/public/img/favicon.png
  264. inkscape -f $(PWD)/assets/logo.svg -w 128 -h 128 -e $(TMPDIR)/images/128-raw.png
  265. inkscape -f $(PWD)/assets/logo.svg -w 64 -h 64 -e $(TMPDIR)/images/64-raw.png
  266. inkscape -f $(PWD)/assets/logo.svg -w 32 -h 32 -jC -i layer1 -e $(TMPDIR)/images/32-1.png
  267. inkscape -f $(PWD)/assets/logo.svg -w 32 -h 32 -jC -i layer2 -e $(TMPDIR)/images/32-2.png
  268. composite -compose atop $(TMPDIR)/images/32-2.png $(TMPDIR)/images/32-1.png $(TMPDIR)/images/32-raw.png
  269. inkscape -f $(PWD)/assets/logo.svg -w 16 -h 16 -jC -i layer1 -e $(TMPDIR)/images/16-raw.png
  270. zopflipng $(TMPDIR)/images/128-raw.png $(TMPDIR)/images/128.png
  271. zopflipng $(TMPDIR)/images/64-raw.png $(TMPDIR)/images/64.png
  272. zopflipng $(TMPDIR)/images/32-raw.png $(TMPDIR)/images/32.png
  273. zopflipng $(TMPDIR)/images/16-raw.png $(TMPDIR)/images/16.png
  274. rm -f $(TMPDIR)/images/*-*.png
  275. convert $(TMPDIR)/images/16.png $(TMPDIR)/images/32.png \
  276. $(TMPDIR)/images/64.png $(TMPDIR)/images/128.png \
  277. $(PWD)/public/img/favicon.ico
  278. rm -rf $(TMPDIR)/images