gitea源码

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