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.

362 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. ifneq ($(DRONE_TAG),)
  20. VERSION ?= $(subst v,,$(DRONE_TAG))
  21. GITEA_VERSION := $(VERSION)
  22. else
  23. ifneq ($(DRONE_BRANCH),)
  24. VERSION ?= $(subst release/v,,$(DRONE_BRANCH))
  25. else
  26. VERSION ?= master
  27. endif
  28. GITEA_VERSION := $(shell git describe --tags --always | sed 's/-/+/' | sed 's/^v//')
  29. endif
  30. LDFLAGS := -X "main.Version=$(GITEA_VERSION)" -X "main.Tags=$(TAGS)"
  31. PACKAGES ?= $(filter-out code.gitea.io/gitea/integrations,$(shell $(GO) list ./... | grep -v /vendor/))
  32. SOURCES ?= $(shell find . -name "*.go" -type f)
  33. TAGS ?=
  34. TMPDIR := $(shell mktemp -d 2>/dev/null || mktemp -d -t 'gitea-temp')
  35. TEST_MYSQL_HOST ?= mysql:3306
  36. TEST_MYSQL_DBNAME ?= testgitea
  37. TEST_MYSQL_USERNAME ?= root
  38. TEST_MYSQL_PASSWORD ?=
  39. TEST_PGSQL_HOST ?= pgsql:5432
  40. TEST_PGSQL_DBNAME ?= testgitea
  41. TEST_PGSQL_USERNAME ?= postgres
  42. TEST_PGSQL_PASSWORD ?= postgres
  43. ifeq ($(OS), Windows_NT)
  44. EXECUTABLE := gitea.exe
  45. else
  46. EXECUTABLE := gitea
  47. endif
  48. # $(call strip-suffix,filename)
  49. strip-suffix = $(firstword $(subst ., ,$(1)))
  50. .PHONY: all
  51. all: build
  52. include docker/Makefile
  53. .PHONY: clean
  54. clean:
  55. $(GO) clean -i ./...
  56. rm -rf $(EXECUTABLE) $(DIST) $(BINDATA) \
  57. integrations*.test \
  58. integrations/gitea-integration-pgsql/ integrations/gitea-integration-mysql/ integrations/gitea-integration-sqlite/ \
  59. integrations/indexers-mysql/ integrations/indexers-pgsql integrations/indexers-sqlite \
  60. integrations/mysql.ini integrations/pgsql.ini
  61. .PHONY: fmt
  62. fmt:
  63. $(GOFMT) -w $(GOFILES)
  64. .PHONY: vet
  65. vet:
  66. $(GO) vet $(PACKAGES)
  67. .PHONY: generate
  68. generate:
  69. @hash go-bindata > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  70. $(GO) get -u github.com/jteeuwen/go-bindata/...; \
  71. fi
  72. $(GO) generate $(PACKAGES)
  73. .PHONY: generate-swagger
  74. generate-swagger:
  75. @hash swagger > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  76. $(GO) get -u github.com/go-swagger/go-swagger/cmd/swagger; \
  77. fi
  78. swagger generate spec -o ./public/swagger.v1.json
  79. .PHONY: swagger-check
  80. swagger-check: generate-swagger
  81. @diff=$$(git diff public/swagger.v1.json); \
  82. if [ -n "$$diff" ]; then \
  83. echo "Please run 'make generate-swagger' and commit the result:"; \
  84. echo "$${diff}"; \
  85. exit 1; \
  86. fi;
  87. .PHONY: swagger-validate
  88. swagger-validate:
  89. @hash swagger > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  90. $(GO) get -u github.com/go-swagger/go-swagger/cmd/swagger; \
  91. fi
  92. swagger validate ./public/swagger.v1.json
  93. .PHONY: errcheck
  94. errcheck:
  95. @hash errcheck > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  96. $(GO) get -u github.com/kisielk/errcheck; \
  97. fi
  98. errcheck $(PACKAGES)
  99. .PHONY: lint
  100. lint:
  101. @hash golint > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  102. $(GO) get -u github.com/golang/lint/golint; \
  103. fi
  104. for PKG in $(PACKAGES); do golint -set_exit_status $$PKG || exit 1; done;
  105. .PHONY: misspell-check
  106. misspell-check:
  107. @hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  108. $(GO) get -u github.com/client9/misspell/cmd/misspell; \
  109. fi
  110. misspell -error -i unknwon $(GOFILES)
  111. .PHONY: misspell
  112. misspell:
  113. @hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  114. $(GO) get -u github.com/client9/misspell/cmd/misspell; \
  115. fi
  116. misspell -w -i unknwon $(GOFILES)
  117. .PHONY: fmt-check
  118. fmt-check:
  119. # get all go files and run go fmt on them
  120. @diff=$$($(GOFMT) -d $(GOFILES)); \
  121. if [ -n "$$diff" ]; then \
  122. echo "Please run 'make fmt' and commit the result:"; \
  123. echo "$${diff}"; \
  124. exit 1; \
  125. fi;
  126. .PHONY: test
  127. test:
  128. $(GO) test -tags=sqlite $(PACKAGES)
  129. .PHONY: coverage
  130. coverage:
  131. @hash gocovmerge > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  132. $(GO) get -u github.com/wadey/gocovmerge; \
  133. fi
  134. gocovmerge integration.coverage.out $(shell find . -type f -name "coverage.out") > coverage.all;\
  135. .PHONY: unit-test-coverage
  136. unit-test-coverage:
  137. for PKG in $(PACKAGES); do $(GO) test -tags=sqlite -cover -coverprofile $$GOPATH/src/$$PKG/coverage.out $$PKG || exit 1; done;
  138. .PHONY: vendor
  139. vendor:
  140. @hash dep > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  141. $(GO) get -u github.com/golang/dep/cmd/dep; \
  142. fi
  143. dep ensure -vendor-only
  144. .PHONY: test-vendor
  145. test-vendor: vendor
  146. @diff=$$(git diff vendor/); \
  147. if [ -n "$$diff" ]; then \
  148. echo "Please run 'make vendor' and commit the result:"; \
  149. echo "$${diff}"; \
  150. exit 1; \
  151. fi;
  152. #TODO add dep status -missing when implemented
  153. .PHONY: test-sqlite
  154. test-sqlite: integrations.sqlite.test
  155. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/sqlite.ini ./integrations.sqlite.test
  156. generate-ini:
  157. sed -e 's|{{TEST_MYSQL_HOST}}|${TEST_MYSQL_HOST}|g' \
  158. -e 's|{{TEST_MYSQL_DBNAME}}|${TEST_MYSQL_DBNAME}|g' \
  159. -e 's|{{TEST_MYSQL_USERNAME}}|${TEST_MYSQL_USERNAME}|g' \
  160. -e 's|{{TEST_MYSQL_PASSWORD}}|${TEST_MYSQL_PASSWORD}|g' \
  161. integrations/mysql.ini.tmpl > integrations/mysql.ini
  162. sed -e 's|{{TEST_PGSQL_HOST}}|${TEST_PGSQL_HOST}|g' \
  163. -e 's|{{TEST_PGSQL_DBNAME}}|${TEST_PGSQL_DBNAME}|g' \
  164. -e 's|{{TEST_PGSQL_USERNAME}}|${TEST_PGSQL_USERNAME}|g' \
  165. -e 's|{{TEST_PGSQL_PASSWORD}}|${TEST_PGSQL_PASSWORD}|g' \
  166. integrations/pgsql.ini.tmpl > integrations/pgsql.ini
  167. .PHONY: test-mysql
  168. test-mysql: integrations.test generate-ini
  169. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql.ini ./integrations.test
  170. .PHONY: test-pgsql
  171. test-pgsql: integrations.test generate-ini
  172. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/pgsql.ini ./integrations.test
  173. .PHONY: bench-sqlite
  174. bench-sqlite: integrations.sqlite.test
  175. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/sqlite.ini ./integrations.sqlite.test -test.cpuprofile=cpu.out -test.run DontRunTests -test.bench .
  176. .PHONY: bench-mysql
  177. bench-mysql: integrations.test generate-ini
  178. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql.ini ./integrations.test -test.cpuprofile=cpu.out -test.run DontRunTests -test.bench .
  179. .PHONY: bench-pgsql
  180. bench-pgsql: integrations.test generate-ini
  181. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/pgsql.ini ./integrations.test -test.cpuprofile=cpu.out -test.run DontRunTests -test.bench .
  182. .PHONY: integration-test-coverage
  183. integration-test-coverage: integrations.cover.test generate-ini
  184. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql.ini ./integrations.cover.test -test.coverprofile=integration.coverage.out
  185. integrations.test: $(SOURCES)
  186. $(GO) test -c code.gitea.io/gitea/integrations -o integrations.test
  187. integrations.sqlite.test: $(SOURCES)
  188. $(GO) test -c code.gitea.io/gitea/integrations -o integrations.sqlite.test -tags 'sqlite'
  189. integrations.cover.test: $(SOURCES)
  190. $(GO) test -c code.gitea.io/gitea/integrations -coverpkg $(shell echo $(PACKAGES) | tr ' ' ',') -o integrations.cover.test
  191. .PHONY: check
  192. check: test
  193. .PHONY: install
  194. install: $(wildcard *.go)
  195. $(GO) install -v -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)'
  196. .PHONY: build
  197. build: $(EXECUTABLE)
  198. $(EXECUTABLE): $(SOURCES)
  199. $(GO) build $(GOFLAGS) $(EXTRA_GOFLAGS) -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)' -o $@
  200. .PHONY: release
  201. release: release-dirs release-windows release-linux release-darwin release-copy release-compress release-check
  202. .PHONY: release-dirs
  203. release-dirs:
  204. mkdir -p $(DIST)/binaries $(DIST)/release
  205. .PHONY: release-windows
  206. release-windows:
  207. @hash xgo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  208. $(GO) get -u github.com/karalabe/xgo; \
  209. fi
  210. xgo -dest $(DIST)/binaries -tags 'netgo $(TAGS)' -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -targets 'windows/*' -out gitea-$(VERSION) .
  211. ifeq ($(CI),drone)
  212. mv /build/* $(DIST)/binaries
  213. endif
  214. .PHONY: release-linux
  215. release-linux:
  216. @hash xgo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  217. $(GO) get -u github.com/karalabe/xgo; \
  218. fi
  219. xgo -dest $(DIST)/binaries -tags 'netgo $(TAGS)' -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -targets 'linux/*' -out gitea-$(VERSION) .
  220. ifeq ($(CI),drone)
  221. mv /build/* $(DIST)/binaries
  222. endif
  223. .PHONY: release-darwin
  224. release-darwin:
  225. @hash xgo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  226. $(GO) get -u github.com/karalabe/xgo; \
  227. fi
  228. xgo -dest $(DIST)/binaries -tags 'netgo $(TAGS)' -ldflags '$(LDFLAGS)' -targets 'darwin/*' -out gitea-$(VERSION) .
  229. ifeq ($(CI),drone)
  230. mv /build/* $(DIST)/binaries
  231. endif
  232. .PHONY: release-copy
  233. release-copy:
  234. $(foreach file,$(wildcard $(DIST)/binaries/$(EXECUTABLE)-*),cp $(file) $(DIST)/release/$(notdir $(file));)
  235. .PHONY: release-check
  236. release-check:
  237. cd $(DIST)/release; $(foreach file,$(wildcard $(DIST)/release/$(EXECUTABLE)-*),sha256sum $(notdir $(file)) > $(notdir $(file)).sha256;)
  238. .PHONY: release-compress
  239. release-compress:
  240. @hash gxz > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  241. $(GO) get -u github.com/ulikunitz/xz/cmd/gxz; \
  242. fi
  243. cd $(DIST)/release; $(foreach file,$(wildcard $(DIST)/binaries/$(EXECUTABLE)-*),gxz -k -9 $(notdir $(file));)
  244. .PHONY: javascripts
  245. javascripts: public/js/index.js
  246. .IGNORE: public/js/index.js
  247. public/js/index.js: $(JAVASCRIPTS)
  248. cat $< >| $@
  249. .PHONY: stylesheets-check
  250. stylesheets-check: generate-stylesheets
  251. @diff=$$(git diff public/css/*); \
  252. if [ -n "$$diff" ]; then \
  253. echo "Please run 'make generate-stylesheets' and commit the result:"; \
  254. echo "$${diff}"; \
  255. exit 1; \
  256. fi;
  257. .PHONY: generate-stylesheets
  258. generate-stylesheets:
  259. node_modules/.bin/lessc --clean-css public/less/index.less public/css/index.css
  260. $(foreach file, $(filter-out public/less/themes/_base.less, $(wildcard public/less/themes/*)),node_modules/.bin/lessc --clean-css public/less/themes/$(notdir $(file)) > public/css/theme-$(notdir $(call strip-suffix,$(file))).css;)
  261. .PHONY: swagger-ui
  262. swagger-ui:
  263. rm -Rf public/vendor/assets/swagger-ui
  264. git clone --depth=10 -b v3.13.4 --single-branch https://github.com/swagger-api/swagger-ui.git $(TMPDIR)/swagger-ui
  265. mv $(TMPDIR)/swagger-ui/dist public/vendor/assets/swagger-ui
  266. rm -Rf $(TMPDIR)/swagger-ui
  267. $(SED_INPLACE) "s;http://petstore.swagger.io/v2/swagger.json;../../../swagger.v1.json;g" public/vendor/assets/swagger-ui/index.html
  268. .PHONY: update-translations
  269. update-translations:
  270. mkdir -p ./translations
  271. cd ./translations && curl -L https://crowdin.com/download/project/gitea.zip > gitea.zip && unzip gitea.zip
  272. rm ./translations/gitea.zip
  273. $(SED_INPLACE) -e 's/="/=/g' -e 's/"$$//g' ./translations/*.ini
  274. $(SED_INPLACE) -e 's/\\"/"/g' ./translations/*.ini
  275. mv ./translations/*.ini ./options/locale/
  276. rmdir ./translations
  277. .PHONY: generate-images
  278. generate-images:
  279. mkdir -p $(TMPDIR)/images
  280. inkscape -f $(PWD)/assets/logo.svg -w 880 -h 880 -e $(PWD)/public/img/gitea-lg.png
  281. inkscape -f $(PWD)/assets/logo.svg -w 120 -h 120 -jC -i layer1 -e $(TMPDIR)/images/sm-1.png
  282. inkscape -f $(PWD)/assets/logo.svg -w 120 -h 120 -jC -i layer2 -e $(TMPDIR)/images/sm-2.png
  283. composite -compose atop $(TMPDIR)/images/sm-2.png $(TMPDIR)/images/sm-1.png $(PWD)/public/img/gitea-sm.png
  284. inkscape -f $(PWD)/assets/logo.svg -w 200 -h 200 -e $(PWD)/public/img/avatar_default.png
  285. inkscape -f $(PWD)/assets/logo.svg -w 180 -h 180 -e $(PWD)/public/img/favicon.png
  286. inkscape -f $(PWD)/assets/logo.svg -w 128 -h 128 -e $(TMPDIR)/images/128-raw.png
  287. inkscape -f $(PWD)/assets/logo.svg -w 64 -h 64 -e $(TMPDIR)/images/64-raw.png
  288. inkscape -f $(PWD)/assets/logo.svg -w 32 -h 32 -jC -i layer1 -e $(TMPDIR)/images/32-1.png
  289. inkscape -f $(PWD)/assets/logo.svg -w 32 -h 32 -jC -i layer2 -e $(TMPDIR)/images/32-2.png
  290. composite -compose atop $(TMPDIR)/images/32-2.png $(TMPDIR)/images/32-1.png $(TMPDIR)/images/32-raw.png
  291. inkscape -f $(PWD)/assets/logo.svg -w 16 -h 16 -jC -i layer1 -e $(TMPDIR)/images/16-raw.png
  292. zopflipng $(TMPDIR)/images/128-raw.png $(TMPDIR)/images/128.png
  293. zopflipng $(TMPDIR)/images/64-raw.png $(TMPDIR)/images/64.png
  294. zopflipng $(TMPDIR)/images/32-raw.png $(TMPDIR)/images/32.png
  295. zopflipng $(TMPDIR)/images/16-raw.png $(TMPDIR)/images/16.png
  296. rm -f $(TMPDIR)/images/*-*.png
  297. convert $(TMPDIR)/images/16.png $(TMPDIR)/images/32.png \
  298. $(TMPDIR)/images/64.png $(TMPDIR)/images/128.png \
  299. $(PWD)/public/img/favicon.ico
  300. rm -rf $(TMPDIR)/images