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.

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