選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

Makefile 40KB

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