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

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