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.

336 lines
11 KiB

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