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

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