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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037
  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. GO ?= go
  16. SHASUM ?= shasum -a 256
  17. HAS_GO := $(shell hash $(GO) > /dev/null 2>&1 && echo yes)
  18. COMMA := ,
  19. XGO_VERSION := go-1.21.x
  20. AIR_PACKAGE ?= github.com/cosmtrek/air@v1.44.0
  21. EDITORCONFIG_CHECKER_PACKAGE ?= github.com/editorconfig-checker/editorconfig-checker/cmd/editorconfig-checker@2.7.0
  22. GOFUMPT_PACKAGE ?= mvdan.cc/gofumpt@v0.5.0
  23. GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/cmd/golangci-lint@v1.54.1
  24. GXZ_PACKAGE ?= github.com/ulikunitz/xz/cmd/gxz@v0.5.11
  25. MISSPELL_PACKAGE ?= github.com/golangci/misspell/cmd/misspell@v0.4.1
  26. SWAGGER_PACKAGE ?= github.com/go-swagger/go-swagger/cmd/swagger@v0.30.5
  27. XGO_PACKAGE ?= src.techknowlogick.com/xgo@latest
  28. GO_LICENSES_PACKAGE ?= github.com/google/go-licenses@v1.6.0
  29. GOVULNCHECK_PACKAGE ?= golang.org/x/vuln/cmd/govulncheck@v1.0.1
  30. ACTIONLINT_PACKAGE ?= github.com/rhysd/actionlint/cmd/actionlint@v1.6.25
  31. DOCKER_IMAGE ?= gitea/gitea
  32. DOCKER_TAG ?= latest
  33. DOCKER_REF := $(DOCKER_IMAGE):$(DOCKER_TAG)
  34. ifeq ($(HAS_GO), yes)
  35. GOPATH ?= $(shell $(GO) env GOPATH)
  36. export PATH := $(GOPATH)/bin:$(PATH)
  37. CGO_EXTRA_CFLAGS := -DSQLITE_MAX_VARIABLE_NUMBER=32766
  38. CGO_CFLAGS ?= $(shell $(GO) env CGO_CFLAGS) $(CGO_EXTRA_CFLAGS)
  39. endif
  40. ifeq ($(OS), Windows_NT)
  41. GOFLAGS := -v -buildmode=exe
  42. EXECUTABLE ?= gitea.exe
  43. else ifeq ($(OS), Windows)
  44. GOFLAGS := -v -buildmode=exe
  45. EXECUTABLE ?= gitea.exe
  46. else
  47. GOFLAGS := -v
  48. EXECUTABLE ?= gitea
  49. endif
  50. ifeq ($(shell sed --version 2>/dev/null | grep -q GNU && echo gnu),gnu)
  51. SED_INPLACE := sed -i
  52. else
  53. SED_INPLACE := sed -i ''
  54. endif
  55. EXTRA_GOFLAGS ?=
  56. MAKE_VERSION := $(shell "$(MAKE)" -v | cat | head -n 1)
  57. MAKE_EVIDENCE_DIR := .make_evidence
  58. ifeq ($(RACE_ENABLED),true)
  59. GOFLAGS += -race
  60. GOTESTFLAGS += -race
  61. endif
  62. STORED_VERSION_FILE := VERSION
  63. HUGO_VERSION ?= 0.111.3
  64. GITHUB_REF_TYPE ?= branch
  65. GITHUB_REF_NAME ?= $(shell git rev-parse --abbrev-ref HEAD)
  66. ifneq ($(GITHUB_REF_TYPE),branch)
  67. VERSION ?= $(subst v,,$(GITHUB_REF_NAME))
  68. GITEA_VERSION ?= $(VERSION)
  69. else
  70. ifneq ($(GITHUB_REF_NAME),)
  71. VERSION ?= $(subst release/v,,$(GITHUB_REF_NAME))
  72. else
  73. VERSION ?= main
  74. endif
  75. STORED_VERSION=$(shell cat $(STORED_VERSION_FILE) 2>/dev/null)
  76. ifneq ($(STORED_VERSION),)
  77. GITEA_VERSION ?= $(STORED_VERSION)
  78. else
  79. GITEA_VERSION ?= $(shell git describe --tags --always | sed 's/-/+/' | sed 's/^v//')
  80. endif
  81. endif
  82. # if version = "main" then update version to "nightly"
  83. ifeq ($(VERSION),main)
  84. VERSION := main-nightly
  85. endif
  86. LDFLAGS := $(LDFLAGS) -X "main.MakeVersion=$(MAKE_VERSION)" -X "main.Version=$(GITEA_VERSION)" -X "main.Tags=$(TAGS)"
  87. LINUX_ARCHS ?= linux/amd64,linux/386,linux/arm-5,linux/arm-6,linux/arm64
  88. GO_PACKAGES ?= $(filter-out code.gitea.io/gitea/tests/integration/migration-test code.gitea.io/gitea/tests code.gitea.io/gitea/tests/integration code.gitea.io/gitea/tests/e2e,$(shell $(GO) list ./... | grep -v /vendor/))
  89. GO_TEST_PACKAGES ?= $(filter-out $(shell $(GO) list code.gitea.io/gitea/models/migrations/...) code.gitea.io/gitea/tests/integration/migration-test code.gitea.io/gitea/tests code.gitea.io/gitea/tests/integration code.gitea.io/gitea/tests/e2e,$(shell $(GO) list ./... | grep -v /vendor/))
  90. FOMANTIC_WORK_DIR := web_src/fomantic
  91. WEBPACK_SOURCES := $(shell find web_src/js web_src/css -type f)
  92. WEBPACK_CONFIGS := webpack.config.js
  93. WEBPACK_DEST := public/assets/js/index.js public/assets/css/index.css
  94. WEBPACK_DEST_ENTRIES := public/assets/js public/assets/css public/assets/fonts public/assets/img/webpack
  95. BINDATA_DEST := modules/public/bindata.go modules/options/bindata.go modules/templates/bindata.go
  96. BINDATA_HASH := $(addsuffix .hash,$(BINDATA_DEST))
  97. GENERATED_GO_DEST := modules/charset/invisible_gen.go modules/charset/ambiguous_gen.go
  98. SVG_DEST_DIR := public/assets/img/svg
  99. AIR_TMP_DIR := .air
  100. GO_LICENSE_TMP_DIR := .go-licenses
  101. GO_LICENSE_FILE := assets/go-licenses.json
  102. TAGS ?=
  103. TAGS_SPLIT := $(subst $(COMMA), ,$(TAGS))
  104. TAGS_EVIDENCE := $(MAKE_EVIDENCE_DIR)/tags
  105. TEST_TAGS ?= sqlite sqlite_unlock_notify
  106. TAR_EXCLUDES := .git data indexers queues log node_modules $(EXECUTABLE) $(FOMANTIC_WORK_DIR)/node_modules $(DIST) $(MAKE_EVIDENCE_DIR) $(AIR_TMP_DIR) $(GO_LICENSE_TMP_DIR)
  107. GO_DIRS := build cmd models modules routers services tests
  108. WEB_DIRS := web_src/js web_src/css
  109. SPELLCHECK_FILES := $(GO_DIRS) $(WEB_DIRS) docs/content templates options/locale/locale_en-US.ini .github
  110. GO_SOURCES := $(wildcard *.go)
  111. GO_SOURCES += $(shell find $(GO_DIRS) -type f -name "*.go" ! -path modules/options/bindata.go ! -path modules/public/bindata.go ! -path modules/templates/bindata.go)
  112. GO_SOURCES += $(GENERATED_GO_DEST)
  113. GO_SOURCES_NO_BINDATA := $(GO_SOURCES)
  114. ifeq ($(filter $(TAGS_SPLIT),bindata),bindata)
  115. GO_SOURCES += $(BINDATA_DEST)
  116. GENERATED_GO_DEST += $(BINDATA_DEST)
  117. endif
  118. # Force installation of playwright dependencies by setting this flag
  119. ifdef DEPS_PLAYWRIGHT
  120. PLAYWRIGHT_FLAGS += --with-deps
  121. endif
  122. SWAGGER_SPEC := templates/swagger/v1_json.tmpl
  123. SWAGGER_SPEC_S_TMPL := s|"basePath": *"/api/v1"|"basePath": "{{AppSubUrl \| JSEscape \| Safe}}/api/v1"|g
  124. SWAGGER_SPEC_S_JSON := s|"basePath": *"{{AppSubUrl \| JSEscape \| Safe}}/api/v1"|"basePath": "/api/v1"|g
  125. SWAGGER_EXCLUDE := code.gitea.io/sdk
  126. SWAGGER_NEWLINE_COMMAND := -e '$$a\'
  127. TEST_MYSQL_HOST ?= mysql:3306
  128. TEST_MYSQL_DBNAME ?= testgitea
  129. TEST_MYSQL_USERNAME ?= root
  130. TEST_MYSQL_PASSWORD ?=
  131. TEST_MYSQL8_HOST ?= mysql8:3306
  132. TEST_MYSQL8_DBNAME ?= testgitea
  133. TEST_MYSQL8_USERNAME ?= root
  134. TEST_MYSQL8_PASSWORD ?=
  135. TEST_PGSQL_HOST ?= pgsql:5432
  136. TEST_PGSQL_DBNAME ?= testgitea
  137. TEST_PGSQL_USERNAME ?= postgres
  138. TEST_PGSQL_PASSWORD ?= postgres
  139. TEST_PGSQL_SCHEMA ?= gtestschema
  140. TEST_MSSQL_HOST ?= mssql:1433
  141. TEST_MSSQL_DBNAME ?= gitea
  142. TEST_MSSQL_USERNAME ?= sa
  143. TEST_MSSQL_PASSWORD ?= MwantsaSecurePassword1
  144. .PHONY: all
  145. all: build
  146. .PHONY: help
  147. help:
  148. @echo "Make Routines:"
  149. @echo " - \"\" equivalent to \"build\""
  150. @echo " - build build everything"
  151. @echo " - frontend build frontend files"
  152. @echo " - backend build backend files"
  153. @echo " - watch watch everything and continuously rebuild"
  154. @echo " - watch-frontend watch frontend files and continuously rebuild"
  155. @echo " - watch-backend watch backend files and continuously rebuild"
  156. @echo " - clean delete backend and integration files"
  157. @echo " - clean-all delete backend, frontend and integration files"
  158. @echo " - deps install dependencies"
  159. @echo " - deps-frontend install frontend dependencies"
  160. @echo " - deps-backend install backend dependencies"
  161. @echo " - deps-tools install tool dependencies"
  162. @echo " - deps-py install python dependencies"
  163. @echo " - lint lint everything"
  164. @echo " - lint-fix lint everything and fix issues"
  165. @echo " - lint-actions lint action workflow files"
  166. @echo " - lint-frontend lint frontend files"
  167. @echo " - lint-frontend-fix lint frontend files and fix issues"
  168. @echo " - lint-backend lint backend files"
  169. @echo " - lint-backend-fix lint backend files and fix issues"
  170. @echo " - lint-go lint go files"
  171. @echo " - lint-go-fix lint go files and fix issues"
  172. @echo " - lint-go-vet lint go files with vet"
  173. @echo " - lint-js lint js files"
  174. @echo " - lint-js-fix lint js files and fix issues"
  175. @echo " - lint-css lint css files"
  176. @echo " - lint-css-fix lint css files and fix issues"
  177. @echo " - lint-md lint markdown files"
  178. @echo " - lint-swagger lint swagger files"
  179. @echo " - lint-templates lint template files"
  180. @echo " - lint-yaml lint yaml files"
  181. @echo " - lint-spell lint spelling"
  182. @echo " - lint-spell-fix lint spelling and fix issues"
  183. @echo " - checks run various consistency checks"
  184. @echo " - checks-frontend check frontend files"
  185. @echo " - checks-backend check backend files"
  186. @echo " - test test everything"
  187. @echo " - test-frontend test frontend files"
  188. @echo " - test-backend test backend files"
  189. @echo " - test-e2e[\#TestSpecificName] test end to end using playwright"
  190. @echo " - update update js and py dependencies"
  191. @echo " - update-js update js dependencies"
  192. @echo " - update-py update py dependencies"
  193. @echo " - webpack build webpack files"
  194. @echo " - svg build svg files"
  195. @echo " - fomantic build fomantic files"
  196. @echo " - generate run \"go generate\""
  197. @echo " - fmt format the Go code"
  198. @echo " - generate-license update license files"
  199. @echo " - generate-gitignore update gitignore files"
  200. @echo " - generate-manpage generate manpage"
  201. @echo " - generate-swagger generate the swagger spec from code comments"
  202. @echo " - swagger-validate check if the swagger spec is valid"
  203. @echo " - go-licenses regenerate go licenses"
  204. @echo " - tidy run go mod tidy"
  205. @echo " - test[\#TestSpecificName] run unit test"
  206. @echo " - test-sqlite[\#TestSpecificName] run integration test for sqlite"
  207. .PHONY: go-check
  208. go-check:
  209. $(eval MIN_GO_VERSION_STR := $(shell grep -Eo '^go\s+[0-9]+\.[0-9]+' go.mod | cut -d' ' -f2))
  210. $(eval MIN_GO_VERSION := $(shell printf "%03d%03d" $(shell echo '$(MIN_GO_VERSION_STR)' | tr '.' ' ')))
  211. $(eval GO_VERSION := $(shell printf "%03d%03d" $(shell $(GO) version | grep -Eo '[0-9]+\.[0-9]+' | tr '.' ' ');))
  212. @if [ "$(GO_VERSION)" -lt "$(MIN_GO_VERSION)" ]; then \
  213. echo "Gitea requires Go $(MIN_GO_VERSION_STR) or greater to build. You can get it at https://go.dev/dl/"; \
  214. exit 1; \
  215. fi
  216. .PHONY: git-check
  217. git-check:
  218. @if git lfs >/dev/null 2>&1 ; then : ; else \
  219. echo "Gitea requires git with lfs support to run tests." ; \
  220. exit 1; \
  221. fi
  222. .PHONY: node-check
  223. node-check:
  224. $(eval MIN_NODE_VERSION_STR := $(shell grep -Eo '"node":.*[0-9.]+"' package.json | sed -n 's/.*[^0-9.]\([0-9.]*\)"/\1/p'))
  225. $(eval MIN_NODE_VERSION := $(shell printf "%03d%03d%03d" $(shell echo '$(MIN_NODE_VERSION_STR)' | tr '.' ' ')))
  226. $(eval NODE_VERSION := $(shell printf "%03d%03d%03d" $(shell node -v | cut -c2- | tr '.' ' ');))
  227. $(eval NPM_MISSING := $(shell hash npm > /dev/null 2>&1 || echo 1))
  228. @if [ "$(NODE_VERSION)" -lt "$(MIN_NODE_VERSION)" -o "$(NPM_MISSING)" = "1" ]; then \
  229. echo "Gitea requires Node.js $(MIN_NODE_VERSION_STR) or greater and npm to build. You can get it at https://nodejs.org/en/download/"; \
  230. exit 1; \
  231. fi
  232. .PHONY: clean-all
  233. clean-all: clean
  234. rm -rf $(WEBPACK_DEST_ENTRIES) node_modules
  235. .PHONY: clean
  236. clean:
  237. $(GO) clean -i ./...
  238. rm -rf $(EXECUTABLE) $(DIST) $(BINDATA_DEST) $(BINDATA_HASH) \
  239. integrations*.test \
  240. e2e*.test \
  241. tests/integration/gitea-integration-pgsql/ tests/integration/gitea-integration-mysql/ tests/integration/gitea-integration-mysql8/ tests/integration/gitea-integration-sqlite/ \
  242. tests/integration/gitea-integration-mssql/ tests/integration/indexers-mysql/ tests/integration/indexers-mysql8/ tests/integration/indexers-pgsql tests/integration/indexers-sqlite \
  243. tests/integration/indexers-mssql tests/mysql.ini tests/mysql8.ini tests/pgsql.ini tests/mssql.ini man/ \
  244. tests/e2e/gitea-e2e-pgsql/ tests/e2e/gitea-e2e-mysql/ tests/e2e/gitea-e2e-mysql8/ tests/e2e/gitea-e2e-sqlite/ \
  245. tests/e2e/gitea-e2e-mssql/ tests/e2e/indexers-mysql/ tests/e2e/indexers-mysql8/ tests/e2e/indexers-pgsql/ tests/e2e/indexers-sqlite/ \
  246. tests/e2e/indexers-mssql/ tests/e2e/reports/ tests/e2e/test-artifacts/ tests/e2e/test-snapshots/
  247. .PHONY: fmt
  248. fmt:
  249. GOFUMPT_PACKAGE=$(GOFUMPT_PACKAGE) $(GO) run build/code-batch-process.go gitea-fmt -w '{file-list}'
  250. $(eval TEMPLATES := $(shell find templates -type f -name '*.tmpl'))
  251. @# strip whitespace after '{{' or '(' and before '}}' or ')' unless there is only
  252. @# whitespace before it
  253. @$(SED_INPLACE) \
  254. -e 's/{{[ ]\{1,\}/{{/g' -e '/^[ ]\{1,\}}}/! s/[ ]\{1,\}}}/}}/g' \
  255. -e 's/([ ]\{1,\}/(/g' -e '/^[ ]\{1,\})/! s/[ ]\{1,\})/)/g' \
  256. $(TEMPLATES)
  257. .PHONY: fmt-check
  258. fmt-check: fmt
  259. @diff=$$(git diff --color=always $(GO_SOURCES) templates $(WEB_DIRS)); \
  260. if [ -n "$$diff" ]; then \
  261. echo "Please run 'make fmt' and commit the result:"; \
  262. echo "$${diff}"; \
  263. exit 1; \
  264. fi
  265. .PHONY: $(TAGS_EVIDENCE)
  266. $(TAGS_EVIDENCE):
  267. @mkdir -p $(MAKE_EVIDENCE_DIR)
  268. @echo "$(TAGS)" > $(TAGS_EVIDENCE)
  269. ifneq "$(TAGS)" "$(shell cat $(TAGS_EVIDENCE) 2>/dev/null)"
  270. TAGS_PREREQ := $(TAGS_EVIDENCE)
  271. endif
  272. .PHONY: generate-swagger
  273. generate-swagger: $(SWAGGER_SPEC)
  274. $(SWAGGER_SPEC): $(GO_SOURCES_NO_BINDATA)
  275. $(GO) run $(SWAGGER_PACKAGE) generate spec -x "$(SWAGGER_EXCLUDE)" -o './$(SWAGGER_SPEC)'
  276. $(SED_INPLACE) '$(SWAGGER_SPEC_S_TMPL)' './$(SWAGGER_SPEC)'
  277. $(SED_INPLACE) $(SWAGGER_NEWLINE_COMMAND) './$(SWAGGER_SPEC)'
  278. .PHONY: swagger-check
  279. swagger-check: generate-swagger
  280. @diff=$$(git diff --color=always '$(SWAGGER_SPEC)'); \
  281. if [ -n "$$diff" ]; then \
  282. echo "Please run 'make generate-swagger' and commit the result:"; \
  283. echo "$${diff}"; \
  284. exit 1; \
  285. fi
  286. .PHONY: swagger-validate
  287. swagger-validate:
  288. $(SED_INPLACE) '$(SWAGGER_SPEC_S_JSON)' './$(SWAGGER_SPEC)'
  289. $(GO) run $(SWAGGER_PACKAGE) validate './$(SWAGGER_SPEC)'
  290. $(SED_INPLACE) '$(SWAGGER_SPEC_S_TMPL)' './$(SWAGGER_SPEC)'
  291. .PHONY: checks
  292. checks: checks-frontend checks-backend
  293. .PHONY: checks-frontend
  294. checks-frontend: lockfile-check svg-check
  295. .PHONY: checks-backend
  296. checks-backend: tidy-check swagger-check fmt-check swagger-validate security-check
  297. .PHONY: lint
  298. lint: lint-frontend lint-backend lint-spell
  299. .PHONY: lint-fix
  300. lint-fix: lint-frontend-fix lint-backend-fix lint-spell-fix
  301. .PHONY: lint-frontend
  302. lint-frontend: lint-js lint-css
  303. .PHONY: lint-frontend-fix
  304. lint-frontend-fix: lint-js-fix lint-css-fix
  305. .PHONY: lint-backend
  306. lint-backend: lint-go lint-go-vet lint-editorconfig
  307. .PHONY: lint-backend-fix
  308. lint-backend-fix: lint-go-fix lint-go-vet lint-editorconfig
  309. .PHONY: lint-js
  310. lint-js: node_modules
  311. npx eslint --color --max-warnings=0 --ext js,vue web_src/js build *.config.js tests/e2e
  312. .PHONY: lint-js-fix
  313. lint-js-fix: node_modules
  314. npx eslint --color --max-warnings=0 --ext js,vue web_src/js build *.config.js tests/e2e --fix
  315. .PHONY: lint-css
  316. lint-css: node_modules
  317. npx stylelint --color --max-warnings=0 web_src/css web_src/js/components/*.vue
  318. .PHONY: lint-css-fix
  319. lint-css-fix: node_modules
  320. npx stylelint --color --max-warnings=0 web_src/css web_src/js/components/*.vue --fix
  321. .PHONY: lint-swagger
  322. lint-swagger: node_modules
  323. npx spectral lint -q -F hint $(SWAGGER_SPEC)
  324. .PHONY: lint-md
  325. lint-md: node_modules
  326. npx markdownlint docs *.md
  327. .PHONY: lint-spell
  328. lint-spell:
  329. @go run $(MISSPELL_PACKAGE) -error $(SPELLCHECK_FILES)
  330. .PHONY: lint-spell-fix
  331. lint-spell-fix:
  332. @go run $(MISSPELL_PACKAGE) -w $(SPELLCHECK_FILES)
  333. .PHONY: lint-go
  334. lint-go:
  335. $(GO) run $(GOLANGCI_LINT_PACKAGE) run
  336. .PHONY: lint-go-fix
  337. lint-go-fix:
  338. $(GO) run $(GOLANGCI_LINT_PACKAGE) run --fix
  339. # workaround step for the lint-go-windows CI task because 'go run' can not
  340. # have distinct GOOS/GOARCH for its build and run steps
  341. .PHONY: lint-go-windows
  342. lint-go-windows:
  343. @GOOS= GOARCH= $(GO) install $(GOLANGCI_LINT_PACKAGE)
  344. golangci-lint run
  345. .PHONY: lint-go-vet
  346. lint-go-vet:
  347. @echo "Running go vet..."
  348. @GOOS= GOARCH= $(GO) build code.gitea.io/gitea-vet
  349. @$(GO) vet -vettool=gitea-vet $(GO_PACKAGES)
  350. .PHONY: lint-editorconfig
  351. lint-editorconfig:
  352. $(GO) run $(EDITORCONFIG_CHECKER_PACKAGE) templates .github/workflows
  353. .PHONY: lint-actions
  354. lint-actions:
  355. $(GO) run $(ACTIONLINT_PACKAGE)
  356. .PHONY: lint-templates
  357. lint-templates: .venv
  358. @poetry run djlint $(shell find templates -type f -iname '*.tmpl')
  359. .PHONY: lint-yaml
  360. lint-yaml: .venv
  361. @poetry run yamllint .
  362. .PHONY: watch
  363. watch:
  364. @bash build/watch.sh
  365. .PHONY: watch-frontend
  366. watch-frontend: node-check node_modules
  367. @rm -rf $(WEBPACK_DEST_ENTRIES)
  368. NODE_ENV=development npx webpack --watch --progress
  369. .PHONY: watch-backend
  370. watch-backend: go-check
  371. GITEA_RUN_MODE=dev $(GO) run $(AIR_PACKAGE) -c .air.toml
  372. .PHONY: test
  373. test: test-frontend test-backend
  374. .PHONY: test-backend
  375. test-backend:
  376. @echo "Running go test with $(GOTESTFLAGS) -tags '$(TEST_TAGS)'..."
  377. @$(GO) test $(GOTESTFLAGS) -tags='$(TEST_TAGS)' $(GO_TEST_PACKAGES)
  378. .PHONY: test-frontend
  379. test-frontend: node_modules
  380. npx vitest
  381. .PHONY: test-check
  382. test-check:
  383. @echo "Running test-check...";
  384. @diff=$$(git status -s); \
  385. if [ -n "$$diff" ]; then \
  386. echo "make test-backend has changed files in the source tree:"; \
  387. echo "$${diff}"; \
  388. echo "You should change the tests to create these files in a temporary directory."; \
  389. echo "Do not simply add these files to .gitignore"; \
  390. exit 1; \
  391. fi
  392. .PHONY: test\#%
  393. test\#%:
  394. @echo "Running go test with -tags '$(TEST_TAGS)'..."
  395. @$(GO) test $(GOTESTFLAGS) -tags='$(TEST_TAGS)' -run $(subst .,/,$*) $(GO_TEST_PACKAGES)
  396. .PHONY: coverage
  397. coverage:
  398. grep '^\(mode: .*\)\|\(.*:[0-9]\+\.[0-9]\+,[0-9]\+\.[0-9]\+ [0-9]\+ [0-9]\+\)$$' coverage.out > coverage-bodged.out
  399. grep '^\(mode: .*\)\|\(.*:[0-9]\+\.[0-9]\+,[0-9]\+\.[0-9]\+ [0-9]\+ [0-9]\+\)$$' integration.coverage.out > integration.coverage-bodged.out
  400. $(GO) run build/gocovmerge.go integration.coverage-bodged.out coverage-bodged.out > coverage.all
  401. .PHONY: unit-test-coverage
  402. unit-test-coverage:
  403. @echo "Running unit-test-coverage $(GOTESTFLAGS) -tags '$(TEST_TAGS)'..."
  404. @$(GO) test $(GOTESTFLAGS) -timeout=20m -tags='$(TEST_TAGS)' -cover -coverprofile coverage.out $(GO_TEST_PACKAGES) && echo "\n==>\033[32m Ok\033[m\n" || exit 1
  405. .PHONY: tidy
  406. tidy:
  407. $(eval MIN_GO_VERSION := $(shell grep -Eo '^go\s+[0-9]+\.[0-9.]+' go.mod | cut -d' ' -f2))
  408. $(GO) mod tidy -compat=$(MIN_GO_VERSION)
  409. @$(MAKE) --no-print-directory $(GO_LICENSE_FILE)
  410. vendor: go.mod go.sum
  411. $(GO) mod vendor
  412. @touch vendor
  413. .PHONY: tidy-check
  414. tidy-check: tidy
  415. @diff=$$(git diff --color=always go.mod go.sum $(GO_LICENSE_FILE)); \
  416. if [ -n "$$diff" ]; then \
  417. echo "Please run 'make tidy' and commit the result:"; \
  418. echo "$${diff}"; \
  419. exit 1; \
  420. fi
  421. .PHONY: go-licenses
  422. go-licenses: $(GO_LICENSE_FILE)
  423. $(GO_LICENSE_FILE): go.mod go.sum
  424. -$(GO) run $(GO_LICENSES_PACKAGE) save . --force --save_path=$(GO_LICENSE_TMP_DIR) 2>/dev/null
  425. $(GO) run build/generate-go-licenses.go $(GO_LICENSE_TMP_DIR) $(GO_LICENSE_FILE)
  426. @rm -rf $(GO_LICENSE_TMP_DIR)
  427. generate-ini-sqlite:
  428. sed -e 's|{{REPO_TEST_DIR}}|${REPO_TEST_DIR}|g' \
  429. -e 's|{{TEST_LOGGER}}|$(or $(TEST_LOGGER),test$(COMMA)file)|g' \
  430. -e 's|{{TEST_TYPE}}|$(or $(TEST_TYPE),integration)|g' \
  431. tests/sqlite.ini.tmpl > tests/sqlite.ini
  432. .PHONY: test-sqlite
  433. test-sqlite: integrations.sqlite.test generate-ini-sqlite
  434. GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/sqlite.ini ./integrations.sqlite.test
  435. .PHONY: test-sqlite\#%
  436. test-sqlite\#%: integrations.sqlite.test generate-ini-sqlite
  437. GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/sqlite.ini ./integrations.sqlite.test -test.run $(subst .,/,$*)
  438. .PHONY: test-sqlite-migration
  439. test-sqlite-migration: migrations.sqlite.test migrations.individual.sqlite.test
  440. generate-ini-mysql:
  441. sed -e 's|{{TEST_MYSQL_HOST}}|${TEST_MYSQL_HOST}|g' \
  442. -e 's|{{TEST_MYSQL_DBNAME}}|${TEST_MYSQL_DBNAME}|g' \
  443. -e 's|{{TEST_MYSQL_USERNAME}}|${TEST_MYSQL_USERNAME}|g' \
  444. -e 's|{{TEST_MYSQL_PASSWORD}}|${TEST_MYSQL_PASSWORD}|g' \
  445. -e 's|{{REPO_TEST_DIR}}|${REPO_TEST_DIR}|g' \
  446. -e 's|{{TEST_LOGGER}}|$(or $(TEST_LOGGER),test$(COMMA)file)|g' \
  447. -e 's|{{TEST_TYPE}}|$(or $(TEST_TYPE),integration)|g' \
  448. tests/mysql.ini.tmpl > tests/mysql.ini
  449. .PHONY: test-mysql
  450. test-mysql: integrations.mysql.test generate-ini-mysql
  451. GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mysql.ini ./integrations.mysql.test
  452. .PHONY: test-mysql\#%
  453. test-mysql\#%: integrations.mysql.test generate-ini-mysql
  454. GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mysql.ini ./integrations.mysql.test -test.run $(subst .,/,$*)
  455. .PHONY: test-mysql-migration
  456. test-mysql-migration: migrations.mysql.test migrations.individual.mysql.test
  457. generate-ini-mysql8:
  458. sed -e 's|{{TEST_MYSQL8_HOST}}|${TEST_MYSQL8_HOST}|g' \
  459. -e 's|{{TEST_MYSQL8_DBNAME}}|${TEST_MYSQL8_DBNAME}|g' \
  460. -e 's|{{TEST_MYSQL8_USERNAME}}|${TEST_MYSQL8_USERNAME}|g' \
  461. -e 's|{{TEST_MYSQL8_PASSWORD}}|${TEST_MYSQL8_PASSWORD}|g' \
  462. -e 's|{{REPO_TEST_DIR}}|${REPO_TEST_DIR}|g' \
  463. -e 's|{{TEST_LOGGER}}|$(or $(TEST_LOGGER),test$(COMMA)file)|g' \
  464. -e 's|{{TEST_TYPE}}|$(or $(TEST_TYPE),integration)|g' \
  465. tests/mysql8.ini.tmpl > tests/mysql8.ini
  466. .PHONY: test-mysql8
  467. test-mysql8: integrations.mysql8.test generate-ini-mysql8
  468. GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mysql8.ini ./integrations.mysql8.test
  469. .PHONY: test-mysql8\#%
  470. test-mysql8\#%: integrations.mysql8.test generate-ini-mysql8
  471. GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mysql8.ini ./integrations.mysql8.test -test.run $(subst .,/,$*)
  472. .PHONY: test-mysql8-migration
  473. test-mysql8-migration: migrations.mysql8.test migrations.individual.mysql8.test
  474. generate-ini-pgsql:
  475. sed -e 's|{{TEST_PGSQL_HOST}}|${TEST_PGSQL_HOST}|g' \
  476. -e 's|{{TEST_PGSQL_DBNAME}}|${TEST_PGSQL_DBNAME}|g' \
  477. -e 's|{{TEST_PGSQL_USERNAME}}|${TEST_PGSQL_USERNAME}|g' \
  478. -e 's|{{TEST_PGSQL_PASSWORD}}|${TEST_PGSQL_PASSWORD}|g' \
  479. -e 's|{{TEST_PGSQL_SCHEMA}}|${TEST_PGSQL_SCHEMA}|g' \
  480. -e 's|{{REPO_TEST_DIR}}|${REPO_TEST_DIR}|g' \
  481. -e 's|{{TEST_LOGGER}}|$(or $(TEST_LOGGER),test$(COMMA)file)|g' \
  482. -e 's|{{TEST_TYPE}}|$(or $(TEST_TYPE),integration)|g' \
  483. tests/pgsql.ini.tmpl > tests/pgsql.ini
  484. .PHONY: test-pgsql
  485. test-pgsql: integrations.pgsql.test generate-ini-pgsql
  486. GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/pgsql.ini ./integrations.pgsql.test
  487. .PHONY: test-pgsql\#%
  488. test-pgsql\#%: integrations.pgsql.test generate-ini-pgsql
  489. GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/pgsql.ini ./integrations.pgsql.test -test.run $(subst .,/,$*)
  490. .PHONY: test-pgsql-migration
  491. test-pgsql-migration: migrations.pgsql.test migrations.individual.pgsql.test
  492. generate-ini-mssql:
  493. sed -e 's|{{TEST_MSSQL_HOST}}|${TEST_MSSQL_HOST}|g' \
  494. -e 's|{{TEST_MSSQL_DBNAME}}|${TEST_MSSQL_DBNAME}|g' \
  495. -e 's|{{TEST_MSSQL_USERNAME}}|${TEST_MSSQL_USERNAME}|g' \
  496. -e 's|{{TEST_MSSQL_PASSWORD}}|${TEST_MSSQL_PASSWORD}|g' \
  497. -e 's|{{REPO_TEST_DIR}}|${REPO_TEST_DIR}|g' \
  498. -e 's|{{TEST_LOGGER}}|$(or $(TEST_LOGGER),test$(COMMA)file)|g' \
  499. -e 's|{{TEST_TYPE}}|$(or $(TEST_TYPE),integration)|g' \
  500. tests/mssql.ini.tmpl > tests/mssql.ini
  501. .PHONY: test-mssql
  502. test-mssql: integrations.mssql.test generate-ini-mssql
  503. GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mssql.ini ./integrations.mssql.test
  504. .PHONY: test-mssql\#%
  505. test-mssql\#%: integrations.mssql.test generate-ini-mssql
  506. GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mssql.ini ./integrations.mssql.test -test.run $(subst .,/,$*)
  507. .PHONY: test-mssql-migration
  508. test-mssql-migration: migrations.mssql.test migrations.individual.mssql.test
  509. .PHONY: playwright
  510. playwright: $(PLAYWRIGHT_DIR)
  511. npm install --no-save @playwright/test
  512. npx playwright install $(PLAYWRIGHT_FLAGS)
  513. .PHONY: test-e2e%
  514. test-e2e%: TEST_TYPE ?= e2e
  515. # Clear display env variable. Otherwise, chromium tests can fail.
  516. DISPLAY=
  517. .PHONY: test-e2e
  518. test-e2e: test-e2e-sqlite
  519. .PHONY: test-e2e-sqlite
  520. test-e2e-sqlite: playwright e2e.sqlite.test generate-ini-sqlite
  521. GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/sqlite.ini ./e2e.sqlite.test
  522. .PHONY: test-e2e-sqlite\#%
  523. test-e2e-sqlite\#%: playwright e2e.sqlite.test generate-ini-sqlite
  524. GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/sqlite.ini ./e2e.sqlite.test -test.run TestE2e/$*
  525. .PHONY: test-e2e-mysql
  526. test-e2e-mysql: playwright e2e.mysql.test generate-ini-mysql
  527. GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mysql.ini ./e2e.mysql.test
  528. .PHONY: test-e2e-mysql\#%
  529. test-e2e-mysql\#%: playwright e2e.mysql.test generate-ini-mysql
  530. GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mysql.ini ./e2e.mysql.test -test.run TestE2e/$*
  531. .PHONY: test-e2e-mysql8
  532. test-e2e-mysql8: playwright e2e.mysql8.test generate-ini-mysql8
  533. GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mysql8.ini ./e2e.mysql8.test
  534. .PHONY: test-e2e-mysql8\#%
  535. test-e2e-mysql8\#%: playwright e2e.mysql8.test generate-ini-mysql8
  536. GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mysql8.ini ./e2e.mysql8.test -test.run TestE2e/$*
  537. .PHONY: test-e2e-pgsql
  538. test-e2e-pgsql: playwright e2e.pgsql.test generate-ini-pgsql
  539. GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/pgsql.ini ./e2e.pgsql.test
  540. .PHONY: test-e2e-pgsql\#%
  541. test-e2e-pgsql\#%: playwright e2e.pgsql.test generate-ini-pgsql
  542. GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/pgsql.ini ./e2e.pgsql.test -test.run TestE2e/$*
  543. .PHONY: test-e2e-mssql
  544. test-e2e-mssql: playwright e2e.mssql.test generate-ini-mssql
  545. GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mssql.ini ./e2e.mssql.test
  546. .PHONY: test-e2e-mssql\#%
  547. test-e2e-mssql\#%: playwright e2e.mssql.test generate-ini-mssql
  548. GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mssql.ini ./e2e.mssql.test -test.run TestE2e/$*
  549. .PHONY: bench-sqlite
  550. bench-sqlite: integrations.sqlite.test generate-ini-sqlite
  551. GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/sqlite.ini ./integrations.sqlite.test -test.cpuprofile=cpu.out -test.run DontRunTests -test.bench .
  552. .PHONY: bench-mysql
  553. bench-mysql: integrations.mysql.test generate-ini-mysql
  554. GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mysql.ini ./integrations.mysql.test -test.cpuprofile=cpu.out -test.run DontRunTests -test.bench .
  555. .PHONY: bench-mssql
  556. bench-mssql: integrations.mssql.test generate-ini-mssql
  557. GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mssql.ini ./integrations.mssql.test -test.cpuprofile=cpu.out -test.run DontRunTests -test.bench .
  558. .PHONY: bench-pgsql
  559. bench-pgsql: integrations.pgsql.test generate-ini-pgsql
  560. GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/pgsql.ini ./integrations.pgsql.test -test.cpuprofile=cpu.out -test.run DontRunTests -test.bench .
  561. .PHONY: integration-test-coverage
  562. integration-test-coverage: integrations.cover.test generate-ini-mysql
  563. GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mysql.ini ./integrations.cover.test -test.coverprofile=integration.coverage.out
  564. .PHONY: integration-test-coverage-sqlite
  565. integration-test-coverage-sqlite: integrations.cover.sqlite.test generate-ini-sqlite
  566. GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/sqlite.ini ./integrations.cover.sqlite.test -test.coverprofile=integration.coverage.out
  567. integrations.mysql.test: git-check $(GO_SOURCES)
  568. $(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/tests/integration -o integrations.mysql.test
  569. integrations.mysql8.test: git-check $(GO_SOURCES)
  570. $(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/tests/integration -o integrations.mysql8.test
  571. integrations.pgsql.test: git-check $(GO_SOURCES)
  572. $(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/tests/integration -o integrations.pgsql.test
  573. integrations.mssql.test: git-check $(GO_SOURCES)
  574. $(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/tests/integration -o integrations.mssql.test
  575. integrations.sqlite.test: git-check $(GO_SOURCES)
  576. $(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/tests/integration -o integrations.sqlite.test -tags '$(TEST_TAGS)'
  577. integrations.cover.test: git-check $(GO_SOURCES)
  578. $(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/tests/integration -coverpkg $(shell echo $(GO_TEST_PACKAGES) | tr ' ' ',') -o integrations.cover.test
  579. integrations.cover.sqlite.test: git-check $(GO_SOURCES)
  580. $(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/tests/integration -coverpkg $(shell echo $(GO_TEST_PACKAGES) | tr ' ' ',') -o integrations.cover.sqlite.test -tags '$(TEST_TAGS)'
  581. .PHONY: migrations.mysql.test
  582. migrations.mysql.test: $(GO_SOURCES) generate-ini-mysql
  583. $(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/tests/integration/migration-test -o migrations.mysql.test
  584. GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mysql.ini ./migrations.mysql.test
  585. .PHONY: migrations.mysql8.test
  586. migrations.mysql8.test: $(GO_SOURCES) generate-ini-mysql8
  587. $(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/tests/integration/migration-test -o migrations.mysql8.test
  588. GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mysql8.ini ./migrations.mysql8.test
  589. .PHONY: migrations.pgsql.test
  590. migrations.pgsql.test: $(GO_SOURCES) generate-ini-pgsql
  591. $(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/tests/integration/migration-test -o migrations.pgsql.test
  592. GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/pgsql.ini ./migrations.pgsql.test
  593. .PHONY: migrations.mssql.test
  594. migrations.mssql.test: $(GO_SOURCES) generate-ini-mssql
  595. $(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/tests/integration/migration-test -o migrations.mssql.test
  596. GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mssql.ini ./migrations.mssql.test
  597. .PHONY: migrations.sqlite.test
  598. migrations.sqlite.test: $(GO_SOURCES) generate-ini-sqlite
  599. $(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/tests/integration/migration-test -o migrations.sqlite.test -tags '$(TEST_TAGS)'
  600. GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/sqlite.ini ./migrations.sqlite.test
  601. .PHONY: migrations.individual.mysql.test
  602. migrations.individual.mysql.test: $(GO_SOURCES)
  603. for pkg in $(shell $(GO) list code.gitea.io/gitea/models/migrations/...); do \
  604. GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mysql.ini $(GO) test $(GOTESTFLAGS) -tags '$(TEST_TAGS)' $$pkg; \
  605. done
  606. .PHONY: migrations.individual.mysql8.test
  607. migrations.individual.mysql8.test: $(GO_SOURCES)
  608. for pkg in $(shell $(GO) list code.gitea.io/gitea/models/migrations/...); do \
  609. GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mysql8.ini $(GO) test $(GOTESTFLAGS) -tags '$(TEST_TAGS)' $$pkg; \
  610. done
  611. .PHONY: migrations.individual.mysql8.test\#%
  612. migrations.individual.sqlite.test\#%: $(GO_SOURCES) generate-ini-sqlite
  613. GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/sqlite.ini $(GO) test $(GOTESTFLAGS) -tags '$(TEST_TAGS)' code.gitea.io/gitea/models/migrations/$*
  614. .PHONY: migrations.individual.pgsql.test
  615. migrations.individual.pgsql.test: $(GO_SOURCES)
  616. for pkg in $(shell $(GO) list code.gitea.io/gitea/models/migrations/...); do \
  617. GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/pgsql.ini $(GO) test $(GOTESTFLAGS) -tags '$(TEST_TAGS)' $$pkg; \
  618. done
  619. .PHONY: migrations.individual.pgsql.test\#%
  620. migrations.individual.pgsql.test\#%: $(GO_SOURCES) generate-ini-pgsql
  621. GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/pgsql.ini $(GO) test $(GOTESTFLAGS) -tags '$(TEST_TAGS)' code.gitea.io/gitea/models/migrations/$*
  622. .PHONY: migrations.individual.mssql.test
  623. migrations.individual.mssql.test: $(GO_SOURCES) generate-ini-mssql
  624. for pkg in $(shell $(GO) list code.gitea.io/gitea/models/migrations/...); do \
  625. GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mssql.ini $(GO) test $(GOTESTFLAGS) -tags '$(TEST_TAGS)' $$pkg -test.failfast; \
  626. done
  627. .PHONY: migrations.individual.mssql.test\#%
  628. migrations.individual.mssql.test\#%: $(GO_SOURCES) generate-ini-mssql
  629. GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mssql.ini $(GO) test $(GOTESTFLAGS) -tags '$(TEST_TAGS)' code.gitea.io/gitea/models/migrations/$*
  630. .PHONY: migrations.individual.sqlite.test
  631. migrations.individual.sqlite.test: $(GO_SOURCES) generate-ini-sqlite
  632. for pkg in $(shell $(GO) list code.gitea.io/gitea/models/migrations/...); do \
  633. GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/sqlite.ini $(GO) test $(GOTESTFLAGS) -tags '$(TEST_TAGS)' $$pkg; \
  634. done
  635. .PHONY: migrations.individual.sqlite.test\#%
  636. migrations.individual.sqlite.test\#%: $(GO_SOURCES) generate-ini-sqlite
  637. GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/sqlite.ini $(GO) test $(GOTESTFLAGS) -tags '$(TEST_TAGS)' code.gitea.io/gitea/models/migrations/$*
  638. e2e.mysql.test: $(GO_SOURCES)
  639. $(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/tests/e2e -o e2e.mysql.test
  640. e2e.mysql8.test: $(GO_SOURCES)
  641. $(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/tests/e2e -o e2e.mysql8.test
  642. e2e.pgsql.test: $(GO_SOURCES)
  643. $(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/tests/e2e -o e2e.pgsql.test
  644. e2e.mssql.test: $(GO_SOURCES)
  645. $(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/tests/e2e -o e2e.mssql.test
  646. e2e.sqlite.test: $(GO_SOURCES)
  647. $(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/tests/e2e -o e2e.sqlite.test -tags '$(TEST_TAGS)'
  648. .PHONY: check
  649. check: test
  650. .PHONY: install $(TAGS_PREREQ)
  651. install: $(wildcard *.go)
  652. CGO_CFLAGS="$(CGO_CFLAGS)" $(GO) install -v -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)'
  653. .PHONY: build
  654. build: frontend backend
  655. .PHONY: frontend
  656. frontend: $(WEBPACK_DEST)
  657. .PHONY: backend
  658. backend: go-check generate-backend $(EXECUTABLE)
  659. # We generate the backend before the frontend in case we in future we want to generate things in the frontend from generated files in backend
  660. .PHONY: generate
  661. generate: generate-backend
  662. .PHONY: generate-backend
  663. generate-backend: $(TAGS_PREREQ) generate-go
  664. .PHONY: generate-go
  665. generate-go: $(TAGS_PREREQ)
  666. @echo "Running go generate..."
  667. @CC= GOOS= GOARCH= $(GO) generate -tags '$(TAGS)' $(GO_PACKAGES)
  668. .PHONY: security-check
  669. security-check:
  670. go run $(GOVULNCHECK_PACKAGE) ./...
  671. $(EXECUTABLE): $(GO_SOURCES) $(TAGS_PREREQ)
  672. CGO_CFLAGS="$(CGO_CFLAGS)" $(GO) build $(GOFLAGS) $(EXTRA_GOFLAGS) -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)' -o $@
  673. .PHONY: release
  674. release: frontend generate release-windows release-linux release-darwin release-freebsd release-copy release-compress vendor release-sources release-docs release-check
  675. $(DIST_DIRS):
  676. mkdir -p $(DIST_DIRS)
  677. .PHONY: release-windows
  678. release-windows: | $(DIST_DIRS)
  679. CGO_CFLAGS="$(CGO_CFLAGS)" $(GO) run $(XGO_PACKAGE) -go $(XGO_VERSION) -buildmode exe -dest $(DIST)/binaries -tags 'osusergo $(TAGS)' -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -targets 'windows/*' -out gitea-$(VERSION) .
  680. ifeq (,$(findstring gogit,$(TAGS)))
  681. CGO_CFLAGS="$(CGO_CFLAGS)" $(GO) run $(XGO_PACKAGE) -go $(XGO_VERSION) -buildmode exe -dest $(DIST)/binaries -tags 'osusergo gogit $(TAGS)' -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -targets 'windows/*' -out gitea-$(VERSION)-gogit .
  682. endif
  683. .PHONY: release-linux
  684. release-linux: | $(DIST_DIRS)
  685. CGO_CFLAGS="$(CGO_CFLAGS)" $(GO) run $(XGO_PACKAGE) -go $(XGO_VERSION) -dest $(DIST)/binaries -tags 'netgo osusergo $(TAGS)' -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -targets '$(LINUX_ARCHS)' -out gitea-$(VERSION) .
  686. .PHONY: release-darwin
  687. release-darwin: | $(DIST_DIRS)
  688. CGO_CFLAGS="$(CGO_CFLAGS)" $(GO) run $(XGO_PACKAGE) -go $(XGO_VERSION) -dest $(DIST)/binaries -tags 'netgo osusergo $(TAGS)' -ldflags '$(LDFLAGS)' -targets 'darwin-10.12/amd64,darwin-10.12/arm64' -out gitea-$(VERSION) .
  689. .PHONY: release-freebsd
  690. release-freebsd: | $(DIST_DIRS)
  691. CGO_CFLAGS="$(CGO_CFLAGS)" $(GO) run $(XGO_PACKAGE) -go $(XGO_VERSION) -dest $(DIST)/binaries -tags 'netgo osusergo $(TAGS)' -ldflags '$(LDFLAGS)' -targets 'freebsd/amd64' -out gitea-$(VERSION) .
  692. .PHONY: release-copy
  693. release-copy: | $(DIST_DIRS)
  694. cd $(DIST); for file in `find . -type f -name "*"`; do cp $${file} ./release/; done;
  695. .PHONY: release-check
  696. release-check: | $(DIST_DIRS)
  697. cd $(DIST)/release/; for file in `find . -type f -name "*"`; do echo "checksumming $${file}" && $(SHASUM) `echo $${file} | sed 's/^..//'` > $${file}.sha256; done;
  698. .PHONY: release-compress
  699. release-compress: | $(DIST_DIRS)
  700. cd $(DIST)/release/; for file in `find . -type f -name "*"`; do echo "compressing $${file}" && $(GO) run $(GXZ_PACKAGE) -k -9 $${file}; done;
  701. .PHONY: release-sources
  702. release-sources: | $(DIST_DIRS)
  703. echo $(VERSION) > $(STORED_VERSION_FILE)
  704. # bsdtar needs a ^ to prevent matching subdirectories
  705. $(eval EXCL := --exclude=$(shell tar --help | grep -q bsdtar && echo "^")./)
  706. # use transform to a add a release-folder prefix; in bsdtar the transform parameter equivalent is -s
  707. $(eval TRANSFORM := $(shell tar --help | grep -q bsdtar && echo "-s '/^./gitea-src-$(VERSION)/'" || echo "--transform 's|^./|gitea-src-$(VERSION)/|'"))
  708. tar $(addprefix $(EXCL),$(TAR_EXCLUDES)) $(TRANSFORM) -czf $(DIST)/release/gitea-src-$(VERSION).tar.gz .
  709. rm -f $(STORED_VERSION_FILE)
  710. .PHONY: release-docs
  711. release-docs: | $(DIST_DIRS) docs
  712. tar -czf $(DIST)/release/gitea-docs-$(VERSION).tar.gz -C ./docs .
  713. .PHONY: docs
  714. docs:
  715. cd docs; bash scripts/trans-copy.sh;
  716. .PHONY: deps
  717. deps: deps-frontend deps-backend deps-tools deps-py
  718. .PHONY: deps-py
  719. deps-py: .venv
  720. .PHONY: deps-frontend
  721. deps-frontend: node_modules
  722. .PHONY: deps-backend
  723. deps-backend:
  724. $(GO) mod download
  725. .PHONY: deps-tools
  726. deps-tools:
  727. $(GO) install $(AIR_PACKAGE)
  728. $(GO) install $(EDITORCONFIG_CHECKER_PACKAGE)
  729. $(GO) install $(GOFUMPT_PACKAGE)
  730. $(GO) install $(GOLANGCI_LINT_PACKAGE)
  731. $(GO) install $(GXZ_PACKAGE)
  732. $(GO) install $(MISSPELL_PACKAGE)
  733. $(GO) install $(SWAGGER_PACKAGE)
  734. $(GO) install $(XGO_PACKAGE)
  735. $(GO) install $(GO_LICENSES_PACKAGE)
  736. $(GO) install $(GOVULNCHECK_PACKAGE)
  737. $(GO) install $(ACTIONLINT_PACKAGE)
  738. node_modules: package-lock.json
  739. npm install --no-save
  740. @touch node_modules
  741. .venv: poetry.lock
  742. poetry install --no-root
  743. @touch .venv
  744. .PHONY: update
  745. update: update-js update-py
  746. .PHONY: update-js
  747. update-js: node-check | node_modules
  748. npx updates -u -f package.json
  749. rm -rf node_modules package-lock.json
  750. npm install --package-lock
  751. @touch node_modules
  752. .PHONY: update-py
  753. update-py: node-check | node_modules
  754. npx updates -u -f pyproject.toml
  755. rm -rf .venv poetry.lock
  756. poetry install
  757. @touch .venv
  758. .PHONY: fomantic
  759. fomantic:
  760. rm -rf $(FOMANTIC_WORK_DIR)/build
  761. cd $(FOMANTIC_WORK_DIR) && npm install --no-save
  762. cp -f $(FOMANTIC_WORK_DIR)/theme.config.less $(FOMANTIC_WORK_DIR)/node_modules/fomantic-ui/src/theme.config
  763. cp -rf $(FOMANTIC_WORK_DIR)/_site $(FOMANTIC_WORK_DIR)/node_modules/fomantic-ui/src/
  764. cd $(FOMANTIC_WORK_DIR) && npx gulp -f node_modules/fomantic-ui/gulpfile.js build
  765. # fomantic uses "touchstart" as click event for some browsers, it's not ideal, so we force fomantic to always use "click" as click event
  766. $(SED_INPLACE) -e 's/clickEvent[ \t]*=/clickEvent = "click", unstableClickEvent =/g' $(FOMANTIC_WORK_DIR)/build/semantic.js
  767. $(SED_INPLACE) -e 's/\r//g' $(FOMANTIC_WORK_DIR)/build/semantic.css $(FOMANTIC_WORK_DIR)/build/semantic.js
  768. rm -f $(FOMANTIC_WORK_DIR)/build/*.min.*
  769. .PHONY: webpack
  770. webpack: $(WEBPACK_DEST)
  771. $(WEBPACK_DEST): $(WEBPACK_SOURCES) $(WEBPACK_CONFIGS) package-lock.json
  772. @$(MAKE) -s node-check node_modules
  773. rm -rf $(WEBPACK_DEST_ENTRIES)
  774. npx webpack
  775. @touch $(WEBPACK_DEST)
  776. .PHONY: svg
  777. svg: node-check | node_modules
  778. rm -rf $(SVG_DEST_DIR)
  779. node build/generate-svg.js
  780. .PHONY: svg-check
  781. svg-check: svg
  782. @git add $(SVG_DEST_DIR)
  783. @diff=$$(git diff --color=always --cached $(SVG_DEST_DIR)); \
  784. if [ -n "$$diff" ]; then \
  785. echo "Please run 'make svg' and 'git add $(SVG_DEST_DIR)' and commit the result:"; \
  786. echo "$${diff}"; \
  787. exit 1; \
  788. fi
  789. .PHONY: lockfile-check
  790. lockfile-check:
  791. npm install --package-lock-only
  792. @diff=$$(git diff --color=always package-lock.json); \
  793. if [ -n "$$diff" ]; then \
  794. echo "package-lock.json is inconsistent with package.json"; \
  795. echo "Please run 'npm install --package-lock-only' and commit the result:"; \
  796. echo "$${diff}"; \
  797. exit 1; \
  798. fi
  799. .PHONY: update-translations
  800. update-translations:
  801. mkdir -p ./translations
  802. cd ./translations && curl -L https://crowdin.com/download/project/gitea.zip > gitea.zip && unzip gitea.zip
  803. rm ./translations/gitea.zip
  804. $(SED_INPLACE) -e 's/="/=/g' -e 's/"$$//g' ./translations/*.ini
  805. $(SED_INPLACE) -e 's/\\"/"/g' ./translations/*.ini
  806. mv ./translations/*.ini ./options/locale/
  807. rmdir ./translations
  808. .PHONY: generate-license
  809. generate-license:
  810. $(GO) run build/generate-licenses.go
  811. .PHONY: generate-gitignore
  812. generate-gitignore:
  813. $(GO) run build/generate-gitignores.go
  814. .PHONY: generate-images
  815. generate-images: | node_modules
  816. npm install --no-save --no-package-lock fabric@5 imagemin-zopfli@7
  817. node build/generate-images.js $(TAGS)
  818. .PHONY: generate-manpage
  819. generate-manpage:
  820. @[ -f gitea ] || make backend
  821. @mkdir -p man/man1/ man/man5
  822. @./gitea docs --man > man/man1/gitea.1
  823. @gzip -9 man/man1/gitea.1 && echo man/man1/gitea.1.gz created
  824. @#TODO A small script that formats config-cheat-sheet.en-us.md nicely for use as a config man page
  825. .PHONY: docker
  826. docker:
  827. docker build --disable-content-trust=false -t $(DOCKER_REF) .
  828. # support also build args docker build --build-arg GITEA_VERSION=v1.2.3 --build-arg TAGS="bindata sqlite sqlite_unlock_notify" .
  829. # This endif closes the if at the top of the file
  830. endif