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

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