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

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