Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

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