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

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