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.

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