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.

343 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. DOCKER_TAG := gitea/gitea:latest
  16. GOFILES := $(shell find . -name "*.go" -type f ! -path "./vendor/*" ! -path "*/bindata.go")
  17. GOFMT ?= gofmt -s
  18. GOFLAGS := -i -v
  19. EXTRA_GOFLAGS ?=
  20. LDFLAGS := -X "main.Version=$(shell git describe --tags --always | sed 's/-/+/' | sed 's/^v//')" -X "main.Tags=$(TAGS)"
  21. PACKAGES ?= $(filter-out code.gitea.io/gitea/integrations,$(shell $(GO) list ./... | grep -v /vendor/))
  22. SOURCES ?= $(shell find . -name "*.go" -type f)
  23. TAGS ?=
  24. TMPDIR := $(shell mktemp -d 2>/dev/null || mktemp -d -t 'gitea-temp')
  25. TEST_MYSQL_HOST ?= mysql:3306
  26. TEST_MYSQL_DBNAME ?= testgitea
  27. TEST_MYSQL_USERNAME ?= root
  28. TEST_MYSQL_PASSWORD ?=
  29. TEST_PGSQL_HOST ?= pgsql:5432
  30. TEST_PGSQL_DBNAME ?= testgitea
  31. TEST_PGSQL_USERNAME ?= postgres
  32. TEST_PGSQL_PASSWORD ?= postgres
  33. ifeq ($(OS), Windows_NT)
  34. EXECUTABLE := gitea.exe
  35. else
  36. EXECUTABLE := gitea
  37. endif
  38. ifneq ($(DRONE_TAG),)
  39. VERSION ?= $(subst v,,$(DRONE_TAG))
  40. else
  41. ifneq ($(DRONE_BRANCH),)
  42. VERSION ?= $(subst release/v,,$(DRONE_BRANCH))
  43. else
  44. VERSION ?= master
  45. endif
  46. endif
  47. .PHONY: all
  48. all: build
  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.mysql.test generate-ini
  153. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql.ini ./integrations.mysql.test
  154. .PHONY: test-pgsql
  155. test-pgsql: integrations.pgsql.test generate-ini
  156. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/pgsql.ini ./integrations.pgsql.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.mysql.test generate-ini
  162. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql.ini ./integrations.mysql.test -test.bench .
  163. .PHONY: bench-pgsql
  164. bench-pgsql: integrations.pgsql.test generate-ini
  165. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/pgsql.ini ./integrations.pgsql.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.mysql.test: $(SOURCES)
  170. $(GO) test -c code.gitea.io/gitea/integrations -o integrations.mysql.test
  171. integrations.pgsql.test: $(SOURCES)
  172. $(GO) test -c code.gitea.io/gitea/integrations -o integrations.pgsql.test
  173. integrations.sqlite.test: $(SOURCES)
  174. $(GO) test -c code.gitea.io/gitea/integrations -o integrations.sqlite.test -tags 'sqlite'
  175. integrations.cover.test: $(SOURCES)
  176. $(GO) test -c code.gitea.io/gitea/integrations -coverpkg $(shell echo $(PACKAGES) | tr ' ' ',') -o integrations.cover.test
  177. .PHONY: check
  178. check: test
  179. .PHONY: install
  180. install: $(wildcard *.go)
  181. $(GO) install -v -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)'
  182. .PHONY: build
  183. build: $(EXECUTABLE)
  184. $(EXECUTABLE): $(SOURCES)
  185. $(GO) build $(GOFLAGS) $(EXTRA_GOFLAGS) -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)' -o $@
  186. .PHONY: docker
  187. docker:
  188. 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
  189. docker build -t $(DOCKER_TAG) .
  190. .PHONY: release
  191. release: release-dirs release-windows release-linux release-darwin release-copy 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: javascripts
  229. javascripts: public/js/index.js
  230. .IGNORE: public/js/index.js
  231. public/js/index.js: $(JAVASCRIPTS)
  232. cat $< >| $@
  233. .PHONY: stylesheets-check
  234. stylesheets-check: generate-stylesheets
  235. @diff=$$(git diff public/css/index.css); \
  236. if [ -n "$$diff" ]; then \
  237. echo "Please run 'make generate-stylesheets' and commit the result:"; \
  238. echo "$${diff}"; \
  239. exit 1; \
  240. fi;
  241. .PHONY: generate-stylesheets
  242. generate-stylesheets:
  243. node_modules/.bin/lessc --no-ie-compat --clean-css public/less/index.less public/css/index.css
  244. .PHONY: swagger-ui
  245. swagger-ui:
  246. rm -Rf public/vendor/assets/swagger-ui
  247. git clone --depth=10 -b v3.3.2 --single-branch https://github.com/swagger-api/swagger-ui.git $(TMPDIR)/swagger-ui
  248. mv $(TMPDIR)/swagger-ui/dist public/vendor/assets/swagger-ui
  249. rm -Rf $(TMPDIR)/swagger-ui
  250. $(SED_INPLACE) "s;http://petstore.swagger.io/v2/swagger.json;../../../swagger.v1.json;g" public/vendor/assets/swagger-ui/index.html
  251. .PHONY: update-translations
  252. update-translations:
  253. mkdir -p ./translations
  254. cd ./translations && curl -L https://crowdin.com/download/project/gitea.zip > gitea.zip && unzip gitea.zip
  255. rm ./translations/gitea.zip
  256. $(SED_INPLACE) -e 's/="/=/g' -e 's/"$$//g' ./translations/*.ini
  257. $(SED_INPLACE) -e 's/\\"/"/g' ./translations/*.ini
  258. mv ./translations/*.ini ./options/locale/
  259. rmdir ./translations
  260. .PHONY: generate-images
  261. generate-images:
  262. mkdir -p $(TMPDIR)/images
  263. inkscape -f $(PWD)/assets/logo.svg -w 880 -h 880 -e $(PWD)/public/img/gitea-lg.png
  264. inkscape -f $(PWD)/assets/logo.svg -w 120 -h 120 -jC -i layer1 -e $(TMPDIR)/images/sm-1.png
  265. inkscape -f $(PWD)/assets/logo.svg -w 120 -h 120 -jC -i layer2 -e $(TMPDIR)/images/sm-2.png
  266. composite -compose atop $(TMPDIR)/images/sm-2.png $(TMPDIR)/images/sm-1.png $(PWD)/public/img/gitea-sm.png
  267. inkscape -f $(PWD)/assets/logo.svg -w 200 -h 200 -e $(PWD)/public/img/avatar_default.png
  268. inkscape -f $(PWD)/assets/logo.svg -w 180 -h 180 -e $(PWD)/public/img/favicon.png
  269. inkscape -f $(PWD)/assets/logo.svg -w 128 -h 128 -e $(TMPDIR)/images/128-raw.png
  270. inkscape -f $(PWD)/assets/logo.svg -w 64 -h 64 -e $(TMPDIR)/images/64-raw.png
  271. inkscape -f $(PWD)/assets/logo.svg -w 32 -h 32 -jC -i layer1 -e $(TMPDIR)/images/32-1.png
  272. inkscape -f $(PWD)/assets/logo.svg -w 32 -h 32 -jC -i layer2 -e $(TMPDIR)/images/32-2.png
  273. composite -compose atop $(TMPDIR)/images/32-2.png $(TMPDIR)/images/32-1.png $(TMPDIR)/images/32-raw.png
  274. inkscape -f $(PWD)/assets/logo.svg -w 16 -h 16 -jC -i layer1 -e $(TMPDIR)/images/16-raw.png
  275. zopflipng $(TMPDIR)/images/128-raw.png $(TMPDIR)/images/128.png
  276. zopflipng $(TMPDIR)/images/64-raw.png $(TMPDIR)/images/64.png
  277. zopflipng $(TMPDIR)/images/32-raw.png $(TMPDIR)/images/32.png
  278. zopflipng $(TMPDIR)/images/16-raw.png $(TMPDIR)/images/16.png
  279. rm -f $(TMPDIR)/images/*-*.png
  280. convert $(TMPDIR)/images/16.png $(TMPDIR)/images/32.png \
  281. $(TMPDIR)/images/64.png $(TMPDIR)/images/128.png \
  282. $(PWD)/public/img/favicon.ico
  283. rm -rf $(TMPDIR)/images