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

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