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 25KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. ifeq ($(USE_REPO_TEST_DIR),1)
  2. # This rule replaces the whole Makefile when we're trying to use /tmp repository temporary files
  3. location = $(CURDIR)/$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
  4. self := $(location)
  5. %:
  6. @tmpdir=`mktemp --tmpdir -d` ; \
  7. echo Using temporary directory $$tmpdir for test repositories ; \
  8. USE_REPO_TEST_DIR= $(MAKE) -f $(self) --no-print-directory REPO_TEST_DIR=$$tmpdir/ $@ ; \
  9. STATUS=$$? ; rm -r "$$tmpdir" ; exit $$STATUS
  10. else
  11. # This is the "normal" part of the Makefile
  12. DIST := dist
  13. DIST_DIRS := $(DIST)/binaries $(DIST)/release
  14. IMPORT := code.gitea.io/gitea
  15. export GO111MODULE=on
  16. GO ?= go
  17. SED_INPLACE := sed -i
  18. SHASUM ?= shasum -a 256
  19. HAS_GO = $(shell hash $(GO) > /dev/null 2>&1 && echo "GO" || echo "NOGO" )
  20. COMMA := ,
  21. XGO_VERSION := go-1.14.x
  22. MIN_GO_VERSION := 001012000
  23. MIN_NODE_VERSION := 010013000
  24. ifeq ($(HAS_GO), GO)
  25. GOPATH ?= $(shell $(GO) env GOPATH)
  26. export PATH := $(GOPATH)/bin:$(PATH)
  27. CGO_EXTRA_CFLAGS := -DSQLITE_MAX_VARIABLE_NUMBER=32766
  28. CGO_CFLAGS ?= $(shell $(GO) env CGO_CFLAGS) $(CGO_EXTRA_CFLAGS)
  29. endif
  30. ifeq ($(OS), Windows_NT)
  31. GOFLAGS := -v -buildmode=exe
  32. EXECUTABLE ?= gitea.exe
  33. else
  34. GOFLAGS := -v
  35. EXECUTABLE ?= gitea
  36. UNAME_S := $(shell uname -s)
  37. ifeq ($(UNAME_S),Darwin)
  38. SED_INPLACE := sed -i ''
  39. endif
  40. ifeq ($(UNAME_S),FreeBSD)
  41. SED_INPLACE := sed -i ''
  42. endif
  43. endif
  44. GOFMT ?= gofmt -s
  45. EXTRA_GOFLAGS ?=
  46. MAKE_VERSION := $(shell $(MAKE) -v | head -n 1)
  47. MAKE_EVIDENCE_DIR := .make_evidence
  48. ifneq ($(RACE_ENABLED),)
  49. GOTESTFLAGS ?= -race
  50. endif
  51. STORED_VERSION_FILE := VERSION
  52. ifneq ($(DRONE_TAG),)
  53. VERSION ?= $(subst v,,$(DRONE_TAG))
  54. GITEA_VERSION ?= $(VERSION)
  55. else
  56. ifneq ($(DRONE_BRANCH),)
  57. VERSION ?= $(subst release/v,,$(DRONE_BRANCH))
  58. else
  59. VERSION ?= master
  60. endif
  61. STORED_VERSION=$(shell cat $(STORED_VERSION_FILE) 2>/dev/null)
  62. ifneq ($(STORED_VERSION),)
  63. GITEA_VERSION ?= $(STORED_VERSION)
  64. else
  65. GITEA_VERSION ?= $(shell git describe --tags --always | sed 's/-/+/' | sed 's/^v//')
  66. endif
  67. endif
  68. LDFLAGS := $(LDFLAGS) -X "main.MakeVersion=$(MAKE_VERSION)" -X "main.Version=$(GITEA_VERSION)" -X "main.Tags=$(TAGS)"
  69. GO_PACKAGES ?= $(filter-out code.gitea.io/gitea/integrations/migration-test,$(filter-out code.gitea.io/gitea/integrations,$(shell $(GO) list -mod=vendor ./... | grep -v /vendor/)))
  70. WEBPACK_SOURCES := $(shell find web_src/js web_src/less -type f)
  71. WEBPACK_CONFIGS := webpack.config.js
  72. WEBPACK_DEST := public/js/index.js public/css/index.css
  73. WEBPACK_DEST_ENTRIES := public/js public/css public/fonts public/serviceworker.js
  74. BINDATA_DEST := modules/public/bindata.go modules/options/bindata.go modules/templates/bindata.go
  75. BINDATA_HASH := $(addsuffix .hash,$(BINDATA_DEST))
  76. TAGS ?=
  77. TAGS_SPLIT := $(subst $(COMMA), ,$(TAGS))
  78. TAGS_EVIDENCE := $(MAKE_EVIDENCE_DIR)/tags
  79. GO_DIRS := cmd integrations models modules routers build services vendor
  80. GO_SOURCES := $(wildcard *.go)
  81. GO_SOURCES += $(shell find $(GO_DIRS) -type f -name "*.go" -not -path modules/options/bindata.go -not -path modules/public/bindata.go -not -path modules/templates/bindata.go)
  82. ifeq ($(filter $(TAGS_SPLIT),bindata),bindata)
  83. GO_SOURCES += $(BINDATA_DEST)
  84. endif
  85. GO_SOURCES_OWN := $(filter-out vendor/% %/bindata.go, $(GO_SOURCES))
  86. FOMANTIC_CONFIGS := semantic.json web_src/fomantic/theme.config.less web_src/fomantic/_site/globals/site.variables web_src/fomantic/css.js
  87. FOMANTIC_DEST := public/fomantic/semantic.min.js public/fomantic/semantic.min.css
  88. FOMANTIC_DEST_DIR := public/fomantic
  89. #To update swagger use: GO111MODULE=on go get -u github.com/go-swagger/go-swagger/cmd/swagger@v0.20.1
  90. SWAGGER := $(GO) run -mod=vendor github.com/go-swagger/go-swagger/cmd/swagger
  91. SWAGGER_SPEC := templates/swagger/v1_json.tmpl
  92. SWAGGER_SPEC_S_TMPL := s|"basePath": *"/api/v1"|"basePath": "{{AppSubUrl}}/api/v1"|g
  93. SWAGGER_SPEC_S_JSON := s|"basePath": *"{{AppSubUrl}}/api/v1"|"basePath": "/api/v1"|g
  94. SWAGGER_NEWLINE_COMMAND := -e '$$a\'
  95. TEST_MYSQL_HOST ?= mysql:3306
  96. TEST_MYSQL_DBNAME ?= testgitea
  97. TEST_MYSQL_USERNAME ?= root
  98. TEST_MYSQL_PASSWORD ?=
  99. TEST_MYSQL8_HOST ?= mysql8:3306
  100. TEST_MYSQL8_DBNAME ?= testgitea
  101. TEST_MYSQL8_USERNAME ?= root
  102. TEST_MYSQL8_PASSWORD ?=
  103. TEST_PGSQL_HOST ?= pgsql:5432
  104. TEST_PGSQL_DBNAME ?= testgitea
  105. TEST_PGSQL_USERNAME ?= postgres
  106. TEST_PGSQL_PASSWORD ?= postgres
  107. TEST_PGSQL_SCHEMA ?= gtestschema
  108. TEST_MSSQL_HOST ?= mssql:1433
  109. TEST_MSSQL_DBNAME ?= gitea
  110. TEST_MSSQL_USERNAME ?= sa
  111. TEST_MSSQL_PASSWORD ?= MwantsaSecurePassword1
  112. .PHONY: all
  113. all: build
  114. include docker/Makefile
  115. .PHONY: help
  116. help:
  117. @echo "Make Routines:"
  118. @echo " - \"\" equivalent to \"build\""
  119. @echo " - build build everything"
  120. @echo " - frontend build frontend files"
  121. @echo " - backend build backend files"
  122. @echo " - clean delete backend and integration files"
  123. @echo " - clean-all delete backend, frontend and integration files"
  124. @echo " - lint lint everything"
  125. @echo " - lint-frontend lint frontend files"
  126. @echo " - lint-backend lint backend files"
  127. @echo " - watch-frontend watch frontend files and continuously rebuild"
  128. @echo " - webpack build webpack files"
  129. @echo " - fomantic build fomantic files"
  130. @echo " - generate run \"go generate\""
  131. @echo " - fmt format the Go code"
  132. @echo " - generate-swagger generate the swagger spec from code comments"
  133. @echo " - swagger-validate check if the swagger spec is valid"
  134. @echo " - golangci-lint run golangci-lint linter"
  135. @echo " - revive run revive linter"
  136. @echo " - misspell check for misspellings"
  137. @echo " - vet examines Go source code and reports suspicious constructs"
  138. @echo " - test[\#TestSpecificName] run unit test"
  139. @echo " - test-sqlite[\#TestSpecificName] run integration test for sqlite"
  140. @echo " - pr#<index> build and start gitea from a PR with integration test data loaded"
  141. .PHONY: go-check
  142. go-check:
  143. $(eval GO_VERSION := $(shell printf "%03d%03d%03d" $(shell go version | grep -Eo '[0-9]+\.[0-9.]+' | tr '.' ' ');))
  144. @if [ "$(GO_VERSION)" -lt "$(MIN_GO_VERSION)" ]; then \
  145. echo "Gitea requires Go 1.12 or greater to build. You can get it at https://golang.org/dl/"; \
  146. exit 1; \
  147. fi
  148. .PHONY: git-check
  149. git-check:
  150. @if git lfs >/dev/null 2>&1 ; then : ; else \
  151. echo "Gitea requires git with lfs support to run tests." ; \
  152. exit 1; \
  153. fi
  154. .PHONY: node-check
  155. node-check:
  156. $(eval NODE_VERSION := $(shell printf "%03d%03d%03d" $(shell node -v | cut -c2- | tr '.' ' ');))
  157. $(eval NPM_MISSING := $(shell hash npm > /dev/null 2>&1 || echo 1))
  158. @if [ "$(NODE_VERSION)" -lt "$(MIN_NODE_VERSION)" -o "$(NPM_MISSING)" = "1" ]; then \
  159. echo "Gitea requires Node.js 10 or greater and npm to build. You can get it at https://nodejs.org/en/download/"; \
  160. exit 1; \
  161. fi
  162. .PHONY: clean-all
  163. clean-all: clean
  164. rm -rf $(WEBPACK_DEST_ENTRIES) $(FOMANTIC_DEST_DIR)
  165. .PHONY: clean
  166. clean:
  167. $(GO) clean -i ./...
  168. rm -rf $(EXECUTABLE) $(DIST) $(BINDATA_DEST) $(BINDATA_HASH) \
  169. integrations*.test \
  170. integrations/gitea-integration-pgsql/ integrations/gitea-integration-mysql/ integrations/gitea-integration-mysql8/ integrations/gitea-integration-sqlite/ \
  171. integrations/gitea-integration-mssql/ integrations/indexers-mysql/ integrations/indexers-mysql8/ integrations/indexers-pgsql integrations/indexers-sqlite \
  172. integrations/indexers-mssql integrations/mysql.ini integrations/mysql8.ini integrations/pgsql.ini integrations/mssql.ini
  173. .PHONY: fmt
  174. fmt:
  175. $(GOFMT) -w $(GO_SOURCES_OWN)
  176. .PHONY: vet
  177. vet:
  178. # Default vet
  179. $(GO) vet $(GO_PACKAGES)
  180. # Custom vet
  181. $(GO) build -mod=vendor gitea.com/jolheiser/gitea-vet
  182. $(GO) vet -vettool=gitea-vet $(GO_PACKAGES)
  183. .PHONY: $(TAGS_EVIDENCE)
  184. $(TAGS_EVIDENCE):
  185. @mkdir -p $(MAKE_EVIDENCE_DIR)
  186. @echo "$(TAGS)" > $(TAGS_EVIDENCE)
  187. ifneq "$(TAGS)" "$(shell cat $(TAGS_EVIDENCE) 2>/dev/null)"
  188. TAGS_PREREQ := $(TAGS_EVIDENCE)
  189. endif
  190. .PHONY: generate-swagger
  191. generate-swagger:
  192. $(SWAGGER) generate spec -o './$(SWAGGER_SPEC)'
  193. $(SED_INPLACE) '$(SWAGGER_SPEC_S_TMPL)' './$(SWAGGER_SPEC)'
  194. $(SED_INPLACE) $(SWAGGER_NEWLINE_COMMAND) './$(SWAGGER_SPEC)'
  195. .PHONY: swagger-check
  196. swagger-check: generate-swagger
  197. @diff=$$(git diff '$(SWAGGER_SPEC)'); \
  198. if [ -n "$$diff" ]; then \
  199. echo "Please run 'make generate-swagger' and commit the result:"; \
  200. echo "$${diff}"; \
  201. exit 1; \
  202. fi;
  203. .PHONY: swagger-validate
  204. swagger-validate:
  205. $(SED_INPLACE) '$(SWAGGER_SPEC_S_JSON)' './$(SWAGGER_SPEC)'
  206. $(SWAGGER) validate './$(SWAGGER_SPEC)'
  207. $(SED_INPLACE) '$(SWAGGER_SPEC_S_TMPL)' './$(SWAGGER_SPEC)'
  208. .PHONY: errcheck
  209. errcheck:
  210. @hash errcheck > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  211. GO111MODULE=off $(GO) get -u github.com/kisielk/errcheck; \
  212. fi
  213. errcheck $(GO_PACKAGES)
  214. .PHONY: revive
  215. revive:
  216. GO111MODULE=on $(GO) run -mod=vendor build/lint.go -config .revive.toml -exclude=./vendor/... ./... || exit 1
  217. .PHONY: misspell-check
  218. misspell-check:
  219. @hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  220. GO111MODULE=off $(GO) get -u github.com/client9/misspell/cmd/misspell; \
  221. fi
  222. misspell -error -i unknwon,destory $(GO_SOURCES_OWN)
  223. .PHONY: misspell
  224. misspell:
  225. @hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  226. GO111MODULE=off $(GO) get -u github.com/client9/misspell/cmd/misspell; \
  227. fi
  228. misspell -w -i unknwon $(GO_SOURCES_OWN)
  229. .PHONY: fmt-check
  230. fmt-check:
  231. # get all go files and run go fmt on them
  232. @diff=$$($(GOFMT) -d $(GO_SOURCES_OWN)); \
  233. if [ -n "$$diff" ]; then \
  234. echo "Please run 'make fmt' and commit the result:"; \
  235. echo "$${diff}"; \
  236. exit 1; \
  237. fi;
  238. .PHONY: lint
  239. lint: lint-backend lint-frontend
  240. .PHONY: lint-backend
  241. lint-backend: golangci-lint revive vet swagger-check swagger-validate test-vendor
  242. .PHONY: lint-frontend
  243. lint-frontend: node_modules
  244. npx eslint web_src/js webpack.config.js
  245. npx stylelint web_src/less
  246. .PHONY: watch-frontend
  247. watch-frontend: node_modules
  248. rm -rf $(WEBPACK_DEST_ENTRIES)
  249. NODE_ENV=development npx webpack --hide-modules --display-entrypoints=false --watch --progress
  250. .PHONY: test
  251. test:
  252. $(GO) test $(GOTESTFLAGS) -mod=vendor -tags='sqlite sqlite_unlock_notify' $(GO_PACKAGES)
  253. .PHONY: test-check
  254. test-check:
  255. @echo "Checking if tests have changed the source tree...";
  256. @diff=$$(git status -s); \
  257. if [ -n "$$diff" ]; then \
  258. echo "make test has changed files in the source tree:"; \
  259. echo "$${diff}"; \
  260. echo "You should change the tests to create these files in a temporary directory."; \
  261. echo "Do not simply add these files to .gitignore"; \
  262. exit 1; \
  263. fi;
  264. .PHONY: test\#%
  265. test\#%:
  266. $(GO) test -mod=vendor -tags='sqlite sqlite_unlock_notify' -run $(subst .,/,$*) $(GO_PACKAGES)
  267. .PHONY: coverage
  268. coverage:
  269. GO111MODULE=on $(GO) run -mod=vendor build/gocovmerge.go integration.coverage.out $(shell find . -type f -name "coverage.out") > coverage.all
  270. .PHONY: unit-test-coverage
  271. unit-test-coverage:
  272. $(GO) test $(GOTESTFLAGS) -mod=vendor -tags='sqlite sqlite_unlock_notify' -cover -coverprofile coverage.out $(GO_PACKAGES) && echo "\n==>\033[32m Ok\033[m\n" || exit 1
  273. .PHONY: vendor
  274. vendor:
  275. $(GO) mod tidy && $(GO) mod vendor
  276. .PHONY: test-vendor
  277. test-vendor: vendor
  278. @diff=$$(git diff vendor/); \
  279. if [ -n "$$diff" ]; then \
  280. echo "Please run 'make vendor' and commit the result:"; \
  281. echo "$${diff}"; \
  282. exit 1; \
  283. fi;
  284. generate-ini-sqlite:
  285. sed -e 's|{{REPO_TEST_DIR}}|${REPO_TEST_DIR}|g' \
  286. integrations/sqlite.ini.tmpl > integrations/sqlite.ini
  287. .PHONY: test-sqlite
  288. test-sqlite: integrations.sqlite.test generate-ini-sqlite
  289. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/sqlite.ini ./integrations.sqlite.test
  290. .PHONY: test-sqlite\#%
  291. test-sqlite\#%: integrations.sqlite.test generate-ini-sqlite
  292. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/sqlite.ini ./integrations.sqlite.test -test.run $(subst .,/,$*)
  293. .PHONY: test-sqlite-migration
  294. test-sqlite-migration: migrations.sqlite.test generate-ini-sqlite
  295. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/sqlite.ini ./migrations.sqlite.test
  296. generate-ini-mysql:
  297. sed -e 's|{{TEST_MYSQL_HOST}}|${TEST_MYSQL_HOST}|g' \
  298. -e 's|{{TEST_MYSQL_DBNAME}}|${TEST_MYSQL_DBNAME}|g' \
  299. -e 's|{{TEST_MYSQL_USERNAME}}|${TEST_MYSQL_USERNAME}|g' \
  300. -e 's|{{TEST_MYSQL_PASSWORD}}|${TEST_MYSQL_PASSWORD}|g' \
  301. -e 's|{{REPO_TEST_DIR}}|${REPO_TEST_DIR}|g' \
  302. integrations/mysql.ini.tmpl > integrations/mysql.ini
  303. .PHONY: test-mysql
  304. test-mysql: integrations.mysql.test generate-ini-mysql
  305. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql.ini ./integrations.mysql.test
  306. .PHONY: test-mysql\#%
  307. test-mysql\#%: integrations.mysql.test generate-ini-mysql
  308. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql.ini ./integrations.mysql.test -test.run $(subst .,/,$*)
  309. .PHONY: test-mysql-migration
  310. test-mysql-migration: migrations.mysql.test generate-ini-mysql
  311. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql.ini ./migrations.mysql.test
  312. generate-ini-mysql8:
  313. sed -e 's|{{TEST_MYSQL8_HOST}}|${TEST_MYSQL8_HOST}|g' \
  314. -e 's|{{TEST_MYSQL8_DBNAME}}|${TEST_MYSQL8_DBNAME}|g' \
  315. -e 's|{{TEST_MYSQL8_USERNAME}}|${TEST_MYSQL8_USERNAME}|g' \
  316. -e 's|{{TEST_MYSQL8_PASSWORD}}|${TEST_MYSQL8_PASSWORD}|g' \
  317. -e 's|{{REPO_TEST_DIR}}|${REPO_TEST_DIR}|g' \
  318. integrations/mysql8.ini.tmpl > integrations/mysql8.ini
  319. .PHONY: test-mysql8
  320. test-mysql8: integrations.mysql8.test generate-ini-mysql8
  321. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql8.ini ./integrations.mysql8.test
  322. .PHONY: test-mysql8\#%
  323. test-mysql8\#%: integrations.mysql8.test generate-ini-mysql8
  324. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql8.ini ./integrations.mysql8.test -test.run $(subst .,/,$*)
  325. .PHONY: test-mysql8-migration
  326. test-mysql8-migration: migrations.mysql8.test generate-ini-mysql8
  327. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql8.ini ./migrations.mysql8.test
  328. generate-ini-pgsql:
  329. sed -e 's|{{TEST_PGSQL_HOST}}|${TEST_PGSQL_HOST}|g' \
  330. -e 's|{{TEST_PGSQL_DBNAME}}|${TEST_PGSQL_DBNAME}|g' \
  331. -e 's|{{TEST_PGSQL_USERNAME}}|${TEST_PGSQL_USERNAME}|g' \
  332. -e 's|{{TEST_PGSQL_PASSWORD}}|${TEST_PGSQL_PASSWORD}|g' \
  333. -e 's|{{TEST_PGSQL_SCHEMA}}|${TEST_PGSQL_SCHEMA}|g' \
  334. -e 's|{{REPO_TEST_DIR}}|${REPO_TEST_DIR}|g' \
  335. integrations/pgsql.ini.tmpl > integrations/pgsql.ini
  336. .PHONY: test-pgsql
  337. test-pgsql: integrations.pgsql.test generate-ini-pgsql
  338. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/pgsql.ini ./integrations.pgsql.test
  339. .PHONY: test-pgsql\#%
  340. test-pgsql\#%: integrations.pgsql.test generate-ini-pgsql
  341. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/pgsql.ini ./integrations.pgsql.test -test.run $(subst .,/,$*)
  342. .PHONY: test-pgsql-migration
  343. test-pgsql-migration: migrations.pgsql.test generate-ini-pgsql
  344. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/pgsql.ini ./migrations.pgsql.test
  345. generate-ini-mssql:
  346. sed -e 's|{{TEST_MSSQL_HOST}}|${TEST_MSSQL_HOST}|g' \
  347. -e 's|{{TEST_MSSQL_DBNAME}}|${TEST_MSSQL_DBNAME}|g' \
  348. -e 's|{{TEST_MSSQL_USERNAME}}|${TEST_MSSQL_USERNAME}|g' \
  349. -e 's|{{TEST_MSSQL_PASSWORD}}|${TEST_MSSQL_PASSWORD}|g' \
  350. -e 's|{{REPO_TEST_DIR}}|${REPO_TEST_DIR}|g' \
  351. integrations/mssql.ini.tmpl > integrations/mssql.ini
  352. .PHONY: test-mssql
  353. test-mssql: integrations.mssql.test generate-ini-mssql
  354. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mssql.ini ./integrations.mssql.test
  355. .PHONY: test-mssql\#%
  356. test-mssql\#%: integrations.mssql.test generate-ini-mssql
  357. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mssql.ini ./integrations.mssql.test -test.run $(subst .,/,$*)
  358. .PHONY: test-mssql-migration
  359. test-mssql-migration: migrations.mssql.test generate-ini-mssql
  360. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mssql.ini ./migrations.mssql.test
  361. .PHONY: bench-sqlite
  362. bench-sqlite: integrations.sqlite.test generate-ini-sqlite
  363. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/sqlite.ini ./integrations.sqlite.test -test.cpuprofile=cpu.out -test.run DontRunTests -test.bench .
  364. .PHONY: bench-mysql
  365. bench-mysql: integrations.mysql.test generate-ini-mysql
  366. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql.ini ./integrations.mysql.test -test.cpuprofile=cpu.out -test.run DontRunTests -test.bench .
  367. .PHONY: bench-mssql
  368. bench-mssql: integrations.mssql.test generate-ini-mssql
  369. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mssql.ini ./integrations.mssql.test -test.cpuprofile=cpu.out -test.run DontRunTests -test.bench .
  370. .PHONY: bench-pgsql
  371. bench-pgsql: integrations.pgsql.test generate-ini-pgsql
  372. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/pgsql.ini ./integrations.pgsql.test -test.cpuprofile=cpu.out -test.run DontRunTests -test.bench .
  373. .PHONY: integration-test-coverage
  374. integration-test-coverage: integrations.cover.test generate-ini-mysql
  375. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql.ini ./integrations.cover.test -test.coverprofile=integration.coverage.out
  376. integrations.mysql.test: git-check $(GO_SOURCES)
  377. $(GO) test $(GOTESTFLAGS) -mod=vendor -c code.gitea.io/gitea/integrations -o integrations.mysql.test
  378. integrations.mysql8.test: git-check $(GO_SOURCES)
  379. $(GO) test $(GOTESTFLAGS) -mod=vendor -c code.gitea.io/gitea/integrations -o integrations.mysql8.test
  380. integrations.pgsql.test: git-check $(GO_SOURCES)
  381. $(GO) test $(GOTESTFLAGS) -mod=vendor -c code.gitea.io/gitea/integrations -o integrations.pgsql.test
  382. integrations.mssql.test: git-check $(GO_SOURCES)
  383. $(GO) test $(GOTESTFLAGS) -mod=vendor -c code.gitea.io/gitea/integrations -o integrations.mssql.test
  384. integrations.sqlite.test: git-check $(GO_SOURCES)
  385. $(GO) test $(GOTESTFLAGS) -mod=vendor -c code.gitea.io/gitea/integrations -o integrations.sqlite.test -tags 'sqlite sqlite_unlock_notify'
  386. integrations.cover.test: git-check $(GO_SOURCES)
  387. $(GO) test $(GOTESTFLAGS) -mod=vendor -c code.gitea.io/gitea/integrations -coverpkg $(shell echo $(GO_PACKAGES) | tr ' ' ',') -o integrations.cover.test
  388. .PHONY: migrations.mysql.test
  389. migrations.mysql.test: $(GO_SOURCES)
  390. $(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/integrations/migration-test -o migrations.mysql.test
  391. .PHONY: migrations.mysql8.test
  392. migrations.mysql8.test: $(GO_SOURCES)
  393. $(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/integrations/migration-test -o migrations.mysql8.test
  394. .PHONY: migrations.pgsql.test
  395. migrations.pgsql.test: $(GO_SOURCES)
  396. $(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/integrations/migration-test -o migrations.pgsql.test
  397. .PHONY: migrations.mssql.test
  398. migrations.mssql.test: $(GO_SOURCES)
  399. $(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/integrations/migration-test -o migrations.mssql.test
  400. .PHONY: migrations.sqlite.test
  401. migrations.sqlite.test: $(GO_SOURCES)
  402. $(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/integrations/migration-test -o migrations.sqlite.test -tags 'sqlite sqlite_unlock_notify'
  403. .PHONY: check
  404. check: test
  405. .PHONY: install $(TAGS_PREREQ)
  406. install: $(wildcard *.go)
  407. CGO_CFLAGS="$(CGO_CFLAGS)" $(GO) install -v -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)'
  408. .PHONY: build
  409. build: frontend backend
  410. .PHONY: frontend
  411. frontend: node-check $(FOMANTIC_DEST) $(WEBPACK_DEST)
  412. .PHONY: backend
  413. backend: go-check generate $(EXECUTABLE)
  414. .PHONY: generate
  415. generate: $(TAGS_PREREQ)
  416. CC= GOOS= GOARCH= $(GO) generate -mod=vendor -tags '$(TAGS)' $(GO_PACKAGES)
  417. $(EXECUTABLE): $(GO_SOURCES) $(TAGS_PREREQ)
  418. CGO_CFLAGS="$(CGO_CFLAGS)" $(GO) build -mod=vendor $(GOFLAGS) $(EXTRA_GOFLAGS) -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)' -o $@
  419. .PHONY: release
  420. release: frontend generate release-windows release-linux release-darwin release-copy release-compress release-sources release-check
  421. $(DIST_DIRS):
  422. mkdir -p $(DIST_DIRS)
  423. .PHONY: release-windows
  424. release-windows: | $(DIST_DIRS)
  425. @hash xgo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  426. GO111MODULE=off $(GO) get -u src.techknowlogick.com/xgo; \
  427. fi
  428. CGO_CFLAGS="$(CGO_CFLAGS)" GO111MODULE=off xgo -go $(XGO_VERSION) -buildmode exe -dest $(DIST)/binaries -tags 'netgo osusergo $(TAGS)' -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -targets 'windows/*' -out gitea-$(VERSION) .
  429. ifeq ($(CI),drone)
  430. cp /build/* $(DIST)/binaries
  431. endif
  432. .PHONY: release-linux
  433. release-linux: | $(DIST_DIRS)
  434. @hash xgo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  435. GO111MODULE=off $(GO) get -u src.techknowlogick.com/xgo; \
  436. fi
  437. CGO_CFLAGS="$(CGO_CFLAGS)" GO111MODULE=off xgo -go $(XGO_VERSION) -dest $(DIST)/binaries -tags 'netgo osusergo $(TAGS)' -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -targets 'linux/amd64,linux/386,linux/arm-5,linux/arm-6,linux/arm64,linux/mips64le,linux/mips,linux/mipsle' -out gitea-$(VERSION) .
  438. ifeq ($(CI),drone)
  439. cp /build/* $(DIST)/binaries
  440. endif
  441. .PHONY: release-darwin
  442. release-darwin: | $(DIST_DIRS)
  443. @hash xgo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  444. GO111MODULE=off $(GO) get -u src.techknowlogick.com/xgo; \
  445. fi
  446. CGO_CFLAGS="$(CGO_CFLAGS)" GO111MODULE=off xgo -go $(XGO_VERSION) -dest $(DIST)/binaries -tags 'netgo osusergo $(TAGS)' -ldflags '$(LDFLAGS)' -targets 'darwin/*' -out gitea-$(VERSION) .
  447. ifeq ($(CI),drone)
  448. cp /build/* $(DIST)/binaries
  449. endif
  450. .PHONY: release-copy
  451. release-copy: | $(DIST_DIRS)
  452. cd $(DIST); for file in `find /build -type f -name "*"`; do cp $${file} ./release/; done;
  453. .PHONY: release-check
  454. release-check: | $(DIST_DIRS)
  455. cd $(DIST)/release/; for file in `find . -type f -name "*"`; do echo "checksumming $${file}" && $(SHASUM) `echo $${file} | sed 's/^..//'` > $${file}.sha256; done;
  456. .PHONY: release-compress
  457. release-compress: | $(DIST_DIRS)
  458. @hash gxz > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  459. GO111MODULE=off $(GO) get -u github.com/ulikunitz/xz/cmd/gxz; \
  460. fi
  461. cd $(DIST)/release/; for file in `find . -type f -name "*"`; do echo "compressing $${file}" && gxz -k -9 $${file}; done;
  462. .PHONY: release-sources
  463. release-sources: | $(DIST_DIRS) node_modules
  464. echo $(VERSION) > $(STORED_VERSION_FILE)
  465. tar --exclude=./$(DIST) --exclude=./.git --exclude=./$(MAKE_EVIDENCE_DIR) --exclude=./node_modules/.cache -czf $(DIST)/release/gitea-src-$(VERSION).tar.gz .
  466. rm -f $(STORED_VERSION_FILE)
  467. node_modules: package-lock.json
  468. npm install --no-save
  469. @touch node_modules
  470. .PHONY: npm-update
  471. npm-update: node-check | node_modules
  472. npx updates -cu
  473. rm -rf node_modules package-lock.json
  474. npm install --package-lock
  475. .PHONY: fomantic
  476. fomantic: $(FOMANTIC_DEST)
  477. $(FOMANTIC_DEST): $(FOMANTIC_CONFIGS) package-lock.json | node_modules
  478. rm -rf $(FOMANTIC_DEST_DIR)
  479. cp web_src/fomantic/theme.config.less node_modules/fomantic-ui/src/theme.config
  480. cp -r web_src/fomantic/_site/* node_modules/fomantic-ui/src/_site/
  481. cp web_src/fomantic/css.js node_modules/fomantic-ui/tasks/build/css.js
  482. npx gulp -f node_modules/fomantic-ui/gulpfile.js build
  483. @touch $(FOMANTIC_DEST)
  484. .PHONY: webpack
  485. webpack: $(WEBPACK_DEST)
  486. $(WEBPACK_DEST): $(WEBPACK_SOURCES) $(WEBPACK_CONFIGS) package-lock.json | node_modules
  487. rm -rf $(WEBPACK_DEST_ENTRIES)
  488. npx webpack --hide-modules --display-entrypoints=false
  489. @touch $(WEBPACK_DEST)
  490. .PHONY: update-translations
  491. update-translations:
  492. mkdir -p ./translations
  493. cd ./translations && curl -L https://crowdin.com/download/project/gitea.zip > gitea.zip && unzip gitea.zip
  494. rm ./translations/gitea.zip
  495. $(SED_INPLACE) -e 's/="/=/g' -e 's/"$$//g' ./translations/*.ini
  496. $(SED_INPLACE) -e 's/\\"/"/g' ./translations/*.ini
  497. mv ./translations/*.ini ./options/locale/
  498. rmdir ./translations
  499. .PHONY: generate-images
  500. generate-images:
  501. $(eval TMPDIR := $(shell mktemp -d 2>/dev/null || mktemp -d -t 'gitea-temp'))
  502. mkdir -p $(TMPDIR)/images
  503. inkscape -f $(PWD)/assets/logo.svg -w 880 -h 880 -e $(PWD)/public/img/gitea-lg.png
  504. inkscape -f $(PWD)/assets/logo.svg -w 512 -h 512 -e $(PWD)/public/img/gitea-512.png
  505. inkscape -f $(PWD)/assets/logo.svg -w 192 -h 192 -e $(PWD)/public/img/gitea-192.png
  506. inkscape -f $(PWD)/assets/logo.svg -w 120 -h 120 -jC -i layer1 -e $(TMPDIR)/images/sm-1.png
  507. inkscape -f $(PWD)/assets/logo.svg -w 120 -h 120 -jC -i layer2 -e $(TMPDIR)/images/sm-2.png
  508. composite -compose atop $(TMPDIR)/images/sm-2.png $(TMPDIR)/images/sm-1.png $(PWD)/public/img/gitea-sm.png
  509. inkscape -f $(PWD)/assets/logo.svg -w 200 -h 200 -e $(PWD)/public/img/avatar_default.png
  510. inkscape -f $(PWD)/assets/logo.svg -w 180 -h 180 -e $(PWD)/public/img/favicon.png
  511. inkscape -f $(PWD)/assets/logo.svg -w 128 -h 128 -e $(TMPDIR)/images/128-raw.png
  512. inkscape -f $(PWD)/assets/logo.svg -w 64 -h 64 -e $(TMPDIR)/images/64-raw.png
  513. inkscape -f $(PWD)/assets/logo.svg -w 32 -h 32 -jC -i layer1 -e $(TMPDIR)/images/32-1.png
  514. inkscape -f $(PWD)/assets/logo.svg -w 32 -h 32 -jC -i layer2 -e $(TMPDIR)/images/32-2.png
  515. composite -compose atop $(TMPDIR)/images/32-2.png $(TMPDIR)/images/32-1.png $(TMPDIR)/images/32-raw.png
  516. inkscape -f $(PWD)/assets/logo.svg -w 16 -h 16 -jC -i layer1 -e $(TMPDIR)/images/16-raw.png
  517. zopflipng -m -y $(TMPDIR)/images/128-raw.png $(TMPDIR)/images/128.png
  518. zopflipng -m -y $(TMPDIR)/images/64-raw.png $(TMPDIR)/images/64.png
  519. zopflipng -m -y $(TMPDIR)/images/32-raw.png $(TMPDIR)/images/32.png
  520. zopflipng -m -y $(TMPDIR)/images/16-raw.png $(TMPDIR)/images/16.png
  521. rm -f $(TMPDIR)/images/*-*.png
  522. convert $(TMPDIR)/images/16.png $(TMPDIR)/images/32.png \
  523. $(TMPDIR)/images/64.png $(TMPDIR)/images/128.png \
  524. $(PWD)/public/img/favicon.ico
  525. convert -flatten $(PWD)/public/img/favicon.png $(PWD)/public/img/apple-touch-icon.png
  526. rm -rf $(TMPDIR)/images
  527. $(foreach file, $(shell find public/img -type f -name '*.png' ! -name 'loading.png'),zopflipng -m -y $(file) $(file);)
  528. .PHONY: pr\#%
  529. pr\#%: clean-all
  530. $(GO) run contrib/pr/checkout.go $*
  531. .PHONY: golangci-lint
  532. golangci-lint:
  533. @hash golangci-lint > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  534. export BINARY="golangci-lint"; \
  535. curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(GOPATH)/bin v1.24.0; \
  536. fi
  537. golangci-lint run --timeout 5m
  538. # This endif closes the if at the top of the file
  539. endif