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

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