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

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