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.

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