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.

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