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 39KB

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