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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773
  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. SHASUM ?= shasum -a 256
  18. HAS_GO = $(shell hash $(GO) > /dev/null 2>&1 && echo "GO" || echo "NOGO" )
  19. COMMA := ,
  20. XGO_VERSION := go-1.16.x
  21. MIN_GO_VERSION := 001014000
  22. MIN_NODE_VERSION := 012017000
  23. DOCKER_IMAGE ?= gitea/gitea
  24. DOCKER_TAG ?= latest
  25. DOCKER_REF := $(DOCKER_IMAGE):$(DOCKER_TAG)
  26. ifeq ($(HAS_GO), GO)
  27. GOPATH ?= $(shell $(GO) env GOPATH)
  28. export PATH := $(GOPATH)/bin:$(PATH)
  29. CGO_EXTRA_CFLAGS := -DSQLITE_MAX_VARIABLE_NUMBER=32766
  30. CGO_CFLAGS ?= $(shell $(GO) env CGO_CFLAGS) $(CGO_EXTRA_CFLAGS)
  31. endif
  32. ifeq ($(OS), Windows_NT)
  33. GOFLAGS := -v -buildmode=exe
  34. EXECUTABLE ?= gitea.exe
  35. else
  36. GOFLAGS := -v
  37. EXECUTABLE ?= gitea
  38. endif
  39. ifeq ($(shell sed --version 2>/dev/null | grep -q GNU && echo gnu),gnu)
  40. SED_INPLACE := sed -i
  41. else
  42. SED_INPLACE := sed -i ''
  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. LINUX_ARCHS ?= linux/amd64,linux/386,linux/arm-5,linux/arm-6,linux/arm64
  70. GO_PACKAGES ?= $(filter-out code.gitea.io/gitea/models/migrations code.gitea.io/gitea/integrations/migration-test code.gitea.io/gitea/integrations,$(shell $(GO) list -mod=vendor ./... | grep -v /vendor/))
  71. FOMANTIC_WORK_DIR := web_src/fomantic
  72. WEBPACK_SOURCES := $(shell find web_src/js web_src/less -type f)
  73. WEBPACK_CONFIGS := webpack.config.js
  74. WEBPACK_DEST := public/js/index.js public/css/index.css
  75. WEBPACK_DEST_ENTRIES := public/js public/css public/fonts public/img/webpack public/serviceworker.js
  76. BINDATA_DEST := modules/public/bindata.go modules/options/bindata.go modules/templates/bindata.go
  77. BINDATA_HASH := $(addsuffix .hash,$(BINDATA_DEST))
  78. SVG_DEST_DIR := public/img/svg
  79. AIR_TMP_DIR := .air
  80. TAGS ?=
  81. TAGS_SPLIT := $(subst $(COMMA), ,$(TAGS))
  82. TAGS_EVIDENCE := $(MAKE_EVIDENCE_DIR)/tags
  83. TEST_TAGS ?= sqlite sqlite_unlock_notify
  84. TAR_EXCLUDES := .git data indexers queues log node_modules $(EXECUTABLE) $(FOMANTIC_WORK_DIR)/node_modules $(DIST) $(MAKE_EVIDENCE_DIR) $(AIR_TMP_DIR)
  85. GO_DIRS := cmd integrations models modules routers build services vendor tools
  86. GO_SOURCES := $(wildcard *.go)
  87. 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)
  88. ifeq ($(filter $(TAGS_SPLIT),bindata),bindata)
  89. GO_SOURCES += $(BINDATA_DEST)
  90. endif
  91. GO_SOURCES_OWN := $(filter-out vendor/% %/bindata.go, $(GO_SOURCES))
  92. #To update swagger use: GO111MODULE=on go get -u github.com/go-swagger/go-swagger/cmd/swagger
  93. SWAGGER := $(GO) run -mod=vendor github.com/go-swagger/go-swagger/cmd/swagger
  94. SWAGGER_SPEC := templates/swagger/v1_json.tmpl
  95. SWAGGER_SPEC_S_TMPL := s|"basePath": *"/api/v1"|"basePath": "{{AppSubUrl \| JSEscape \| Safe}}/api/v1"|g
  96. SWAGGER_SPEC_S_JSON := s|"basePath": *"{{AppSubUrl \| JSEscape \| Safe}}/api/v1"|"basePath": "/api/v1"|g
  97. SWAGGER_EXCLUDE := code.gitea.io/sdk
  98. SWAGGER_NEWLINE_COMMAND := -e '$$a\'
  99. TEST_MYSQL_HOST ?= mysql:3306
  100. TEST_MYSQL_DBNAME ?= testgitea
  101. TEST_MYSQL_USERNAME ?= root
  102. TEST_MYSQL_PASSWORD ?=
  103. TEST_MYSQL8_HOST ?= mysql8:3306
  104. TEST_MYSQL8_DBNAME ?= testgitea
  105. TEST_MYSQL8_USERNAME ?= root
  106. TEST_MYSQL8_PASSWORD ?=
  107. TEST_PGSQL_HOST ?= pgsql:5432
  108. TEST_PGSQL_DBNAME ?= testgitea
  109. TEST_PGSQL_USERNAME ?= postgres
  110. TEST_PGSQL_PASSWORD ?= postgres
  111. TEST_PGSQL_SCHEMA ?= gtestschema
  112. TEST_MSSQL_HOST ?= mssql:1433
  113. TEST_MSSQL_DBNAME ?= gitea
  114. TEST_MSSQL_USERNAME ?= sa
  115. TEST_MSSQL_PASSWORD ?= MwantsaSecurePassword1
  116. .PHONY: all
  117. all: build
  118. .PHONY: help
  119. help:
  120. @echo "Make Routines:"
  121. @echo " - \"\" equivalent to \"build\""
  122. @echo " - build build everything"
  123. @echo " - frontend build frontend files"
  124. @echo " - backend build backend files"
  125. @echo " - watch watch everything and continuously rebuild"
  126. @echo " - watch-frontend watch frontend files and continuously rebuild"
  127. @echo " - watch-backend watch backend files and continuously rebuild"
  128. @echo " - clean delete backend and integration files"
  129. @echo " - clean-all delete backend, frontend and integration files"
  130. @echo " - lint lint everything"
  131. @echo " - lint-frontend lint frontend files"
  132. @echo " - lint-backend lint backend files"
  133. @echo " - checks run various consistency checks"
  134. @echo " - checks-frontend check frontend files"
  135. @echo " - checks-backend check backend files"
  136. @echo " - test test everything"
  137. @echo " - test-frontend test frontend files"
  138. @echo " - test-backend test backend files"
  139. @echo " - webpack build webpack files"
  140. @echo " - svg build svg files"
  141. @echo " - fomantic build fomantic files"
  142. @echo " - generate run \"go generate\""
  143. @echo " - fmt format the Go code"
  144. @echo " - generate-license update license files"
  145. @echo " - generate-gitignore update gitignore files"
  146. @echo " - generate-manpage generate manpage"
  147. @echo " - generate-swagger generate the swagger spec from code comments"
  148. @echo " - swagger-validate check if the swagger spec is valid"
  149. @echo " - golangci-lint run golangci-lint linter"
  150. @echo " - revive run revive linter"
  151. @echo " - misspell check for misspellings"
  152. @echo " - vet examines Go source code and reports suspicious constructs"
  153. @echo " - test[\#TestSpecificName] run unit test"
  154. @echo " - test-sqlite[\#TestSpecificName] run integration test for sqlite"
  155. @echo " - pr#<index> build and start gitea from a PR with integration test data loaded"
  156. .PHONY: go-check
  157. go-check:
  158. $(eval GO_VERSION := $(shell printf "%03d%03d%03d" $(shell $(GO) version | grep -Eo '[0-9]+\.[0-9.]+' | tr '.' ' ');))
  159. @if [ "$(GO_VERSION)" -lt "$(MIN_GO_VERSION)" ]; then \
  160. echo "Gitea requires Go 1.14 or greater to build. You can get it at https://golang.org/dl/"; \
  161. exit 1; \
  162. fi
  163. .PHONY: git-check
  164. git-check:
  165. @if git lfs >/dev/null 2>&1 ; then : ; else \
  166. echo "Gitea requires git with lfs support to run tests." ; \
  167. exit 1; \
  168. fi
  169. .PHONY: node-check
  170. node-check:
  171. $(eval NODE_VERSION := $(shell printf "%03d%03d%03d" $(shell node -v | cut -c2- | tr '.' ' ');))
  172. $(eval NPM_MISSING := $(shell hash npm > /dev/null 2>&1 || echo 1))
  173. @if [ "$(NODE_VERSION)" -lt "$(MIN_NODE_VERSION)" -o "$(NPM_MISSING)" = "1" ]; then \
  174. echo "Gitea requires Node.js 10 or greater and npm to build. You can get it at https://nodejs.org/en/download/"; \
  175. exit 1; \
  176. fi
  177. .PHONY: clean-all
  178. clean-all: clean
  179. rm -rf $(WEBPACK_DEST_ENTRIES)
  180. .PHONY: clean
  181. clean:
  182. $(GO) clean -i ./...
  183. rm -rf $(EXECUTABLE) $(DIST) $(BINDATA_DEST) $(BINDATA_HASH) \
  184. integrations*.test \
  185. integrations/gitea-integration-pgsql/ integrations/gitea-integration-mysql/ integrations/gitea-integration-mysql8/ integrations/gitea-integration-sqlite/ \
  186. integrations/gitea-integration-mssql/ integrations/indexers-mysql/ integrations/indexers-mysql8/ integrations/indexers-pgsql integrations/indexers-sqlite \
  187. integrations/indexers-mssql integrations/mysql.ini integrations/mysql8.ini integrations/pgsql.ini integrations/mssql.ini man/
  188. .PHONY: fmt
  189. fmt:
  190. @echo "Running go fmt..."
  191. @$(GOFMT) -w $(GO_SOURCES_OWN)
  192. .PHONY: vet
  193. vet:
  194. @echo "Running go vet..."
  195. @$(GO) vet $(GO_PACKAGES)
  196. @GOOS= GOARCH= $(GO) build -mod=vendor code.gitea.io/gitea-vet
  197. @$(GO) vet -vettool=gitea-vet $(GO_PACKAGES)
  198. .PHONY: $(TAGS_EVIDENCE)
  199. $(TAGS_EVIDENCE):
  200. @mkdir -p $(MAKE_EVIDENCE_DIR)
  201. @echo "$(TAGS)" > $(TAGS_EVIDENCE)
  202. ifneq "$(TAGS)" "$(shell cat $(TAGS_EVIDENCE) 2>/dev/null)"
  203. TAGS_PREREQ := $(TAGS_EVIDENCE)
  204. endif
  205. .PHONY: generate-swagger
  206. generate-swagger:
  207. $(SWAGGER) generate spec -x "$(SWAGGER_EXCLUDE)" -o './$(SWAGGER_SPEC)'
  208. $(SED_INPLACE) '$(SWAGGER_SPEC_S_TMPL)' './$(SWAGGER_SPEC)'
  209. $(SED_INPLACE) $(SWAGGER_NEWLINE_COMMAND) './$(SWAGGER_SPEC)'
  210. .PHONY: swagger-check
  211. swagger-check: generate-swagger
  212. @diff=$$(git diff '$(SWAGGER_SPEC)'); \
  213. if [ -n "$$diff" ]; then \
  214. echo "Please run 'make generate-swagger' and commit the result:"; \
  215. echo "$${diff}"; \
  216. exit 1; \
  217. fi
  218. .PHONY: swagger-validate
  219. swagger-validate:
  220. $(SED_INPLACE) '$(SWAGGER_SPEC_S_JSON)' './$(SWAGGER_SPEC)'
  221. $(SWAGGER) validate './$(SWAGGER_SPEC)'
  222. $(SED_INPLACE) '$(SWAGGER_SPEC_S_TMPL)' './$(SWAGGER_SPEC)'
  223. .PHONY: errcheck
  224. errcheck:
  225. @hash errcheck > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  226. GO111MODULE=off $(GO) get -u github.com/kisielk/errcheck; \
  227. fi
  228. @echo "Running errcheck..."
  229. @errcheck $(GO_PACKAGES)
  230. .PHONY: revive
  231. revive:
  232. GO111MODULE=on $(GO) run -mod=vendor build/lint.go -config .revive.toml -exclude=./vendor/... ./... || exit 1
  233. .PHONY: misspell-check
  234. misspell-check:
  235. @hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  236. GO111MODULE=off $(GO) get -u github.com/client9/misspell/cmd/misspell; \
  237. fi
  238. @echo "Running misspell-check..."
  239. @misspell -error -i unknwon,destory $(GO_SOURCES_OWN)
  240. .PHONY: misspell
  241. misspell:
  242. @hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  243. GO111MODULE=off $(GO) get -u github.com/client9/misspell/cmd/misspell; \
  244. fi
  245. @echo "Running go misspell..."
  246. @misspell -w -i unknwon $(GO_SOURCES_OWN)
  247. .PHONY: fmt-check
  248. fmt-check:
  249. # get all go files and run go fmt on them
  250. @diff=$$($(GOFMT) -d $(GO_SOURCES_OWN)); \
  251. if [ -n "$$diff" ]; then \
  252. echo "Please run 'make fmt' and commit the result:"; \
  253. echo "$${diff}"; \
  254. exit 1; \
  255. fi
  256. .PHONY: checks
  257. checks: checks-frontend checks-backend
  258. .PHONY: checks-frontend
  259. checks-frontend: svg-check
  260. .PHONY: checks-backend
  261. checks-backend: misspell-check test-vendor swagger-check swagger-validate
  262. .PHONY: lint
  263. lint: lint-frontend lint-backend
  264. .PHONY: lint-frontend
  265. lint-frontend: node_modules
  266. npx eslint --color --max-warnings=0 web_src/js build templates *.config.js
  267. npx stylelint --color --max-warnings=0 web_src/less
  268. npx editorconfig-checker templates
  269. .PHONY: lint-backend
  270. lint-backend: golangci-lint revive vet
  271. .PHONY: watch
  272. watch:
  273. bash tools/watch.sh
  274. .PHONY: watch-frontend
  275. watch-frontend: node-check node_modules
  276. rm -rf $(WEBPACK_DEST_ENTRIES)
  277. NODE_ENV=development npx webpack --watch --progress
  278. .PHONY: watch-backend
  279. watch-backend: go-check
  280. @hash air > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  281. GO111MODULE=off $(GO) get -u github.com/cosmtrek/air; \
  282. fi
  283. air -c .air.conf
  284. .PHONY: test
  285. test: test-frontend test-backend
  286. .PHONY: test-backend
  287. test-backend:
  288. @echo "Running go test with -tags '$(TEST_TAGS)'..."
  289. @$(GO) test $(GOTESTFLAGS) -mod=vendor -tags='$(TEST_TAGS)' $(GO_PACKAGES)
  290. .PHONY: test-frontend
  291. test-frontend:
  292. @NODE_OPTIONS="--experimental-vm-modules --no-warnings" npx jest --color
  293. .PHONY: test-check
  294. test-check:
  295. @echo "Running test-check...";
  296. @diff=$$(git status -s); \
  297. if [ -n "$$diff" ]; then \
  298. echo "make test-backend has changed files in the source tree:"; \
  299. echo "$${diff}"; \
  300. echo "You should change the tests to create these files in a temporary directory."; \
  301. echo "Do not simply add these files to .gitignore"; \
  302. exit 1; \
  303. fi
  304. .PHONY: test\#%
  305. test\#%:
  306. @echo "Running go test with -tags '$(TEST_TAGS)'..."
  307. @$(GO) test -mod=vendor -tags='$(TEST_TAGS)' -run $(subst .,/,$*) $(GO_PACKAGES)
  308. .PHONY: coverage
  309. coverage:
  310. GO111MODULE=on $(GO) run -mod=vendor build/gocovmerge.go integration.coverage.out $(shell find . -type f -name "coverage.out") > coverage.all
  311. .PHONY: unit-test-coverage
  312. unit-test-coverage:
  313. @echo "Running unit-test-coverage -tags '$(TEST_TAGS)'..."
  314. @$(GO) test $(GOTESTFLAGS) -mod=vendor -tags='$(TEST_TAGS)' -cover -coverprofile coverage.out $(GO_PACKAGES) && echo "\n==>\033[32m Ok\033[m\n" || exit 1
  315. .PHONY: vendor
  316. vendor:
  317. $(GO) mod tidy && $(GO) mod vendor
  318. .PHONY: test-vendor
  319. test-vendor: vendor
  320. @diff=$$(git diff vendor/); \
  321. if [ -n "$$diff" ]; then \
  322. echo "Please run 'make vendor' and commit the result:"; \
  323. echo "$${diff}"; \
  324. exit 1; \
  325. fi
  326. generate-ini-sqlite:
  327. sed -e 's|{{REPO_TEST_DIR}}|${REPO_TEST_DIR}|g' \
  328. integrations/sqlite.ini.tmpl > integrations/sqlite.ini
  329. .PHONY: test-sqlite
  330. test-sqlite: integrations.sqlite.test generate-ini-sqlite
  331. GITEA_ROOT="$(CURDIR)" GITEA_CONF=integrations/sqlite.ini ./integrations.sqlite.test
  332. .PHONY: test-sqlite\#%
  333. test-sqlite\#%: integrations.sqlite.test generate-ini-sqlite
  334. GITEA_ROOT="$(CURDIR)" GITEA_CONF=integrations/sqlite.ini ./integrations.sqlite.test -test.run $(subst .,/,$*)
  335. .PHONY: test-sqlite-migration
  336. test-sqlite-migration: migrations.sqlite.test migrations.individual.sqlite.test generate-ini-sqlite
  337. GITEA_ROOT="$(CURDIR)" GITEA_CONF=integrations/sqlite.ini ./migrations.sqlite.test
  338. GITEA_ROOT="$(CURDIR)" GITEA_CONF=integrations/sqlite.ini ./migrations.individual.sqlite.test
  339. generate-ini-mysql:
  340. sed -e 's|{{TEST_MYSQL_HOST}}|${TEST_MYSQL_HOST}|g' \
  341. -e 's|{{TEST_MYSQL_DBNAME}}|${TEST_MYSQL_DBNAME}|g' \
  342. -e 's|{{TEST_MYSQL_USERNAME}}|${TEST_MYSQL_USERNAME}|g' \
  343. -e 's|{{TEST_MYSQL_PASSWORD}}|${TEST_MYSQL_PASSWORD}|g' \
  344. -e 's|{{REPO_TEST_DIR}}|${REPO_TEST_DIR}|g' \
  345. integrations/mysql.ini.tmpl > integrations/mysql.ini
  346. .PHONY: test-mysql
  347. test-mysql: integrations.mysql.test generate-ini-mysql
  348. GITEA_ROOT="$(CURDIR)" GITEA_CONF=integrations/mysql.ini ./integrations.mysql.test
  349. .PHONY: test-mysql\#%
  350. test-mysql\#%: integrations.mysql.test generate-ini-mysql
  351. GITEA_ROOT="$(CURDIR)" GITEA_CONF=integrations/mysql.ini ./integrations.mysql.test -test.run $(subst .,/,$*)
  352. .PHONY: test-mysql-migration
  353. test-mysql-migration: migrations.mysql.test migrations.individual.mysql.test generate-ini-mysql
  354. GITEA_ROOT="$(CURDIR)" GITEA_CONF=integrations/mysql.ini ./migrations.mysql.test
  355. GITEA_ROOT="$(CURDIR)" GITEA_CONF=integrations/mysql.ini ./migrations.individual.mysql.test
  356. generate-ini-mysql8:
  357. sed -e 's|{{TEST_MYSQL8_HOST}}|${TEST_MYSQL8_HOST}|g' \
  358. -e 's|{{TEST_MYSQL8_DBNAME}}|${TEST_MYSQL8_DBNAME}|g' \
  359. -e 's|{{TEST_MYSQL8_USERNAME}}|${TEST_MYSQL8_USERNAME}|g' \
  360. -e 's|{{TEST_MYSQL8_PASSWORD}}|${TEST_MYSQL8_PASSWORD}|g' \
  361. -e 's|{{REPO_TEST_DIR}}|${REPO_TEST_DIR}|g' \
  362. integrations/mysql8.ini.tmpl > integrations/mysql8.ini
  363. .PHONY: test-mysql8
  364. test-mysql8: integrations.mysql8.test generate-ini-mysql8
  365. GITEA_ROOT="$(CURDIR)" GITEA_CONF=integrations/mysql8.ini ./integrations.mysql8.test
  366. .PHONY: test-mysql8\#%
  367. test-mysql8\#%: integrations.mysql8.test generate-ini-mysql8
  368. GITEA_ROOT="$(CURDIR)" GITEA_CONF=integrations/mysql8.ini ./integrations.mysql8.test -test.run $(subst .,/,$*)
  369. .PHONY: test-mysql8-migration
  370. test-mysql8-migration: migrations.mysql8.test migrations.individual.mysql8.test generate-ini-mysql8
  371. GITEA_ROOT="$(CURDIR)" GITEA_CONF=integrations/mysql8.ini ./migrations.mysql8.test
  372. GITEA_ROOT="$(CURDIR)" GITEA_CONF=integrations/mysql8.ini ./migrations.individual.mysql8.test
  373. generate-ini-pgsql:
  374. sed -e 's|{{TEST_PGSQL_HOST}}|${TEST_PGSQL_HOST}|g' \
  375. -e 's|{{TEST_PGSQL_DBNAME}}|${TEST_PGSQL_DBNAME}|g' \
  376. -e 's|{{TEST_PGSQL_USERNAME}}|${TEST_PGSQL_USERNAME}|g' \
  377. -e 's|{{TEST_PGSQL_PASSWORD}}|${TEST_PGSQL_PASSWORD}|g' \
  378. -e 's|{{TEST_PGSQL_SCHEMA}}|${TEST_PGSQL_SCHEMA}|g' \
  379. -e 's|{{REPO_TEST_DIR}}|${REPO_TEST_DIR}|g' \
  380. integrations/pgsql.ini.tmpl > integrations/pgsql.ini
  381. .PHONY: test-pgsql
  382. test-pgsql: integrations.pgsql.test generate-ini-pgsql
  383. GITEA_ROOT="$(CURDIR)" GITEA_CONF=integrations/pgsql.ini ./integrations.pgsql.test
  384. .PHONY: test-pgsql\#%
  385. test-pgsql\#%: integrations.pgsql.test generate-ini-pgsql
  386. GITEA_ROOT="$(CURDIR)" GITEA_CONF=integrations/pgsql.ini ./integrations.pgsql.test -test.run $(subst .,/,$*)
  387. .PHONY: test-pgsql-migration
  388. test-pgsql-migration: migrations.pgsql.test migrations.individual.pgsql.test generate-ini-pgsql
  389. GITEA_ROOT="$(CURDIR)" GITEA_CONF=integrations/pgsql.ini ./migrations.pgsql.test
  390. GITEA_ROOT="$(CURDIR)" GITEA_CONF=integrations/pgsql.ini ./migrations.individual.pgsql.test
  391. generate-ini-mssql:
  392. sed -e 's|{{TEST_MSSQL_HOST}}|${TEST_MSSQL_HOST}|g' \
  393. -e 's|{{TEST_MSSQL_DBNAME}}|${TEST_MSSQL_DBNAME}|g' \
  394. -e 's|{{TEST_MSSQL_USERNAME}}|${TEST_MSSQL_USERNAME}|g' \
  395. -e 's|{{TEST_MSSQL_PASSWORD}}|${TEST_MSSQL_PASSWORD}|g' \
  396. -e 's|{{REPO_TEST_DIR}}|${REPO_TEST_DIR}|g' \
  397. integrations/mssql.ini.tmpl > integrations/mssql.ini
  398. .PHONY: test-mssql
  399. test-mssql: integrations.mssql.test generate-ini-mssql
  400. GITEA_ROOT="$(CURDIR)" GITEA_CONF=integrations/mssql.ini ./integrations.mssql.test
  401. .PHONY: test-mssql\#%
  402. test-mssql\#%: integrations.mssql.test generate-ini-mssql
  403. GITEA_ROOT="$(CURDIR)" GITEA_CONF=integrations/mssql.ini ./integrations.mssql.test -test.run $(subst .,/,$*)
  404. .PHONY: test-mssql-migration
  405. test-mssql-migration: migrations.mssql.test migrations.individual.mssql.test generate-ini-mssql
  406. GITEA_ROOT="$(CURDIR)" GITEA_CONF=integrations/mssql.ini ./migrations.mssql.test -test.failfast
  407. GITEA_ROOT="$(CURDIR)" GITEA_CONF=integrations/mssql.ini ./migrations.individual.mssql.test -test.failfast
  408. .PHONY: bench-sqlite
  409. bench-sqlite: integrations.sqlite.test generate-ini-sqlite
  410. GITEA_ROOT="$(CURDIR)" GITEA_CONF=integrations/sqlite.ini ./integrations.sqlite.test -test.cpuprofile=cpu.out -test.run DontRunTests -test.bench .
  411. .PHONY: bench-mysql
  412. bench-mysql: integrations.mysql.test generate-ini-mysql
  413. GITEA_ROOT="$(CURDIR)" GITEA_CONF=integrations/mysql.ini ./integrations.mysql.test -test.cpuprofile=cpu.out -test.run DontRunTests -test.bench .
  414. .PHONY: bench-mssql
  415. bench-mssql: integrations.mssql.test generate-ini-mssql
  416. GITEA_ROOT="$(CURDIR)" GITEA_CONF=integrations/mssql.ini ./integrations.mssql.test -test.cpuprofile=cpu.out -test.run DontRunTests -test.bench .
  417. .PHONY: bench-pgsql
  418. bench-pgsql: integrations.pgsql.test generate-ini-pgsql
  419. GITEA_ROOT="$(CURDIR)" GITEA_CONF=integrations/pgsql.ini ./integrations.pgsql.test -test.cpuprofile=cpu.out -test.run DontRunTests -test.bench .
  420. .PHONY: integration-test-coverage
  421. integration-test-coverage: integrations.cover.test generate-ini-mysql
  422. GITEA_ROOT="$(CURDIR)" GITEA_CONF=integrations/mysql.ini ./integrations.cover.test -test.coverprofile=integration.coverage.out
  423. integrations.mysql.test: git-check $(GO_SOURCES)
  424. $(GO) test $(GOTESTFLAGS) -mod=vendor -c code.gitea.io/gitea/integrations -o integrations.mysql.test
  425. integrations.mysql8.test: git-check $(GO_SOURCES)
  426. $(GO) test $(GOTESTFLAGS) -mod=vendor -c code.gitea.io/gitea/integrations -o integrations.mysql8.test
  427. integrations.pgsql.test: git-check $(GO_SOURCES)
  428. $(GO) test $(GOTESTFLAGS) -mod=vendor -c code.gitea.io/gitea/integrations -o integrations.pgsql.test
  429. integrations.mssql.test: git-check $(GO_SOURCES)
  430. $(GO) test $(GOTESTFLAGS) -mod=vendor -c code.gitea.io/gitea/integrations -o integrations.mssql.test
  431. integrations.sqlite.test: git-check $(GO_SOURCES)
  432. $(GO) test $(GOTESTFLAGS) -mod=vendor -c code.gitea.io/gitea/integrations -o integrations.sqlite.test -tags '$(TEST_TAGS)'
  433. integrations.cover.test: git-check $(GO_SOURCES)
  434. $(GO) test $(GOTESTFLAGS) -mod=vendor -c code.gitea.io/gitea/integrations -coverpkg $(shell echo $(GO_PACKAGES) | tr ' ' ',') -o integrations.cover.test
  435. .PHONY: migrations.mysql.test
  436. migrations.mysql.test: $(GO_SOURCES)
  437. $(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/integrations/migration-test -o migrations.mysql.test
  438. .PHONY: migrations.mysql8.test
  439. migrations.mysql8.test: $(GO_SOURCES)
  440. $(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/integrations/migration-test -o migrations.mysql8.test
  441. .PHONY: migrations.pgsql.test
  442. migrations.pgsql.test: $(GO_SOURCES)
  443. $(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/integrations/migration-test -o migrations.pgsql.test
  444. .PHONY: migrations.mssql.test
  445. migrations.mssql.test: $(GO_SOURCES)
  446. $(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/integrations/migration-test -o migrations.mssql.test
  447. .PHONY: migrations.sqlite.test
  448. migrations.sqlite.test: $(GO_SOURCES)
  449. $(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/integrations/migration-test -o migrations.sqlite.test -tags '$(TEST_TAGS)'
  450. .PHONY: migrations.individual.mysql.test
  451. migrations.individual.mysql.test: $(GO_SOURCES)
  452. $(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/models/migrations -o migrations.individual.mysql.test
  453. .PHONY: migrations.individual.mysql8.test
  454. migrations.individual.mysql8.test: $(GO_SOURCES)
  455. $(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/models/migrations -o migrations.individual.mysql8.test
  456. .PHONY: migrations.individual.pgsql.test
  457. migrations.individual.pgsql.test: $(GO_SOURCES)
  458. $(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/models/migrations -o migrations.individual.pgsql.test
  459. .PHONY: migrations.individual.mssql.test
  460. migrations.individual.mssql.test: $(GO_SOURCES)
  461. $(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/models/migrations -o migrations.individual.mssql.test
  462. .PHONY: migrations.individual.sqlite.test
  463. migrations.individual.sqlite.test: $(GO_SOURCES)
  464. $(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/models/migrations -o migrations.individual.sqlite.test -tags '$(TEST_TAGS)'
  465. .PHONY: check
  466. check: test
  467. .PHONY: install $(TAGS_PREREQ)
  468. install: $(wildcard *.go)
  469. CGO_CFLAGS="$(CGO_CFLAGS)" $(GO) install -v -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)'
  470. .PHONY: build
  471. build: frontend backend
  472. .PHONY: frontend
  473. frontend: $(WEBPACK_DEST)
  474. .PHONY: backend
  475. backend: go-check generate $(EXECUTABLE)
  476. .PHONY: generate
  477. generate: $(TAGS_PREREQ)
  478. @echo "Running go generate..."
  479. @CC= GOOS= GOARCH= $(GO) generate -mod=vendor -tags '$(TAGS)' $(GO_PACKAGES)
  480. $(EXECUTABLE): $(GO_SOURCES) $(TAGS_PREREQ)
  481. CGO_CFLAGS="$(CGO_CFLAGS)" $(GO) build -mod=vendor $(GOFLAGS) $(EXTRA_GOFLAGS) -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)' -o $@
  482. .PHONY: release
  483. release: frontend generate release-windows release-linux release-darwin release-copy release-compress release-sources release-docs release-check
  484. $(DIST_DIRS):
  485. mkdir -p $(DIST_DIRS)
  486. .PHONY: release-windows
  487. release-windows: | $(DIST_DIRS)
  488. @hash xgo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  489. $(GO) install src.techknowlogick.com/xgo@latest; \
  490. fi
  491. CGO_CFLAGS="$(CGO_CFLAGS)" xgo -go $(XGO_VERSION) -buildmode exe -dest $(DIST)/binaries -tags 'netgo osusergo $(TAGS)' -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -targets 'windows/*' -out gitea-$(VERSION) .
  492. ifeq (,$(findstring gogit,$(TAGS)))
  493. CGO_CFLAGS="$(CGO_CFLAGS)" xgo -go $(XGO_VERSION) -buildmode exe -dest $(DIST)/binaries -tags 'netgo osusergo gogit $(TAGS)' -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -targets 'windows/*' -out gitea-$(VERSION)-gogit .
  494. endif
  495. ifeq ($(CI),drone)
  496. cp /build/* $(DIST)/binaries
  497. endif
  498. .PHONY: release-linux
  499. release-linux: | $(DIST_DIRS)
  500. @hash xgo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  501. $(GO) install src.techknowlogick.com/xgo@latest; \
  502. fi
  503. CGO_CFLAGS="$(CGO_CFLAGS)" xgo -go $(XGO_VERSION) -dest $(DIST)/binaries -tags 'netgo osusergo $(TAGS)' -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -targets '$(LINUX_ARCHS)' -out gitea-$(VERSION) .
  504. ifeq ($(CI),drone)
  505. cp /build/* $(DIST)/binaries
  506. endif
  507. .PHONY: release-darwin
  508. release-darwin: | $(DIST_DIRS)
  509. @hash xgo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  510. $(GO) install src.techknowlogick.com/xgo@latest; \
  511. fi
  512. CGO_CFLAGS="$(CGO_CFLAGS)" xgo -go $(XGO_VERSION) -dest $(DIST)/binaries -tags 'netgo osusergo $(TAGS)' -ldflags '$(LDFLAGS)' -targets 'darwin-10.12/amd64,darwin-10.12/arm64' -out gitea-$(VERSION) .
  513. ifeq ($(CI),drone)
  514. cp /build/* $(DIST)/binaries
  515. endif
  516. .PHONY: release-copy
  517. release-copy: | $(DIST_DIRS)
  518. cd $(DIST); for file in `find /build -type f -name "*"`; do cp $${file} ./release/; done;
  519. .PHONY: release-check
  520. release-check: | $(DIST_DIRS)
  521. cd $(DIST)/release/; for file in `find . -type f -name "*"`; do echo "checksumming $${file}" && $(SHASUM) `echo $${file} | sed 's/^..//'` > $${file}.sha256; done;
  522. .PHONY: release-compress
  523. release-compress: | $(DIST_DIRS)
  524. @hash gxz > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  525. GO111MODULE=off $(GO) get -u github.com/ulikunitz/xz/cmd/gxz; \
  526. fi
  527. cd $(DIST)/release/; for file in `find . -type f -name "*"`; do echo "compressing $${file}" && gxz -k -9 $${file}; done;
  528. .PHONY: release-sources
  529. release-sources: | $(DIST_DIRS)
  530. echo $(VERSION) > $(STORED_VERSION_FILE)
  531. # bsdtar needs a ^ to prevent matching subdirectories
  532. $(eval EXCL := --exclude=$(shell tar --help | grep -q bsdtar && echo "^")./)
  533. tar $(addprefix $(EXCL),$(TAR_EXCLUDES)) -czf $(DIST)/release/gitea-src-$(VERSION).tar.gz .
  534. rm -f $(STORED_VERSION_FILE)
  535. .PHONY: release-docs
  536. release-docs: | $(DIST_DIRS) docs
  537. tar -czf $(DIST)/release/gitea-docs-$(VERSION).tar.gz -C ./docs/public .
  538. .PHONY: docs
  539. docs:
  540. @hash hugo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  541. curl -sL https://github.com/gohugoio/hugo/releases/download/v0.74.3/hugo_0.74.3_Linux-64bit.tar.gz | tar zxf - -C /tmp && mv /tmp/hugo /usr/bin/hugo && chmod +x /usr/bin/hugo; \
  542. fi
  543. cd docs; make trans-copy clean build-offline;
  544. node_modules: package-lock.json
  545. npm install --no-save
  546. @touch node_modules
  547. .PHONY: npm-update
  548. npm-update: node-check | node_modules
  549. npx updates -cu
  550. rm -rf node_modules package-lock.json
  551. npm install --package-lock
  552. @touch node_modules
  553. .PHONY: fomantic
  554. fomantic:
  555. rm -rf $(FOMANTIC_WORK_DIR)/build
  556. cd $(FOMANTIC_WORK_DIR) && npm install --no-save
  557. cp -f $(FOMANTIC_WORK_DIR)/theme.config.less $(FOMANTIC_WORK_DIR)/node_modules/fomantic-ui/src/theme.config
  558. cp -rf $(FOMANTIC_WORK_DIR)/_site $(FOMANTIC_WORK_DIR)/node_modules/fomantic-ui/src/
  559. cd $(FOMANTIC_WORK_DIR) && npx gulp -f node_modules/fomantic-ui/gulpfile.js build
  560. .PHONY: webpack
  561. webpack: $(WEBPACK_DEST)
  562. $(WEBPACK_DEST): $(WEBPACK_SOURCES) $(WEBPACK_CONFIGS) package-lock.json
  563. @$(MAKE) -s node-check node_modules
  564. rm -rf $(WEBPACK_DEST_ENTRIES)
  565. npx webpack
  566. @touch $(WEBPACK_DEST)
  567. .PHONY: svg
  568. svg: node-check | node_modules
  569. rm -rf $(SVG_DEST_DIR)
  570. node build/generate-svg.js
  571. .PHONY: svg-check
  572. svg-check: svg
  573. @git add $(SVG_DEST_DIR)
  574. @diff=$$(git diff --cached $(SVG_DEST_DIR)); \
  575. if [ -n "$$diff" ]; then \
  576. echo "Please run 'make svg' and 'git add $(SVG_DEST_DIR)' and commit the result:"; \
  577. echo "$${diff}"; \
  578. exit 1; \
  579. fi
  580. .PHONY: update-translations
  581. update-translations:
  582. mkdir -p ./translations
  583. cd ./translations && curl -L https://crowdin.com/download/project/gitea.zip > gitea.zip && unzip gitea.zip
  584. rm ./translations/gitea.zip
  585. $(SED_INPLACE) -e 's/="/=/g' -e 's/"$$//g' ./translations/*.ini
  586. $(SED_INPLACE) -e 's/\\"/"/g' ./translations/*.ini
  587. mv ./translations/*.ini ./options/locale/
  588. rmdir ./translations
  589. .PHONY: generate-license
  590. generate-license:
  591. GO111MODULE=on $(GO) run build/generate-licenses.go
  592. .PHONY: generate-gitignore
  593. generate-gitignore:
  594. GO111MODULE=on $(GO) run build/generate-gitignores.go
  595. .PHONY: generate-images
  596. generate-images: | node_modules
  597. npm install --no-save --no-package-lock fabric@4 imagemin-zopfli@7
  598. node build/generate-images.js $(TAGS)
  599. .PHONY: generate-manpage
  600. generate-manpage:
  601. @[ -f gitea ] || make backend
  602. @mkdir -p man/man1/ man/man5
  603. @./gitea docs --man > man/man1/gitea.1
  604. @gzip -9 man/man1/gitea.1 && echo man/man1/gitea.1.gz created
  605. @#TODO A smal script witch format config-cheat-sheet.en-us.md nicely to suit as config man page
  606. .PHONY: pr\#%
  607. pr\#%: clean-all
  608. $(GO) run contrib/pr/checkout.go $*
  609. .PHONY: golangci-lint
  610. golangci-lint:
  611. @hash golangci-lint > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  612. export BINARY="golangci-lint"; \
  613. curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(GOPATH)/bin v1.37.0; \
  614. fi
  615. golangci-lint run --timeout 10m
  616. .PHONY: docker
  617. docker:
  618. docker build --disable-content-trust=false -t $(DOCKER_REF) .
  619. # support also build args docker build --build-arg GITEA_VERSION=v1.2.3 --build-arg TAGS="bindata sqlite sqlite_unlock_notify" .
  620. .PHONY: docker-build
  621. docker-build:
  622. docker run -ti --rm -v "$(CURDIR):/srv/app/src/code.gitea.io/gitea" -w /srv/app/src/code.gitea.io/gitea -e TAGS="bindata $(TAGS)" LDFLAGS="$(LDFLAGS)" CGO_EXTRA_CFLAGS="$(CGO_EXTRA_CFLAGS)" webhippie/golang:edge make clean build
  623. # This endif closes the if at the top of the file
  624. endif