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.

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