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

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