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

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