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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027
  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.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.53.3
  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.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@v0.2.0
  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. GO_SOURCES := $(wildcard *.go)
  110. 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)
  111. GO_SOURCES += $(GENERATED_GO_DEST)
  112. GO_SOURCES_NO_BINDATA := $(GO_SOURCES)
  113. ifeq ($(filter $(TAGS_SPLIT),bindata),bindata)
  114. GO_SOURCES += $(BINDATA_DEST)
  115. GENERATED_GO_DEST += $(BINDATA_DEST)
  116. endif
  117. # Force installation of playwright dependencies by setting this flag
  118. ifdef DEPS_PLAYWRIGHT
  119. PLAYWRIGHT_FLAGS += --with-deps
  120. endif
  121. SWAGGER_SPEC := templates/swagger/v1_json.tmpl
  122. SWAGGER_SPEC_S_TMPL := s|"basePath": *"/api/v1"|"basePath": "{{AppSubUrl \| JSEscape \| Safe}}/api/v1"|g
  123. SWAGGER_SPEC_S_JSON := s|"basePath": *"{{AppSubUrl \| JSEscape \| Safe}}/api/v1"|"basePath": "/api/v1"|g
  124. SWAGGER_EXCLUDE := code.gitea.io/sdk
  125. SWAGGER_NEWLINE_COMMAND := -e '$$a\'
  126. TEST_MYSQL_HOST ?= mysql:3306
  127. TEST_MYSQL_DBNAME ?= testgitea
  128. TEST_MYSQL_USERNAME ?= root
  129. TEST_MYSQL_PASSWORD ?=
  130. TEST_MYSQL8_HOST ?= mysql8:3306
  131. TEST_MYSQL8_DBNAME ?= testgitea
  132. TEST_MYSQL8_USERNAME ?= root
  133. TEST_MYSQL8_PASSWORD ?=
  134. TEST_PGSQL_HOST ?= pgsql:5432
  135. TEST_PGSQL_DBNAME ?= testgitea
  136. TEST_PGSQL_USERNAME ?= postgres
  137. TEST_PGSQL_PASSWORD ?= postgres
  138. TEST_PGSQL_SCHEMA ?= gtestschema
  139. TEST_MSSQL_HOST ?= mssql:1433
  140. TEST_MSSQL_DBNAME ?= gitea
  141. TEST_MSSQL_USERNAME ?= sa
  142. TEST_MSSQL_PASSWORD ?= MwantsaSecurePassword1
  143. .PHONY: all
  144. all: build
  145. .PHONY: help
  146. help:
  147. @echo "Make Routines:"
  148. @echo " - \"\" equivalent to \"build\""
  149. @echo " - build build everything"
  150. @echo " - frontend build frontend files"
  151. @echo " - backend build backend files"
  152. @echo " - watch watch everything and continuously rebuild"
  153. @echo " - watch-frontend watch frontend files and continuously rebuild"
  154. @echo " - watch-backend watch backend files and continuously rebuild"
  155. @echo " - clean delete backend and integration files"
  156. @echo " - clean-all delete backend, frontend and integration files"
  157. @echo " - deps install dependencies"
  158. @echo " - deps-docs install docs 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 " - checks run various consistency checks"
  181. @echo " - checks-frontend check frontend files"
  182. @echo " - checks-backend check backend files"
  183. @echo " - test test everything"
  184. @echo " - test-frontend test frontend files"
  185. @echo " - test-backend test backend files"
  186. @echo " - test-e2e[\#TestSpecificName] test end to end using playwright"
  187. @echo " - update-js update js dependencies"
  188. @echo " - update-py update py dependencies"
  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
  302. .PHONY: lint-frontend-fix
  303. lint-frontend-fix: lint-js-fix lint-css-fix
  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 docs/assets/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 docs/assets/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: lint-templates
  350. lint-templates: .venv
  351. @poetry run djlint $(shell find templates -type f -iname '*.tmpl')
  352. .PHONY: watch
  353. watch:
  354. @bash build/watch.sh
  355. .PHONY: watch-frontend
  356. watch-frontend: node-check node_modules
  357. @rm -rf $(WEBPACK_DEST_ENTRIES)
  358. NODE_ENV=development npx webpack --watch --progress
  359. .PHONY: watch-backend
  360. watch-backend: go-check
  361. GITEA_RUN_MODE=dev $(GO) run $(AIR_PACKAGE) -c .air.toml
  362. .PHONY: test
  363. test: test-frontend test-backend
  364. .PHONY: test-backend
  365. test-backend:
  366. @echo "Running go test with $(GOTESTFLAGS) -tags '$(TEST_TAGS)'..."
  367. @$(GO) test $(GOTESTFLAGS) -tags='$(TEST_TAGS)' $(GO_TEST_PACKAGES)
  368. .PHONY: test-frontend
  369. test-frontend: node_modules
  370. npx vitest
  371. .PHONY: test-check
  372. test-check:
  373. @echo "Running test-check...";
  374. @diff=$$(git status -s); \
  375. if [ -n "$$diff" ]; then \
  376. echo "make test-backend has changed files in the source tree:"; \
  377. echo "$${diff}"; \
  378. echo "You should change the tests to create these files in a temporary directory."; \
  379. echo "Do not simply add these files to .gitignore"; \
  380. exit 1; \
  381. fi
  382. .PHONY: test\#%
  383. test\#%:
  384. @echo "Running go test with -tags '$(TEST_TAGS)'..."
  385. @$(GO) test $(GOTESTFLAGS) -tags='$(TEST_TAGS)' -run $(subst .,/,$*) $(GO_TEST_PACKAGES)
  386. .PHONY: coverage
  387. coverage:
  388. grep '^\(mode: .*\)\|\(.*:[0-9]\+\.[0-9]\+,[0-9]\+\.[0-9]\+ [0-9]\+ [0-9]\+\)$$' coverage.out > coverage-bodged.out
  389. grep '^\(mode: .*\)\|\(.*:[0-9]\+\.[0-9]\+,[0-9]\+\.[0-9]\+ [0-9]\+ [0-9]\+\)$$' integration.coverage.out > integration.coverage-bodged.out
  390. $(GO) run build/gocovmerge.go integration.coverage-bodged.out coverage-bodged.out > coverage.all
  391. .PHONY: unit-test-coverage
  392. unit-test-coverage:
  393. @echo "Running unit-test-coverage $(GOTESTFLAGS) -tags '$(TEST_TAGS)'..."
  394. @$(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
  395. .PHONY: tidy
  396. tidy:
  397. $(eval MIN_GO_VERSION := $(shell grep -Eo '^go\s+[0-9]+\.[0-9.]+' go.mod | cut -d' ' -f2))
  398. $(GO) mod tidy -compat=$(MIN_GO_VERSION)
  399. @$(MAKE) --no-print-directory $(GO_LICENSE_FILE)
  400. vendor: go.mod go.sum
  401. $(GO) mod vendor
  402. @touch vendor
  403. .PHONY: tidy-check
  404. tidy-check: tidy
  405. @diff=$$(git diff --color=always go.mod go.sum $(GO_LICENSE_FILE)); \
  406. if [ -n "$$diff" ]; then \
  407. echo "Please run 'make tidy' and commit the result:"; \
  408. echo "$${diff}"; \
  409. exit 1; \
  410. fi
  411. .PHONY: go-licenses
  412. go-licenses: $(GO_LICENSE_FILE)
  413. $(GO_LICENSE_FILE): go.mod go.sum
  414. -$(GO) run $(GO_LICENSES_PACKAGE) save . --force --save_path=$(GO_LICENSE_TMP_DIR) 2>/dev/null
  415. $(GO) run build/generate-go-licenses.go $(GO_LICENSE_TMP_DIR) $(GO_LICENSE_FILE)
  416. @rm -rf $(GO_LICENSE_TMP_DIR)
  417. generate-ini-sqlite:
  418. sed -e 's|{{REPO_TEST_DIR}}|${REPO_TEST_DIR}|g' \
  419. -e 's|{{TEST_LOGGER}}|$(or $(TEST_LOGGER),test$(COMMA)file)|g' \
  420. -e 's|{{TEST_TYPE}}|$(or $(TEST_TYPE),integration)|g' \
  421. tests/sqlite.ini.tmpl > tests/sqlite.ini
  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
  425. .PHONY: test-sqlite\#%
  426. test-sqlite\#%: integrations.sqlite.test generate-ini-sqlite
  427. GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/sqlite.ini ./integrations.sqlite.test -test.run $(subst .,/,$*)
  428. .PHONY: test-sqlite-migration
  429. test-sqlite-migration: migrations.sqlite.test migrations.individual.sqlite.test
  430. generate-ini-mysql:
  431. sed -e 's|{{TEST_MYSQL_HOST}}|${TEST_MYSQL_HOST}|g' \
  432. -e 's|{{TEST_MYSQL_DBNAME}}|${TEST_MYSQL_DBNAME}|g' \
  433. -e 's|{{TEST_MYSQL_USERNAME}}|${TEST_MYSQL_USERNAME}|g' \
  434. -e 's|{{TEST_MYSQL_PASSWORD}}|${TEST_MYSQL_PASSWORD}|g' \
  435. -e 's|{{REPO_TEST_DIR}}|${REPO_TEST_DIR}|g' \
  436. -e 's|{{TEST_LOGGER}}|$(or $(TEST_LOGGER),test$(COMMA)file)|g' \
  437. -e 's|{{TEST_TYPE}}|$(or $(TEST_TYPE),integration)|g' \
  438. tests/mysql.ini.tmpl > tests/mysql.ini
  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
  442. .PHONY: test-mysql\#%
  443. test-mysql\#%: integrations.mysql.test generate-ini-mysql
  444. GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mysql.ini ./integrations.mysql.test -test.run $(subst .,/,$*)
  445. .PHONY: test-mysql-migration
  446. test-mysql-migration: migrations.mysql.test migrations.individual.mysql.test
  447. generate-ini-mysql8:
  448. sed -e 's|{{TEST_MYSQL8_HOST}}|${TEST_MYSQL8_HOST}|g' \
  449. -e 's|{{TEST_MYSQL8_DBNAME}}|${TEST_MYSQL8_DBNAME}|g' \
  450. -e 's|{{TEST_MYSQL8_USERNAME}}|${TEST_MYSQL8_USERNAME}|g' \
  451. -e 's|{{TEST_MYSQL8_PASSWORD}}|${TEST_MYSQL8_PASSWORD}|g' \
  452. -e 's|{{REPO_TEST_DIR}}|${REPO_TEST_DIR}|g' \
  453. -e 's|{{TEST_LOGGER}}|$(or $(TEST_LOGGER),test$(COMMA)file)|g' \
  454. -e 's|{{TEST_TYPE}}|$(or $(TEST_TYPE),integration)|g' \
  455. tests/mysql8.ini.tmpl > tests/mysql8.ini
  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
  459. .PHONY: test-mysql8\#%
  460. test-mysql8\#%: integrations.mysql8.test generate-ini-mysql8
  461. GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mysql8.ini ./integrations.mysql8.test -test.run $(subst .,/,$*)
  462. .PHONY: test-mysql8-migration
  463. test-mysql8-migration: migrations.mysql8.test migrations.individual.mysql8.test
  464. generate-ini-pgsql:
  465. sed -e 's|{{TEST_PGSQL_HOST}}|${TEST_PGSQL_HOST}|g' \
  466. -e 's|{{TEST_PGSQL_DBNAME}}|${TEST_PGSQL_DBNAME}|g' \
  467. -e 's|{{TEST_PGSQL_USERNAME}}|${TEST_PGSQL_USERNAME}|g' \
  468. -e 's|{{TEST_PGSQL_PASSWORD}}|${TEST_PGSQL_PASSWORD}|g' \
  469. -e 's|{{TEST_PGSQL_SCHEMA}}|${TEST_PGSQL_SCHEMA}|g' \
  470. -e 's|{{REPO_TEST_DIR}}|${REPO_TEST_DIR}|g' \
  471. -e 's|{{TEST_LOGGER}}|$(or $(TEST_LOGGER),test$(COMMA)file)|g' \
  472. -e 's|{{TEST_TYPE}}|$(or $(TEST_TYPE),integration)|g' \
  473. tests/pgsql.ini.tmpl > tests/pgsql.ini
  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
  477. .PHONY: test-pgsql\#%
  478. test-pgsql\#%: integrations.pgsql.test generate-ini-pgsql
  479. GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/pgsql.ini ./integrations.pgsql.test -test.run $(subst .,/,$*)
  480. .PHONY: test-pgsql-migration
  481. test-pgsql-migration: migrations.pgsql.test migrations.individual.pgsql.test
  482. generate-ini-mssql:
  483. sed -e 's|{{TEST_MSSQL_HOST}}|${TEST_MSSQL_HOST}|g' \
  484. -e 's|{{TEST_MSSQL_DBNAME}}|${TEST_MSSQL_DBNAME}|g' \
  485. -e 's|{{TEST_MSSQL_USERNAME}}|${TEST_MSSQL_USERNAME}|g' \
  486. -e 's|{{TEST_MSSQL_PASSWORD}}|${TEST_MSSQL_PASSWORD}|g' \
  487. -e 's|{{REPO_TEST_DIR}}|${REPO_TEST_DIR}|g' \
  488. -e 's|{{TEST_LOGGER}}|$(or $(TEST_LOGGER),test$(COMMA)file)|g' \
  489. -e 's|{{TEST_TYPE}}|$(or $(TEST_TYPE),integration)|g' \
  490. tests/mssql.ini.tmpl > tests/mssql.ini
  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
  494. .PHONY: test-mssql\#%
  495. test-mssql\#%: integrations.mssql.test generate-ini-mssql
  496. GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mssql.ini ./integrations.mssql.test -test.run $(subst .,/,$*)
  497. .PHONY: test-mssql-migration
  498. test-mssql-migration: migrations.mssql.test migrations.individual.mssql.test
  499. .PHONY: playwright
  500. playwright: $(PLAYWRIGHT_DIR)
  501. npm install --no-save @playwright/test
  502. npx playwright install $(PLAYWRIGHT_FLAGS)
  503. .PHONY: test-e2e%
  504. test-e2e%: TEST_TYPE ?= e2e
  505. # Clear display env variable. Otherwise, chromium tests can fail.
  506. DISPLAY=
  507. .PHONY: test-e2e
  508. test-e2e: test-e2e-sqlite
  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
  512. .PHONY: test-e2e-sqlite\#%
  513. test-e2e-sqlite\#%: playwright e2e.sqlite.test generate-ini-sqlite
  514. GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/sqlite.ini ./e2e.sqlite.test -test.run TestE2e/$*
  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
  518. .PHONY: test-e2e-mysql\#%
  519. test-e2e-mysql\#%: playwright e2e.mysql.test generate-ini-mysql
  520. GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mysql.ini ./e2e.mysql.test -test.run TestE2e/$*
  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
  524. .PHONY: test-e2e-mysql8\#%
  525. test-e2e-mysql8\#%: playwright e2e.mysql8.test generate-ini-mysql8
  526. GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mysql8.ini ./e2e.mysql8.test -test.run TestE2e/$*
  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
  530. .PHONY: test-e2e-pgsql\#%
  531. test-e2e-pgsql\#%: playwright e2e.pgsql.test generate-ini-pgsql
  532. GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/pgsql.ini ./e2e.pgsql.test -test.run TestE2e/$*
  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
  536. .PHONY: test-e2e-mssql\#%
  537. test-e2e-mssql\#%: playwright e2e.mssql.test generate-ini-mssql
  538. GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mssql.ini ./e2e.mssql.test -test.run TestE2e/$*
  539. .PHONY: bench-sqlite
  540. bench-sqlite: integrations.sqlite.test generate-ini-sqlite
  541. GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/sqlite.ini ./integrations.sqlite.test -test.cpuprofile=cpu.out -test.run DontRunTests -test.bench .
  542. .PHONY: bench-mysql
  543. bench-mysql: integrations.mysql.test generate-ini-mysql
  544. GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mysql.ini ./integrations.mysql.test -test.cpuprofile=cpu.out -test.run DontRunTests -test.bench .
  545. .PHONY: bench-mssql
  546. bench-mssql: integrations.mssql.test generate-ini-mssql
  547. GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mssql.ini ./integrations.mssql.test -test.cpuprofile=cpu.out -test.run DontRunTests -test.bench .
  548. .PHONY: bench-pgsql
  549. bench-pgsql: integrations.pgsql.test generate-ini-pgsql
  550. GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/pgsql.ini ./integrations.pgsql.test -test.cpuprofile=cpu.out -test.run DontRunTests -test.bench .
  551. .PHONY: integration-test-coverage
  552. integration-test-coverage: integrations.cover.test generate-ini-mysql
  553. GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mysql.ini ./integrations.cover.test -test.coverprofile=integration.coverage.out
  554. .PHONY: integration-test-coverage-sqlite
  555. integration-test-coverage-sqlite: integrations.cover.sqlite.test generate-ini-sqlite
  556. GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/sqlite.ini ./integrations.cover.sqlite.test -test.coverprofile=integration.coverage.out
  557. integrations.mysql.test: git-check $(GO_SOURCES)
  558. $(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/tests/integration -o integrations.mysql.test
  559. integrations.mysql8.test: git-check $(GO_SOURCES)
  560. $(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/tests/integration -o integrations.mysql8.test
  561. integrations.pgsql.test: git-check $(GO_SOURCES)
  562. $(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/tests/integration -o integrations.pgsql.test
  563. integrations.mssql.test: git-check $(GO_SOURCES)
  564. $(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/tests/integration -o integrations.mssql.test
  565. integrations.sqlite.test: git-check $(GO_SOURCES)
  566. $(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/tests/integration -o integrations.sqlite.test -tags '$(TEST_TAGS)'
  567. integrations.cover.test: git-check $(GO_SOURCES)
  568. $(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/tests/integration -coverpkg $(shell echo $(GO_TEST_PACKAGES) | tr ' ' ',') -o integrations.cover.test
  569. integrations.cover.sqlite.test: git-check $(GO_SOURCES)
  570. $(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)'
  571. .PHONY: migrations.mysql.test
  572. migrations.mysql.test: $(GO_SOURCES) generate-ini-mysql
  573. $(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/tests/integration/migration-test -o migrations.mysql.test
  574. GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mysql.ini ./migrations.mysql.test
  575. .PHONY: migrations.mysql8.test
  576. migrations.mysql8.test: $(GO_SOURCES) generate-ini-mysql8
  577. $(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/tests/integration/migration-test -o migrations.mysql8.test
  578. GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mysql8.ini ./migrations.mysql8.test
  579. .PHONY: migrations.pgsql.test
  580. migrations.pgsql.test: $(GO_SOURCES) generate-ini-pgsql
  581. $(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/tests/integration/migration-test -o migrations.pgsql.test
  582. GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/pgsql.ini ./migrations.pgsql.test
  583. .PHONY: migrations.mssql.test
  584. migrations.mssql.test: $(GO_SOURCES) generate-ini-mssql
  585. $(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/tests/integration/migration-test -o migrations.mssql.test
  586. GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mssql.ini ./migrations.mssql.test
  587. .PHONY: migrations.sqlite.test
  588. migrations.sqlite.test: $(GO_SOURCES) generate-ini-sqlite
  589. $(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/tests/integration/migration-test -o migrations.sqlite.test -tags '$(TEST_TAGS)'
  590. GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/sqlite.ini ./migrations.sqlite.test
  591. .PHONY: migrations.individual.mysql.test
  592. migrations.individual.mysql.test: $(GO_SOURCES)
  593. for pkg in $(shell $(GO) list code.gitea.io/gitea/models/migrations/...); do \
  594. GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mysql.ini $(GO) test $(GOTESTFLAGS) -tags '$(TEST_TAGS)' $$pkg; \
  595. done
  596. .PHONY: migrations.individual.mysql8.test
  597. migrations.individual.mysql8.test: $(GO_SOURCES)
  598. for pkg in $(shell $(GO) list code.gitea.io/gitea/models/migrations/...); do \
  599. GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mysql8.ini $(GO) test $(GOTESTFLAGS) -tags '$(TEST_TAGS)' $$pkg; \
  600. done
  601. .PHONY: migrations.individual.mysql8.test\#%
  602. migrations.individual.sqlite.test\#%: $(GO_SOURCES) generate-ini-sqlite
  603. GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/sqlite.ini $(GO) test $(GOTESTFLAGS) -tags '$(TEST_TAGS)' code.gitea.io/gitea/models/migrations/$*
  604. .PHONY: migrations.individual.pgsql.test
  605. migrations.individual.pgsql.test: $(GO_SOURCES)
  606. for pkg in $(shell $(GO) list code.gitea.io/gitea/models/migrations/...); do \
  607. GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/pgsql.ini $(GO) test $(GOTESTFLAGS) -tags '$(TEST_TAGS)' $$pkg; \
  608. done
  609. .PHONY: migrations.individual.pgsql.test\#%
  610. migrations.individual.pgsql.test\#%: $(GO_SOURCES) generate-ini-pgsql
  611. GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/pgsql.ini $(GO) test $(GOTESTFLAGS) -tags '$(TEST_TAGS)' code.gitea.io/gitea/models/migrations/$*
  612. .PHONY: migrations.individual.mssql.test
  613. migrations.individual.mssql.test: $(GO_SOURCES) generate-ini-mssql
  614. for pkg in $(shell $(GO) list code.gitea.io/gitea/models/migrations/...); do \
  615. GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mssql.ini $(GO) test $(GOTESTFLAGS) -tags '$(TEST_TAGS)' $$pkg -test.failfast; \
  616. done
  617. .PHONY: migrations.individual.mssql.test\#%
  618. migrations.individual.mssql.test\#%: $(GO_SOURCES) generate-ini-mssql
  619. GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mssql.ini $(GO) test $(GOTESTFLAGS) -tags '$(TEST_TAGS)' code.gitea.io/gitea/models/migrations/$*
  620. .PHONY: migrations.individual.sqlite.test
  621. migrations.individual.sqlite.test: $(GO_SOURCES) generate-ini-sqlite
  622. for pkg in $(shell $(GO) list code.gitea.io/gitea/models/migrations/...); do \
  623. GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/sqlite.ini $(GO) test $(GOTESTFLAGS) -tags '$(TEST_TAGS)' $$pkg; \
  624. done
  625. .PHONY: migrations.individual.sqlite.test\#%
  626. migrations.individual.sqlite.test\#%: $(GO_SOURCES) generate-ini-sqlite
  627. GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/sqlite.ini $(GO) test $(GOTESTFLAGS) -tags '$(TEST_TAGS)' code.gitea.io/gitea/models/migrations/$*
  628. e2e.mysql.test: $(GO_SOURCES)
  629. $(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/tests/e2e -o e2e.mysql.test
  630. e2e.mysql8.test: $(GO_SOURCES)
  631. $(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/tests/e2e -o e2e.mysql8.test
  632. e2e.pgsql.test: $(GO_SOURCES)
  633. $(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/tests/e2e -o e2e.pgsql.test
  634. e2e.mssql.test: $(GO_SOURCES)
  635. $(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/tests/e2e -o e2e.mssql.test
  636. e2e.sqlite.test: $(GO_SOURCES)
  637. $(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/tests/e2e -o e2e.sqlite.test -tags '$(TEST_TAGS)'
  638. .PHONY: check
  639. check: test
  640. .PHONY: install $(TAGS_PREREQ)
  641. install: $(wildcard *.go)
  642. CGO_CFLAGS="$(CGO_CFLAGS)" $(GO) install -v -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)'
  643. .PHONY: build
  644. build: frontend backend
  645. .PHONY: frontend
  646. frontend: $(WEBPACK_DEST)
  647. .PHONY: backend
  648. backend: go-check generate-backend $(EXECUTABLE)
  649. # 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
  650. .PHONY: generate
  651. generate: generate-backend
  652. .PHONY: generate-backend
  653. generate-backend: $(TAGS_PREREQ) generate-go
  654. .PHONY: generate-go
  655. generate-go: $(TAGS_PREREQ)
  656. @echo "Running go generate..."
  657. @CC= GOOS= GOARCH= $(GO) generate -tags '$(TAGS)' $(GO_PACKAGES)
  658. .PHONY: security-check
  659. security-check:
  660. go run $(GOVULNCHECK_PACKAGE) ./...
  661. $(EXECUTABLE): $(GO_SOURCES) $(TAGS_PREREQ)
  662. CGO_CFLAGS="$(CGO_CFLAGS)" $(GO) build $(GOFLAGS) $(EXTRA_GOFLAGS) -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)' -o $@
  663. .PHONY: release
  664. release: frontend generate release-windows release-linux release-darwin release-freebsd release-copy release-compress vendor release-sources release-docs release-check
  665. $(DIST_DIRS):
  666. mkdir -p $(DIST_DIRS)
  667. .PHONY: release-windows
  668. release-windows: | $(DIST_DIRS)
  669. 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) .
  670. ifeq (,$(findstring gogit,$(TAGS)))
  671. 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 .
  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. .PHONY: release-darwin
  677. release-darwin: | $(DIST_DIRS)
  678. 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) .
  679. .PHONY: release-freebsd
  680. release-freebsd: | $(DIST_DIRS)
  681. 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) .
  682. .PHONY: release-copy
  683. release-copy: | $(DIST_DIRS)
  684. cd $(DIST); for file in `find . -type f -name "*"`; do cp $${file} ./release/; done;
  685. .PHONY: release-check
  686. release-check: | $(DIST_DIRS)
  687. cd $(DIST)/release/; for file in `find . -type f -name "*"`; do echo "checksumming $${file}" && $(SHASUM) `echo $${file} | sed 's/^..//'` > $${file}.sha256; done;
  688. .PHONY: release-compress
  689. release-compress: | $(DIST_DIRS)
  690. cd $(DIST)/release/; for file in `find . -type f -name "*"`; do echo "compressing $${file}" && $(GO) run $(GXZ_PAGAGE) -k -9 $${file}; done;
  691. .PHONY: release-sources
  692. release-sources: | $(DIST_DIRS)
  693. echo $(VERSION) > $(STORED_VERSION_FILE)
  694. # bsdtar needs a ^ to prevent matching subdirectories
  695. $(eval EXCL := --exclude=$(shell tar --help | grep -q bsdtar && echo "^")./)
  696. # use transform to a add a release-folder prefix; in bsdtar the transform parameter equivalent is -s
  697. $(eval TRANSFORM := $(shell tar --help | grep -q bsdtar && echo "-s '/^./gitea-src-$(VERSION)/'" || echo "--transform 's|^./|gitea-src-$(VERSION)/|'"))
  698. tar $(addprefix $(EXCL),$(TAR_EXCLUDES)) $(TRANSFORM) -czf $(DIST)/release/gitea-src-$(VERSION).tar.gz .
  699. rm -f $(STORED_VERSION_FILE)
  700. .PHONY: release-docs
  701. release-docs: | $(DIST_DIRS) docs
  702. tar -czf $(DIST)/release/gitea-docs-$(VERSION).tar.gz -C ./docs/public .
  703. .PHONY: docs
  704. docs: deps-docs
  705. cd docs; make trans-copy clean build-offline;
  706. .PHONY: deps-docs
  707. deps-docs:
  708. @hash hugo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  709. curl -sL https://github.com/gohugoio/hugo/releases/download/v$(HUGO_VERSION)/hugo_$(HUGO_VERSION)_Linux-64bit.tar.gz | tar zxf - -C /tmp && mkdir -p ~/go/bin && mv /tmp/hugo ~/go/bin/hugo && chmod +x ~/go/bin/hugo; \
  710. fi
  711. .PHONY: deps
  712. deps: deps-frontend deps-backend deps-tools deps-docs deps-py
  713. .PHONY: deps-py
  714. deps-py: .venv
  715. .PHONY: deps-frontend
  716. deps-frontend: node_modules
  717. .PHONY: deps-backend
  718. deps-backend:
  719. $(GO) mod download
  720. .PHONY: deps-tools
  721. deps-tools:
  722. $(GO) install $(AIR_PACKAGE)
  723. $(GO) install $(EDITORCONFIG_CHECKER_PACKAGE)
  724. $(GO) install $(GOFUMPT_PACKAGE)
  725. $(GO) install $(GOLANGCI_LINT_PACKAGE)
  726. $(GO) install $(GXZ_PAGAGE)
  727. $(GO) install $(MISSPELL_PACKAGE)
  728. $(GO) install $(SWAGGER_PACKAGE)
  729. $(GO) install $(XGO_PACKAGE)
  730. $(GO) install $(GO_LICENSES_PACKAGE)
  731. $(GO) install $(GOVULNCHECK_PACKAGE)
  732. $(GO) install $(ACTIONLINT_PACKAGE)
  733. node_modules: package-lock.json
  734. npm install --no-save
  735. @touch node_modules
  736. .venv: poetry.lock
  737. poetry install
  738. @touch .venv
  739. .PHONY: update-js
  740. update-js: node-check | node_modules
  741. npx updates -u -f package.json
  742. rm -rf node_modules package-lock.json
  743. npm install --package-lock
  744. @touch node_modules
  745. .PHONY: update-py
  746. update-py: node-check | node_modules
  747. npx updates -u -f pyproject.toml
  748. rm -rf .venv poetry.lock
  749. poetry install
  750. @touch .venv
  751. .PHONY: fomantic
  752. fomantic:
  753. rm -rf $(FOMANTIC_WORK_DIR)/build
  754. cd $(FOMANTIC_WORK_DIR) && npm install --no-save
  755. cp -f $(FOMANTIC_WORK_DIR)/theme.config.less $(FOMANTIC_WORK_DIR)/node_modules/fomantic-ui/src/theme.config
  756. cp -rf $(FOMANTIC_WORK_DIR)/_site $(FOMANTIC_WORK_DIR)/node_modules/fomantic-ui/src/
  757. cd $(FOMANTIC_WORK_DIR) && npx gulp -f node_modules/fomantic-ui/gulpfile.js build
  758. # fomantic uses "touchstart" as click event for some browsers, it's not ideal, so we force fomantic to always use "click" as click event
  759. $(SED_INPLACE) -e 's/clickEvent[ \t]*=/clickEvent = "click", unstableClickEvent =/g' $(FOMANTIC_WORK_DIR)/build/semantic.js
  760. $(SED_INPLACE) -e 's/\r//g' $(FOMANTIC_WORK_DIR)/build/semantic.css $(FOMANTIC_WORK_DIR)/build/semantic.js
  761. rm -f $(FOMANTIC_WORK_DIR)/build/*.min.*
  762. .PHONY: webpack
  763. webpack: $(WEBPACK_DEST)
  764. $(WEBPACK_DEST): $(WEBPACK_SOURCES) $(WEBPACK_CONFIGS) package-lock.json
  765. @$(MAKE) -s node-check node_modules
  766. rm -rf $(WEBPACK_DEST_ENTRIES)
  767. npx webpack
  768. @touch $(WEBPACK_DEST)
  769. .PHONY: svg
  770. svg: node-check | node_modules
  771. rm -rf $(SVG_DEST_DIR)
  772. node build/generate-svg.js
  773. .PHONY: svg-check
  774. svg-check: svg
  775. @git add $(SVG_DEST_DIR)
  776. @diff=$$(git diff --color=always --cached $(SVG_DEST_DIR)); \
  777. if [ -n "$$diff" ]; then \
  778. echo "Please run 'make svg' and 'git add $(SVG_DEST_DIR)' and commit the result:"; \
  779. echo "$${diff}"; \
  780. exit 1; \
  781. fi
  782. .PHONY: lockfile-check
  783. lockfile-check:
  784. npm install --package-lock-only
  785. @diff=$$(git diff --color=always package-lock.json); \
  786. if [ -n "$$diff" ]; then \
  787. echo "package-lock.json is inconsistent with package.json"; \
  788. echo "Please run 'npm install --package-lock-only' and commit the result:"; \
  789. echo "$${diff}"; \
  790. exit 1; \
  791. fi
  792. .PHONY: update-translations
  793. update-translations:
  794. mkdir -p ./translations
  795. cd ./translations && curl -L https://crowdin.com/download/project/gitea.zip > gitea.zip && unzip gitea.zip
  796. rm ./translations/gitea.zip
  797. $(SED_INPLACE) -e 's/="/=/g' -e 's/"$$//g' ./translations/*.ini
  798. $(SED_INPLACE) -e 's/\\"/"/g' ./translations/*.ini
  799. mv ./translations/*.ini ./options/locale/
  800. rmdir ./translations
  801. .PHONY: generate-license
  802. generate-license:
  803. $(GO) run build/generate-licenses.go
  804. .PHONY: generate-gitignore
  805. generate-gitignore:
  806. $(GO) run build/generate-gitignores.go
  807. .PHONY: generate-images
  808. generate-images: | node_modules
  809. npm install --no-save --no-package-lock fabric@5 imagemin-zopfli@7
  810. node build/generate-images.js $(TAGS)
  811. .PHONY: generate-manpage
  812. generate-manpage:
  813. @[ -f gitea ] || make backend
  814. @mkdir -p man/man1/ man/man5
  815. @./gitea docs --man > man/man1/gitea.1
  816. @gzip -9 man/man1/gitea.1 && echo man/man1/gitea.1.gz created
  817. @#TODO A small script that formats config-cheat-sheet.en-us.md nicely for use as a config man page
  818. .PHONY: docker
  819. docker:
  820. docker build --disable-content-trust=false -t $(DOCKER_REF) .
  821. # support also build args docker build --build-arg GITEA_VERSION=v1.2.3 --build-arg TAGS="bindata sqlite sqlite_unlock_notify" .
  822. # This endif closes the if at the top of the file
  823. endif