Makefile 13 KB

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