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.

Makefile 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  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/migration-test,$(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. .PHONY: test-sqlite-migration
  167. test-sqlite-migration: migrations.sqlite.test
  168. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/sqlite.ini ./migrations.sqlite.test
  169. generate-ini:
  170. sed -e 's|{{TEST_MYSQL_HOST}}|${TEST_MYSQL_HOST}|g' \
  171. -e 's|{{TEST_MYSQL_DBNAME}}|${TEST_MYSQL_DBNAME}|g' \
  172. -e 's|{{TEST_MYSQL_USERNAME}}|${TEST_MYSQL_USERNAME}|g' \
  173. -e 's|{{TEST_MYSQL_PASSWORD}}|${TEST_MYSQL_PASSWORD}|g' \
  174. integrations/mysql.ini.tmpl > integrations/mysql.ini
  175. sed -e 's|{{TEST_PGSQL_HOST}}|${TEST_PGSQL_HOST}|g' \
  176. -e 's|{{TEST_PGSQL_DBNAME}}|${TEST_PGSQL_DBNAME}|g' \
  177. -e 's|{{TEST_PGSQL_USERNAME}}|${TEST_PGSQL_USERNAME}|g' \
  178. -e 's|{{TEST_PGSQL_PASSWORD}}|${TEST_PGSQL_PASSWORD}|g' \
  179. integrations/pgsql.ini.tmpl > integrations/pgsql.ini
  180. sed -e 's|{{TEST_MSSQL_HOST}}|${TEST_MSSQL_HOST}|g' \
  181. -e 's|{{TEST_MSSQL_DBNAME}}|${TEST_MSSQL_DBNAME}|g' \
  182. -e 's|{{TEST_MSSQL_USERNAME}}|${TEST_MSSQL_USERNAME}|g' \
  183. -e 's|{{TEST_MSSQL_PASSWORD}}|${TEST_MSSQL_PASSWORD}|g' \
  184. integrations/mssql.ini.tmpl > integrations/mssql.ini
  185. .PHONY: test-mysql
  186. test-mysql: integrations.test generate-ini
  187. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql.ini ./integrations.test
  188. .PHONY: test-mysql-migration
  189. test-mysql-migration: migrations.test generate-ini
  190. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql.ini ./migrations.test
  191. .PHONY: test-pgsql
  192. test-pgsql: integrations.test generate-ini
  193. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/pgsql.ini ./integrations.test
  194. .PHONY: test-pgsql-migration
  195. test-pgsql-migration: migrations.test generate-ini
  196. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/pgsql.ini ./migrations.test
  197. .PHONY: test-mssql
  198. test-mssql: integrations.test generate-ini
  199. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mssql.ini ./integrations.test
  200. .PHONY: test-mssql-migration
  201. test-mssql-migration: migrations.test generate-ini
  202. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mssql.ini ./migrations.test
  203. .PHONY: bench-sqlite
  204. bench-sqlite: integrations.sqlite.test
  205. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/sqlite.ini ./integrations.sqlite.test -test.cpuprofile=cpu.out -test.run DontRunTests -test.bench .
  206. .PHONY: bench-mysql
  207. bench-mysql: integrations.test generate-ini
  208. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql.ini ./integrations.test -test.cpuprofile=cpu.out -test.run DontRunTests -test.bench .
  209. .PHONY: bench-mssql
  210. bench-mssql: integrations.test generate-ini
  211. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mssql.ini ./integrations.test -test.cpuprofile=cpu.out -test.run DontRunTests -test.bench .
  212. .PHONY: bench-pgsql
  213. bench-pgsql: integrations.test generate-ini
  214. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/pgsql.ini ./integrations.test -test.cpuprofile=cpu.out -test.run DontRunTests -test.bench .
  215. .PHONY: integration-test-coverage
  216. integration-test-coverage: integrations.cover.test generate-ini
  217. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql.ini ./integrations.cover.test -test.coverprofile=integration.coverage.out
  218. integrations.test: $(SOURCES)
  219. $(GO) test -c code.gitea.io/gitea/integrations -o integrations.test
  220. integrations.sqlite.test: $(SOURCES)
  221. $(GO) test -c code.gitea.io/gitea/integrations -o integrations.sqlite.test -tags 'sqlite sqlite_unlock_notify'
  222. integrations.cover.test: $(SOURCES)
  223. $(GO) test -c code.gitea.io/gitea/integrations -coverpkg $(shell echo $(PACKAGES) | tr ' ' ',') -o integrations.cover.test
  224. .PHONY: migrations.test
  225. migrations.test: $(SOURCES)
  226. $(GO) test -c code.gitea.io/gitea/integrations/migration-test -o migrations.test
  227. .PHONY: migrations.sqlite.test
  228. migrations.sqlite.test: $(SOURCES)
  229. $(GO) test -c code.gitea.io/gitea/integrations/migration-test -o migrations.sqlite.test -tags 'sqlite sqlite_unlock_notify'
  230. .PHONY: check
  231. check: test
  232. .PHONY: install
  233. install: $(wildcard *.go)
  234. $(GO) install -v -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)'
  235. .PHONY: build
  236. build: $(EXECUTABLE)
  237. $(EXECUTABLE): $(SOURCES)
  238. $(GO) build $(GOFLAGS) $(EXTRA_GOFLAGS) -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)' -o $@
  239. .PHONY: release
  240. release: release-dirs release-windows release-linux release-darwin release-copy release-compress release-check
  241. .PHONY: release-dirs
  242. release-dirs:
  243. mkdir -p $(DIST)/binaries $(DIST)/release
  244. .PHONY: release-windows
  245. release-windows:
  246. @hash xgo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  247. $(GO) get -u github.com/karalabe/xgo; \
  248. fi
  249. xgo -dest $(DIST)/binaries -tags 'netgo $(TAGS)' -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -targets 'windows/*' -out gitea-$(VERSION) .
  250. ifeq ($(CI),drone)
  251. mv /build/* $(DIST)/binaries
  252. endif
  253. .PHONY: release-linux
  254. release-linux:
  255. @hash xgo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  256. $(GO) get -u github.com/karalabe/xgo; \
  257. fi
  258. xgo -dest $(DIST)/binaries -tags 'netgo $(TAGS)' -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -targets 'linux/*' -out gitea-$(VERSION) .
  259. ifeq ($(CI),drone)
  260. mv /build/* $(DIST)/binaries
  261. endif
  262. .PHONY: release-darwin
  263. release-darwin:
  264. @hash xgo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  265. $(GO) get -u github.com/karalabe/xgo; \
  266. fi
  267. xgo -dest $(DIST)/binaries -tags 'netgo $(TAGS)' -ldflags '$(LDFLAGS)' -targets 'darwin/*' -out gitea-$(VERSION) .
  268. ifeq ($(CI),drone)
  269. mv /build/* $(DIST)/binaries
  270. endif
  271. .PHONY: release-copy
  272. release-copy:
  273. $(foreach file,$(wildcard $(DIST)/binaries/$(EXECUTABLE)-*),cp $(file) $(DIST)/release/$(notdir $(file));)
  274. .PHONY: release-check
  275. release-check:
  276. cd $(DIST)/release; $(foreach file,$(wildcard $(DIST)/release/$(EXECUTABLE)-*),sha256sum $(notdir $(file)) > $(notdir $(file)).sha256;)
  277. .PHONY: release-compress
  278. release-compress:
  279. @hash gxz > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  280. $(GO) get -u github.com/ulikunitz/xz/cmd/gxz; \
  281. fi
  282. cd $(DIST)/release; $(foreach file,$(wildcard $(DIST)/binaries/$(EXECUTABLE)-*),gxz -k -9 $(notdir $(file));)
  283. .PHONY: javascripts
  284. javascripts: public/js/index.js
  285. .IGNORE: public/js/index.js
  286. public/js/index.js: $(JAVASCRIPTS)
  287. cat $< >| $@
  288. .PHONY: stylesheets-check
  289. stylesheets-check: generate-stylesheets
  290. @diff=$$(git diff public/css/*); \
  291. if [ -n "$$diff" ]; then \
  292. echo "Please run 'make generate-stylesheets' and commit the result:"; \
  293. echo "$${diff}"; \
  294. exit 1; \
  295. fi;
  296. .PHONY: generate-stylesheets
  297. generate-stylesheets:
  298. $(eval BROWSERS := "> 2%, last 2 firefox versions, last 2 safari versions")
  299. node_modules/.bin/lessc --clean-css public/less/index.less public/css/index.css
  300. $(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;)
  301. $(foreach file, $(wildcard public/css/*),node_modules/.bin/postcss --use autoprefixer --autoprefixer.browsers $(BROWSERS) -o $(file) $(file);)
  302. .PHONY: swagger-ui
  303. swagger-ui:
  304. rm -Rf public/vendor/assets/swagger-ui
  305. git clone --depth=10 -b v3.13.4 --single-branch https://github.com/swagger-api/swagger-ui.git $(TMPDIR)/swagger-ui
  306. mv $(TMPDIR)/swagger-ui/dist public/vendor/assets/swagger-ui
  307. rm -Rf $(TMPDIR)/swagger-ui
  308. $(SED_INPLACE) "s;http://petstore.swagger.io/v2/swagger.json;../../../swagger.v1.json;g" public/vendor/assets/swagger-ui/index.html
  309. .PHONY: update-translations
  310. update-translations:
  311. mkdir -p ./translations
  312. cd ./translations && curl -L https://crowdin.com/download/project/gitea.zip > gitea.zip && unzip gitea.zip
  313. rm ./translations/gitea.zip
  314. $(SED_INPLACE) -e 's/="/=/g' -e 's/"$$//g' ./translations/*.ini
  315. $(SED_INPLACE) -e 's/\\"/"/g' ./translations/*.ini
  316. mv ./translations/*.ini ./options/locale/
  317. rmdir ./translations
  318. .PHONY: generate-images
  319. generate-images:
  320. mkdir -p $(TMPDIR)/images
  321. inkscape -f $(PWD)/assets/logo.svg -w 880 -h 880 -e $(PWD)/public/img/gitea-lg.png
  322. inkscape -f $(PWD)/assets/logo.svg -w 512 -h 512 -e $(PWD)/public/img/gitea-512.png
  323. inkscape -f $(PWD)/assets/logo.svg -w 192 -h 192 -e $(PWD)/public/img/gitea-192.png
  324. inkscape -f $(PWD)/assets/logo.svg -w 120 -h 120 -jC -i layer1 -e $(TMPDIR)/images/sm-1.png
  325. inkscape -f $(PWD)/assets/logo.svg -w 120 -h 120 -jC -i layer2 -e $(TMPDIR)/images/sm-2.png
  326. composite -compose atop $(TMPDIR)/images/sm-2.png $(TMPDIR)/images/sm-1.png $(PWD)/public/img/gitea-sm.png
  327. inkscape -f $(PWD)/assets/logo.svg -w 200 -h 200 -e $(PWD)/public/img/avatar_default.png
  328. inkscape -f $(PWD)/assets/logo.svg -w 180 -h 180 -e $(PWD)/public/img/favicon.png
  329. inkscape -f $(PWD)/assets/logo.svg -w 128 -h 128 -e $(TMPDIR)/images/128-raw.png
  330. inkscape -f $(PWD)/assets/logo.svg -w 64 -h 64 -e $(TMPDIR)/images/64-raw.png
  331. inkscape -f $(PWD)/assets/logo.svg -w 32 -h 32 -jC -i layer1 -e $(TMPDIR)/images/32-1.png
  332. inkscape -f $(PWD)/assets/logo.svg -w 32 -h 32 -jC -i layer2 -e $(TMPDIR)/images/32-2.png
  333. composite -compose atop $(TMPDIR)/images/32-2.png $(TMPDIR)/images/32-1.png $(TMPDIR)/images/32-raw.png
  334. inkscape -f $(PWD)/assets/logo.svg -w 16 -h 16 -jC -i layer1 -e $(TMPDIR)/images/16-raw.png
  335. zopflipng $(TMPDIR)/images/128-raw.png $(TMPDIR)/images/128.png
  336. zopflipng $(TMPDIR)/images/64-raw.png $(TMPDIR)/images/64.png
  337. zopflipng $(TMPDIR)/images/32-raw.png $(TMPDIR)/images/32.png
  338. zopflipng $(TMPDIR)/images/16-raw.png $(TMPDIR)/images/16.png
  339. rm -f $(TMPDIR)/images/*-*.png
  340. convert $(TMPDIR)/images/16.png $(TMPDIR)/images/32.png \
  341. $(TMPDIR)/images/64.png $(TMPDIR)/images/128.png \
  342. $(PWD)/public/img/favicon.ico
  343. rm -rf $(TMPDIR)/images