gitea

Зеркало из https://github.com/go-gitea/gitea
Форк
0
/
Makefile 
995 строк · 38.0 Кб
1
ifeq ($(USE_REPO_TEST_DIR),1)
2

3
# This rule replaces the whole Makefile when we're trying to use /tmp repository temporary files
4
location = $(CURDIR)/$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
5
self := $(location)
6

7
%:
8
	@tmpdir=`mktemp --tmpdir -d` ; \
9
	echo Using temporary directory $$tmpdir for test repositories ; \
10
	USE_REPO_TEST_DIR= $(MAKE) -f $(self) --no-print-directory REPO_TEST_DIR=$$tmpdir/ $@ ; \
11
	STATUS=$$? ; rm -r "$$tmpdir" ; exit $$STATUS
12

13
else
14

15
# This is the "normal" part of the Makefile
16

17
DIST := dist
18
DIST_DIRS := $(DIST)/binaries $(DIST)/release
19
IMPORT := code.gitea.io/gitea
20

21
GO ?= go
22
SHASUM ?= shasum -a 256
23
HAS_GO := $(shell hash $(GO) > /dev/null 2>&1 && echo yes)
24
COMMA := ,
25

26
XGO_VERSION := go-1.23.x
27

28
AIR_PACKAGE ?= github.com/air-verse/air@v1
29
EDITORCONFIG_CHECKER_PACKAGE ?= github.com/editorconfig-checker/editorconfig-checker/cmd/editorconfig-checker@2.7.0
30
GOFUMPT_PACKAGE ?= mvdan.cc/gofumpt@v0.7.0
31
GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/cmd/golangci-lint@v1.60.3
32
GXZ_PACKAGE ?= github.com/ulikunitz/xz/cmd/gxz@v0.5.11
33
MISSPELL_PACKAGE ?= github.com/golangci/misspell/cmd/misspell@v0.5.1
34
SWAGGER_PACKAGE ?= github.com/go-swagger/go-swagger/cmd/swagger@v0.31.0
35
XGO_PACKAGE ?= src.techknowlogick.com/xgo@latest
36
GO_LICENSES_PACKAGE ?= github.com/google/go-licenses@v1
37
GOVULNCHECK_PACKAGE ?= golang.org/x/vuln/cmd/govulncheck@v1
38
ACTIONLINT_PACKAGE ?= github.com/rhysd/actionlint/cmd/actionlint@v1
39
GOPLS_PACKAGE ?= golang.org/x/tools/gopls@v0.15.3
40

41
DOCKER_IMAGE ?= gitea/gitea
42
DOCKER_TAG ?= latest
43
DOCKER_REF := $(DOCKER_IMAGE):$(DOCKER_TAG)
44

45
ifeq ($(HAS_GO), yes)
46
	CGO_EXTRA_CFLAGS := -DSQLITE_MAX_VARIABLE_NUMBER=32766
47
	CGO_CFLAGS ?= $(shell $(GO) env CGO_CFLAGS) $(CGO_EXTRA_CFLAGS)
48
endif
49

50
ifeq ($(GOOS),windows)
51
	IS_WINDOWS := yes
52
else ifeq ($(patsubst Windows%,Windows,$(OS)),Windows)
53
	ifeq ($(GOOS),)
54
		IS_WINDOWS := yes
55
	endif
56
endif
57
ifeq ($(IS_WINDOWS),yes)
58
	GOFLAGS := -v -buildmode=exe
59
	EXECUTABLE ?= gitea.exe
60
else
61
	GOFLAGS := -v
62
	EXECUTABLE ?= gitea
63
endif
64

65
ifeq ($(shell sed --version 2>/dev/null | grep -q GNU && echo gnu),gnu)
66
	SED_INPLACE := sed -i
67
else
68
	SED_INPLACE := sed -i ''
69
endif
70

71
EXTRA_GOFLAGS ?=
72

73
MAKE_VERSION := $(shell "$(MAKE)" -v | cat | head -n 1)
74
MAKE_EVIDENCE_DIR := .make_evidence
75

76
ifeq ($(RACE_ENABLED),true)
77
	GOFLAGS += -race
78
	GOTESTFLAGS += -race
79
endif
80

81
STORED_VERSION_FILE := VERSION
82
HUGO_VERSION ?= 0.111.3
83

84
GITHUB_REF_TYPE ?= branch
85
GITHUB_REF_NAME ?= $(shell git rev-parse --abbrev-ref HEAD)
86

87
ifneq ($(GITHUB_REF_TYPE),branch)
88
	VERSION ?= $(subst v,,$(GITHUB_REF_NAME))
89
	GITEA_VERSION ?= $(VERSION)
90
else
91
	ifneq ($(GITHUB_REF_NAME),)
92
		VERSION ?= $(subst release/v,,$(GITHUB_REF_NAME))-nightly
93
	else
94
		VERSION ?= main
95
	endif
96

97
	STORED_VERSION=$(shell cat $(STORED_VERSION_FILE) 2>/dev/null)
98
	ifneq ($(STORED_VERSION),)
99
		GITEA_VERSION ?= $(STORED_VERSION)
100
	else
101
		GITEA_VERSION ?= $(shell git describe --tags --always | sed 's/-/+/' | sed 's/^v//')
102
	endif
103
endif
104

105
# if version = "main" then update version to "nightly"
106
ifeq ($(VERSION),main)
107
	VERSION := main-nightly
108
endif
109

110
LDFLAGS := $(LDFLAGS) -X "main.MakeVersion=$(MAKE_VERSION)" -X "main.Version=$(GITEA_VERSION)" -X "main.Tags=$(TAGS)"
111

112
LINUX_ARCHS ?= linux/amd64,linux/386,linux/arm-5,linux/arm-6,linux/arm64
113

114
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/))
115
MIGRATE_TEST_PACKAGES ?= $(shell $(GO) list code.gitea.io/gitea/models/migrations/...)
116

117
FOMANTIC_WORK_DIR := web_src/fomantic
118

119
WEBPACK_SOURCES := $(shell find web_src/js web_src/css -type f)
120
WEBPACK_CONFIGS := webpack.config.js tailwind.config.js
121
WEBPACK_DEST := public/assets/js/index.js public/assets/css/index.css
122
WEBPACK_DEST_ENTRIES := public/assets/js public/assets/css public/assets/fonts
123

124
BINDATA_DEST := modules/public/bindata.go modules/options/bindata.go modules/templates/bindata.go
125
BINDATA_HASH := $(addsuffix .hash,$(BINDATA_DEST))
126

127
GENERATED_GO_DEST := modules/charset/invisible_gen.go modules/charset/ambiguous_gen.go
128

129
SVG_DEST_DIR := public/assets/img/svg
130

131
AIR_TMP_DIR := .air
132

133
GO_LICENSE_TMP_DIR := .go-licenses
134
GO_LICENSE_FILE := assets/go-licenses.json
135

136
TAGS ?=
137
TAGS_SPLIT := $(subst $(COMMA), ,$(TAGS))
138
TAGS_EVIDENCE := $(MAKE_EVIDENCE_DIR)/tags
139

140
TEST_TAGS ?= $(TAGS_SPLIT) sqlite sqlite_unlock_notify
141

142
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)
143

144
GO_DIRS := build cmd models modules routers services tests
145
WEB_DIRS := web_src/js web_src/css
146

147
ESLINT_FILES := web_src/js tools *.js *.ts tests/e2e
148
STYLELINT_FILES := web_src/css web_src/js/components/*.vue
149
SPELLCHECK_FILES := $(GO_DIRS) $(WEB_DIRS) templates options/locale/locale_en-US.ini .github $(filter-out CHANGELOG.md, $(wildcard *.go *.js *.md *.yml *.yaml *.toml))
150
EDITORCONFIG_FILES := templates .github/workflows options/locale/locale_en-US.ini
151

152
GO_SOURCES := $(wildcard *.go)
153
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)
154
GO_SOURCES += $(GENERATED_GO_DEST)
155
GO_SOURCES_NO_BINDATA := $(GO_SOURCES)
156

157
ifeq ($(filter $(TAGS_SPLIT),bindata),bindata)
158
	GO_SOURCES += $(BINDATA_DEST)
159
	GENERATED_GO_DEST += $(BINDATA_DEST)
160
endif
161

162
# Force installation of playwright dependencies by setting this flag
163
ifdef DEPS_PLAYWRIGHT
164
	PLAYWRIGHT_FLAGS += --with-deps
165
endif
166

167
SWAGGER_SPEC := templates/swagger/v1_json.tmpl
168
SWAGGER_SPEC_S_TMPL := s|"basePath": *"/api/v1"|"basePath": "{{AppSubUrl \| JSEscape}}/api/v1"|g
169
SWAGGER_SPEC_S_JSON := s|"basePath": *"{{AppSubUrl \| JSEscape}}/api/v1"|"basePath": "/api/v1"|g
170
SWAGGER_EXCLUDE := code.gitea.io/sdk
171
SWAGGER_NEWLINE_COMMAND := -e '$$a\'
172

173
TEST_MYSQL_HOST ?= mysql:3306
174
TEST_MYSQL_DBNAME ?= testgitea
175
TEST_MYSQL_USERNAME ?= root
176
TEST_MYSQL_PASSWORD ?=
177
TEST_PGSQL_HOST ?= pgsql:5432
178
TEST_PGSQL_DBNAME ?= testgitea
179
TEST_PGSQL_USERNAME ?= postgres
180
TEST_PGSQL_PASSWORD ?= postgres
181
TEST_PGSQL_SCHEMA ?= gtestschema
182
TEST_MINIO_ENDPOINT ?= minio:9000
183
TEST_MSSQL_HOST ?= mssql:1433
184
TEST_MSSQL_DBNAME ?= gitea
185
TEST_MSSQL_USERNAME ?= sa
186
TEST_MSSQL_PASSWORD ?= MwantsaSecurePassword1
187

188
.PHONY: all
189
all: build
190

191
.PHONY: help
192
help:
193
	@echo "Make Routines:"
194
	@echo " - \"\"                               equivalent to \"build\""
195
	@echo " - build                            build everything"
196
	@echo " - frontend                         build frontend files"
197
	@echo " - backend                          build backend files"
198
	@echo " - watch                            watch everything and continuously rebuild"
199
	@echo " - watch-frontend                   watch frontend files and continuously rebuild"
200
	@echo " - watch-backend                    watch backend files and continuously rebuild"
201
	@echo " - clean                            delete backend and integration files"
202
	@echo " - clean-all                        delete backend, frontend and integration files"
203
	@echo " - deps                             install dependencies"
204
	@echo " - deps-frontend                    install frontend dependencies"
205
	@echo " - deps-backend                     install backend dependencies"
206
	@echo " - deps-tools                       install tool dependencies"
207
	@echo " - deps-py                          install python dependencies"
208
	@echo " - lint                             lint everything"
209
	@echo " - lint-fix                         lint everything and fix issues"
210
	@echo " - lint-actions                     lint action workflow files"
211
	@echo " - lint-frontend                    lint frontend files"
212
	@echo " - lint-frontend-fix                lint frontend files and fix issues"
213
	@echo " - lint-backend                     lint backend files"
214
	@echo " - lint-backend-fix                 lint backend files and fix issues"
215
	@echo " - lint-go                          lint go files"
216
	@echo " - lint-go-fix                      lint go files and fix issues"
217
	@echo " - lint-go-vet                      lint go files with vet"
218
	@echo " - lint-go-gopls                    lint go files with gopls"
219
	@echo " - lint-js                          lint js files"
220
	@echo " - lint-js-fix                      lint js files and fix issues"
221
	@echo " - lint-css                         lint css files"
222
	@echo " - lint-css-fix                     lint css files and fix issues"
223
	@echo " - lint-md                          lint markdown files"
224
	@echo " - lint-swagger                     lint swagger files"
225
	@echo " - lint-templates                   lint template files"
226
	@echo " - lint-yaml                        lint yaml files"
227
	@echo " - lint-spell                       lint spelling"
228
	@echo " - lint-spell-fix                   lint spelling and fix issues"
229
	@echo " - checks                           run various consistency checks"
230
	@echo " - checks-frontend                  check frontend files"
231
	@echo " - checks-backend                   check backend files"
232
	@echo " - test                             test everything"
233
	@echo " - test-frontend                    test frontend files"
234
	@echo " - test-backend                     test backend files"
235
	@echo " - test-e2e[\#TestSpecificName]     test end to end using playwright"
236
	@echo " - update                           update js and py dependencies"
237
	@echo " - update-js                        update js dependencies"
238
	@echo " - update-py                        update py dependencies"
239
	@echo " - webpack                          build webpack files"
240
	@echo " - svg                              build svg files"
241
	@echo " - fomantic                         build fomantic files"
242
	@echo " - generate                         run \"go generate\""
243
	@echo " - fmt                              format the Go code"
244
	@echo " - generate-license                 update license files"
245
	@echo " - generate-gitignore               update gitignore files"
246
	@echo " - generate-manpage                 generate manpage"
247
	@echo " - generate-swagger                 generate the swagger spec from code comments"
248
	@echo " - swagger-validate                 check if the swagger spec is valid"
249
	@echo " - go-licenses                      regenerate go licenses"
250
	@echo " - tidy                             run go mod tidy"
251
	@echo " - test[\#TestSpecificName]    	    run unit test"
252
	@echo " - test-sqlite[\#TestSpecificName]  run integration test for sqlite"
253

254
.PHONY: go-check
255
go-check:
256
	$(eval MIN_GO_VERSION_STR := $(shell grep -Eo '^go\s+[0-9]+\.[0-9]+' go.mod | cut -d' ' -f2))
257
	$(eval MIN_GO_VERSION := $(shell printf "%03d%03d" $(shell echo '$(MIN_GO_VERSION_STR)' | tr '.' ' ')))
258
	$(eval GO_VERSION := $(shell printf "%03d%03d" $(shell $(GO) version | grep -Eo '[0-9]+\.[0-9]+' | tr '.' ' ');))
259
	@if [ "$(GO_VERSION)" -lt "$(MIN_GO_VERSION)" ]; then \
260
		echo "Gitea requires Go $(MIN_GO_VERSION_STR) or greater to build. You can get it at https://go.dev/dl/"; \
261
		exit 1; \
262
	fi
263

264
.PHONY: git-check
265
git-check:
266
	@if git lfs >/dev/null 2>&1 ; then : ; else \
267
		echo "Gitea requires git with lfs support to run tests." ; \
268
		exit 1; \
269
	fi
270

271
.PHONY: node-check
272
node-check:
273
	$(eval MIN_NODE_VERSION_STR := $(shell grep -Eo '"node":.*[0-9.]+"' package.json | sed -n 's/.*[^0-9.]\([0-9.]*\)"/\1/p'))
274
	$(eval MIN_NODE_VERSION := $(shell printf "%03d%03d%03d" $(shell echo '$(MIN_NODE_VERSION_STR)' | tr '.' ' ')))
275
	$(eval NODE_VERSION := $(shell printf "%03d%03d%03d" $(shell node -v | cut -c2- | tr '.' ' ');))
276
	$(eval NPM_MISSING := $(shell hash npm > /dev/null 2>&1 || echo 1))
277
	@if [ "$(NODE_VERSION)" -lt "$(MIN_NODE_VERSION)" -o "$(NPM_MISSING)" = "1" ]; then \
278
		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/"; \
279
		exit 1; \
280
	fi
281

282
.PHONY: clean-all
283
clean-all: clean
284
	rm -rf $(WEBPACK_DEST_ENTRIES) node_modules
285

286
.PHONY: clean
287
clean:
288
	rm -rf $(EXECUTABLE) $(DIST) $(BINDATA_DEST) $(BINDATA_HASH) \
289
		integrations*.test \
290
		e2e*.test \
291
		tests/integration/gitea-integration-* \
292
		tests/integration/indexers-* \
293
		tests/mysql.ini tests/pgsql.ini tests/mssql.ini man/ \
294
		tests/e2e/gitea-e2e-*/ \
295
		tests/e2e/indexers-*/ \
296
		tests/e2e/reports/ tests/e2e/test-artifacts/ tests/e2e/test-snapshots/
297

298
.PHONY: fmt
299
fmt:
300
	@GOFUMPT_PACKAGE=$(GOFUMPT_PACKAGE) $(GO) run build/code-batch-process.go gitea-fmt -w '{file-list}'
301
	$(eval TEMPLATES := $(shell find templates -type f -name '*.tmpl'))
302
	@# strip whitespace after '{{' or '(' and before '}}' or ')' unless there is only
303
	@# whitespace before it
304
	@$(SED_INPLACE) \
305
		-e 's/{{[ 	]\{1,\}/{{/g' -e '/^[ 	]\{1,\}}}/! s/[ 	]\{1,\}}}/}}/g' \
306
	  -e 's/([ 	]\{1,\}/(/g' -e '/^[ 	]\{1,\})/! s/[ 	]\{1,\})/)/g' \
307
	  $(TEMPLATES)
308

309
.PHONY: fmt-check
310
fmt-check: fmt
311
	@diff=$$(git diff --color=always $(GO_SOURCES) templates $(WEB_DIRS)); \
312
	if [ -n "$$diff" ]; then \
313
	  echo "Please run 'make fmt' and commit the result:"; \
314
	  echo "$${diff}"; \
315
	  exit 1; \
316
	fi
317

318
.PHONY: $(TAGS_EVIDENCE)
319
$(TAGS_EVIDENCE):
320
	@mkdir -p $(MAKE_EVIDENCE_DIR)
321
	@echo "$(TAGS)" > $(TAGS_EVIDENCE)
322

323
ifneq "$(TAGS)" "$(shell cat $(TAGS_EVIDENCE) 2>/dev/null)"
324
TAGS_PREREQ := $(TAGS_EVIDENCE)
325
endif
326

327
.PHONY: generate-swagger
328
generate-swagger: $(SWAGGER_SPEC)
329

330
$(SWAGGER_SPEC): $(GO_SOURCES_NO_BINDATA)
331
	$(GO) run $(SWAGGER_PACKAGE) generate spec -x "$(SWAGGER_EXCLUDE)" -o './$(SWAGGER_SPEC)'
332
	$(SED_INPLACE) '$(SWAGGER_SPEC_S_TMPL)' './$(SWAGGER_SPEC)'
333
	$(SED_INPLACE) $(SWAGGER_NEWLINE_COMMAND) './$(SWAGGER_SPEC)'
334

335
.PHONY: swagger-check
336
swagger-check: generate-swagger
337
	@diff=$$(git diff --color=always '$(SWAGGER_SPEC)'); \
338
	if [ -n "$$diff" ]; then \
339
		echo "Please run 'make generate-swagger' and commit the result:"; \
340
		echo "$${diff}"; \
341
		exit 1; \
342
	fi
343

344
.PHONY: swagger-validate
345
swagger-validate:
346
	$(SED_INPLACE) '$(SWAGGER_SPEC_S_JSON)' './$(SWAGGER_SPEC)'
347
	$(GO) run $(SWAGGER_PACKAGE) validate './$(SWAGGER_SPEC)'
348
	$(SED_INPLACE) '$(SWAGGER_SPEC_S_TMPL)' './$(SWAGGER_SPEC)'
349

350
.PHONY: checks
351
checks: checks-frontend checks-backend
352

353
.PHONY: checks-frontend
354
checks-frontend: lockfile-check svg-check
355

356
.PHONY: checks-backend
357
checks-backend: tidy-check swagger-check fmt-check swagger-validate security-check
358

359
.PHONY: lint
360
lint: lint-frontend lint-backend lint-spell
361

362
.PHONY: lint-fix
363
lint-fix: lint-frontend-fix lint-backend-fix lint-spell-fix
364

365
.PHONY: lint-frontend
366
lint-frontend: lint-js lint-css
367

368
.PHONY: lint-frontend-fix
369
lint-frontend-fix: lint-js-fix lint-css-fix
370

371
.PHONY: lint-backend
372
lint-backend: lint-go lint-go-vet lint-go-gopls lint-editorconfig
373

374
.PHONY: lint-backend-fix
375
lint-backend-fix: lint-go-fix lint-go-vet lint-editorconfig
376

377
.PHONY: lint-js
378
lint-js: node_modules
379
	npx eslint --color --max-warnings=0 --ext js,ts,vue $(ESLINT_FILES)
380
#	npx tsc
381

382
.PHONY: lint-js-fix
383
lint-js-fix: node_modules
384
	npx eslint --color --max-warnings=0 --ext js,ts,vue $(ESLINT_FILES) --fix
385
#	npx tsc
386

387
.PHONY: lint-css
388
lint-css: node_modules
389
	npx stylelint --color --max-warnings=0 $(STYLELINT_FILES)
390

391
.PHONY: lint-css-fix
392
lint-css-fix: node_modules
393
	npx stylelint --color --max-warnings=0 $(STYLELINT_FILES) --fix
394

395
.PHONY: lint-swagger
396
lint-swagger: node_modules
397
	npx spectral lint -q -F hint $(SWAGGER_SPEC)
398

399
.PHONY: lint-md
400
lint-md: node_modules
401
	npx markdownlint *.md
402

403
.PHONY: lint-spell
404
lint-spell:
405
	@go run $(MISSPELL_PACKAGE) -dict tools/misspellings.csv -error $(SPELLCHECK_FILES)
406

407
.PHONY: lint-spell-fix
408
lint-spell-fix:
409
	@go run $(MISSPELL_PACKAGE) -dict tools/misspellings.csv -w $(SPELLCHECK_FILES)
410

411
.PHONY: lint-go
412
lint-go:
413
	$(GO) run $(GOLANGCI_LINT_PACKAGE) run
414

415
.PHONY: lint-go-fix
416
lint-go-fix:
417
	$(GO) run $(GOLANGCI_LINT_PACKAGE) run --fix
418

419
# workaround step for the lint-go-windows CI task because 'go run' can not
420
# have distinct GOOS/GOARCH for its build and run steps
421
.PHONY: lint-go-windows
422
lint-go-windows:
423
	@GOOS= GOARCH= $(GO) install $(GOLANGCI_LINT_PACKAGE)
424
	golangci-lint run
425

426
.PHONY: lint-go-vet
427
lint-go-vet:
428
	@echo "Running go vet..."
429
	@GOOS= GOARCH= $(GO) build code.gitea.io/gitea-vet
430
	@$(GO) vet -vettool=gitea-vet ./...
431

432
.PHONY: lint-go-gopls
433
lint-go-gopls:
434
	@echo "Running gopls check..."
435
	@GO=$(GO) GOPLS_PACKAGE=$(GOPLS_PACKAGE) tools/lint-go-gopls.sh $(GO_SOURCES_NO_BINDATA)
436

437
.PHONY: lint-editorconfig
438
lint-editorconfig:
439
	@$(GO) run $(EDITORCONFIG_CHECKER_PACKAGE) $(EDITORCONFIG_FILES)
440

441
.PHONY: lint-actions
442
lint-actions:
443
	$(GO) run $(ACTIONLINT_PACKAGE)
444

445
.PHONY: lint-templates
446
lint-templates: .venv node_modules
447
	@node tools/lint-templates-svg.js
448
	@poetry run djlint $(shell find templates -type f -iname '*.tmpl')
449

450
.PHONY: lint-yaml
451
lint-yaml: .venv
452
	@poetry run yamllint .
453

454
.PHONY: watch
455
watch:
456
	@bash tools/watch.sh
457

458
.PHONY: watch-frontend
459
watch-frontend: node-check node_modules
460
	@rm -rf $(WEBPACK_DEST_ENTRIES)
461
	NODE_ENV=development npx webpack --watch --progress
462

463
.PHONY: watch-backend
464
watch-backend: go-check
465
	GITEA_RUN_MODE=dev $(GO) run $(AIR_PACKAGE) -c .air.toml
466

467
.PHONY: test
468
test: test-frontend test-backend
469

470
.PHONY: test-backend
471
test-backend:
472
	@echo "Running go test with $(GOTESTFLAGS) -tags '$(TEST_TAGS)'..."
473
	@$(GO) test $(GOTESTFLAGS) -tags='$(TEST_TAGS)' $(GO_TEST_PACKAGES)
474

475
.PHONY: test-frontend
476
test-frontend: node_modules
477
	npx vitest
478

479
.PHONY: test-check
480
test-check:
481
	@echo "Running test-check...";
482
	@diff=$$(git status -s); \
483
	if [ -n "$$diff" ]; then \
484
		echo "make test-backend has changed files in the source tree:"; \
485
		echo "$${diff}"; \
486
		echo "You should change the tests to create these files in a temporary directory."; \
487
		echo "Do not simply add these files to .gitignore"; \
488
		exit 1; \
489
	fi
490

491
.PHONY: test\#%
492
test\#%:
493
	@echo "Running go test with -tags '$(TEST_TAGS)'..."
494
	@$(GO) test $(GOTESTFLAGS) -tags='$(TEST_TAGS)' -run $(subst .,/,$*) $(GO_TEST_PACKAGES)
495

496
.PHONY: coverage
497
coverage:
498
	grep '^\(mode: .*\)\|\(.*:[0-9]\+\.[0-9]\+,[0-9]\+\.[0-9]\+ [0-9]\+ [0-9]\+\)$$' coverage.out > coverage-bodged.out
499
	grep '^\(mode: .*\)\|\(.*:[0-9]\+\.[0-9]\+,[0-9]\+\.[0-9]\+ [0-9]\+ [0-9]\+\)$$' integration.coverage.out > integration.coverage-bodged.out
500
	$(GO) run build/gocovmerge.go integration.coverage-bodged.out coverage-bodged.out > coverage.all
501

502
.PHONY: unit-test-coverage
503
unit-test-coverage:
504
	@echo "Running unit-test-coverage $(GOTESTFLAGS) -tags '$(TEST_TAGS)'..."
505
	@$(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
506

507
.PHONY: tidy
508
tidy:
509
	$(eval MIN_GO_VERSION := $(shell grep -Eo '^go\s+[0-9]+\.[0-9.]+' go.mod | cut -d' ' -f2))
510
	$(GO) mod tidy -compat=$(MIN_GO_VERSION)
511
	@$(MAKE) --no-print-directory $(GO_LICENSE_FILE)
512

513
vendor: go.mod go.sum
514
	$(GO) mod vendor
515
	@touch vendor
516

517
.PHONY: tidy-check
518
tidy-check: tidy
519
	@diff=$$(git diff --color=always go.mod go.sum $(GO_LICENSE_FILE)); \
520
	if [ -n "$$diff" ]; then \
521
		echo "Please run 'make tidy' and commit the result:"; \
522
		echo "$${diff}"; \
523
		exit 1; \
524
	fi
525

526
.PHONY: go-licenses
527
go-licenses: $(GO_LICENSE_FILE)
528

529
$(GO_LICENSE_FILE): go.mod go.sum
530
	-$(GO) run $(GO_LICENSES_PACKAGE) save . --force --save_path=$(GO_LICENSE_TMP_DIR) 2>/dev/null
531
	$(GO) run build/generate-go-licenses.go $(GO_LICENSE_TMP_DIR) $(GO_LICENSE_FILE)
532
	@rm -rf $(GO_LICENSE_TMP_DIR)
533

534
generate-ini-sqlite:
535
	sed -e 's|{{REPO_TEST_DIR}}|${REPO_TEST_DIR}|g' \
536
		-e 's|{{TEST_LOGGER}}|$(or $(TEST_LOGGER),test$(COMMA)file)|g' \
537
		-e 's|{{TEST_TYPE}}|$(or $(TEST_TYPE),integration)|g' \
538
			tests/sqlite.ini.tmpl > tests/sqlite.ini
539

540
.PHONY: test-sqlite
541
test-sqlite: integrations.sqlite.test generate-ini-sqlite
542
	GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/sqlite.ini ./integrations.sqlite.test
543

544
.PHONY: test-sqlite\#%
545
test-sqlite\#%: integrations.sqlite.test generate-ini-sqlite
546
	GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/sqlite.ini ./integrations.sqlite.test -test.run $(subst .,/,$*)
547

548
.PHONY: test-sqlite-migration
549
test-sqlite-migration:  migrations.sqlite.test migrations.individual.sqlite.test
550

551
generate-ini-mysql:
552
	sed -e 's|{{TEST_MYSQL_HOST}}|${TEST_MYSQL_HOST}|g' \
553
		-e 's|{{TEST_MYSQL_DBNAME}}|${TEST_MYSQL_DBNAME}|g' \
554
		-e 's|{{TEST_MYSQL_USERNAME}}|${TEST_MYSQL_USERNAME}|g' \
555
		-e 's|{{TEST_MYSQL_PASSWORD}}|${TEST_MYSQL_PASSWORD}|g' \
556
		-e 's|{{REPO_TEST_DIR}}|${REPO_TEST_DIR}|g' \
557
		-e 's|{{TEST_LOGGER}}|$(or $(TEST_LOGGER),test$(COMMA)file)|g' \
558
		-e 's|{{TEST_TYPE}}|$(or $(TEST_TYPE),integration)|g' \
559
			tests/mysql.ini.tmpl > tests/mysql.ini
560

561
.PHONY: test-mysql
562
test-mysql: integrations.mysql.test generate-ini-mysql
563
	GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mysql.ini ./integrations.mysql.test
564

565
.PHONY: test-mysql\#%
566
test-mysql\#%: integrations.mysql.test generate-ini-mysql
567
	GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mysql.ini ./integrations.mysql.test -test.run $(subst .,/,$*)
568

569
.PHONY: test-mysql-migration
570
test-mysql-migration: migrations.mysql.test migrations.individual.mysql.test
571

572
generate-ini-pgsql:
573
	sed -e 's|{{TEST_PGSQL_HOST}}|${TEST_PGSQL_HOST}|g' \
574
		-e 's|{{TEST_PGSQL_DBNAME}}|${TEST_PGSQL_DBNAME}|g' \
575
		-e 's|{{TEST_PGSQL_USERNAME}}|${TEST_PGSQL_USERNAME}|g' \
576
		-e 's|{{TEST_PGSQL_PASSWORD}}|${TEST_PGSQL_PASSWORD}|g' \
577
		-e 's|{{TEST_PGSQL_SCHEMA}}|${TEST_PGSQL_SCHEMA}|g' \
578
		-e 's|{{TEST_MINIO_ENDPOINT}}|${TEST_MINIO_ENDPOINT}|g' \
579
		-e 's|{{REPO_TEST_DIR}}|${REPO_TEST_DIR}|g' \
580
		-e 's|{{TEST_LOGGER}}|$(or $(TEST_LOGGER),test$(COMMA)file)|g' \
581
		-e 's|{{TEST_TYPE}}|$(or $(TEST_TYPE),integration)|g' \
582
			tests/pgsql.ini.tmpl > tests/pgsql.ini
583

584
.PHONY: test-pgsql
585
test-pgsql: integrations.pgsql.test generate-ini-pgsql
586
	GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/pgsql.ini ./integrations.pgsql.test
587

588
.PHONY: test-pgsql\#%
589
test-pgsql\#%: integrations.pgsql.test generate-ini-pgsql
590
	GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/pgsql.ini ./integrations.pgsql.test -test.run $(subst .,/,$*)
591

592
.PHONY: test-pgsql-migration
593
test-pgsql-migration: migrations.pgsql.test migrations.individual.pgsql.test
594

595
generate-ini-mssql:
596
	sed -e 's|{{TEST_MSSQL_HOST}}|${TEST_MSSQL_HOST}|g' \
597
		-e 's|{{TEST_MSSQL_DBNAME}}|${TEST_MSSQL_DBNAME}|g' \
598
		-e 's|{{TEST_MSSQL_USERNAME}}|${TEST_MSSQL_USERNAME}|g' \
599
		-e 's|{{TEST_MSSQL_PASSWORD}}|${TEST_MSSQL_PASSWORD}|g' \
600
		-e 's|{{REPO_TEST_DIR}}|${REPO_TEST_DIR}|g' \
601
		-e 's|{{TEST_LOGGER}}|$(or $(TEST_LOGGER),test$(COMMA)file)|g' \
602
		-e 's|{{TEST_TYPE}}|$(or $(TEST_TYPE),integration)|g' \
603
			tests/mssql.ini.tmpl > tests/mssql.ini
604

605
.PHONY: test-mssql
606
test-mssql: integrations.mssql.test generate-ini-mssql
607
	GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mssql.ini ./integrations.mssql.test
608

609
.PHONY: test-mssql\#%
610
test-mssql\#%: integrations.mssql.test generate-ini-mssql
611
	GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mssql.ini ./integrations.mssql.test -test.run $(subst .,/,$*)
612

613
.PHONY: test-mssql-migration
614
test-mssql-migration: migrations.mssql.test migrations.individual.mssql.test
615

616
.PHONY: playwright
617
playwright: deps-frontend
618
	npx playwright install $(PLAYWRIGHT_FLAGS)
619

620
.PHONY: test-e2e%
621
test-e2e%: TEST_TYPE ?= e2e
622
	# Clear display env variable. Otherwise, chromium tests can fail.
623
	DISPLAY=
624

625
.PHONY: test-e2e
626
test-e2e: test-e2e-sqlite
627

628
.PHONY: test-e2e-sqlite
629
test-e2e-sqlite: playwright e2e.sqlite.test generate-ini-sqlite
630
	GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/sqlite.ini ./e2e.sqlite.test
631

632
.PHONY: test-e2e-sqlite\#%
633
test-e2e-sqlite\#%: playwright e2e.sqlite.test generate-ini-sqlite
634
	GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/sqlite.ini ./e2e.sqlite.test -test.run TestE2e/$*
635

636
.PHONY: test-e2e-mysql
637
test-e2e-mysql: playwright e2e.mysql.test generate-ini-mysql
638
	GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mysql.ini ./e2e.mysql.test
639

640
.PHONY: test-e2e-mysql\#%
641
test-e2e-mysql\#%: playwright e2e.mysql.test generate-ini-mysql
642
	GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mysql.ini ./e2e.mysql.test -test.run TestE2e/$*
643

644
.PHONY: test-e2e-pgsql
645
test-e2e-pgsql: playwright e2e.pgsql.test generate-ini-pgsql
646
	GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/pgsql.ini ./e2e.pgsql.test
647

648
.PHONY: test-e2e-pgsql\#%
649
test-e2e-pgsql\#%: playwright e2e.pgsql.test generate-ini-pgsql
650
	GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/pgsql.ini ./e2e.pgsql.test -test.run TestE2e/$*
651

652
.PHONY: test-e2e-mssql
653
test-e2e-mssql: playwright e2e.mssql.test generate-ini-mssql
654
	GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mssql.ini ./e2e.mssql.test
655

656
.PHONY: test-e2e-mssql\#%
657
test-e2e-mssql\#%: playwright e2e.mssql.test generate-ini-mssql
658
	GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mssql.ini ./e2e.mssql.test -test.run TestE2e/$*
659

660
.PHONY: bench-sqlite
661
bench-sqlite: integrations.sqlite.test generate-ini-sqlite
662
	GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/sqlite.ini ./integrations.sqlite.test -test.cpuprofile=cpu.out -test.run DontRunTests -test.bench .
663

664
.PHONY: bench-mysql
665
bench-mysql: integrations.mysql.test generate-ini-mysql
666
	GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mysql.ini ./integrations.mysql.test -test.cpuprofile=cpu.out -test.run DontRunTests -test.bench .
667

668
.PHONY: bench-mssql
669
bench-mssql: integrations.mssql.test generate-ini-mssql
670
	GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mssql.ini ./integrations.mssql.test -test.cpuprofile=cpu.out -test.run DontRunTests -test.bench .
671

672
.PHONY: bench-pgsql
673
bench-pgsql: integrations.pgsql.test generate-ini-pgsql
674
	GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/pgsql.ini ./integrations.pgsql.test -test.cpuprofile=cpu.out -test.run DontRunTests -test.bench .
675

676
.PHONY: integration-test-coverage
677
integration-test-coverage: integrations.cover.test generate-ini-mysql
678
	GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mysql.ini ./integrations.cover.test -test.coverprofile=integration.coverage.out
679

680
.PHONY: integration-test-coverage-sqlite
681
integration-test-coverage-sqlite: integrations.cover.sqlite.test generate-ini-sqlite
682
	GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/sqlite.ini ./integrations.cover.sqlite.test -test.coverprofile=integration.coverage.out
683

684
integrations.mysql.test: git-check $(GO_SOURCES)
685
	$(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/tests/integration -o integrations.mysql.test
686

687
integrations.pgsql.test: git-check $(GO_SOURCES)
688
	$(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/tests/integration -o integrations.pgsql.test
689

690
integrations.mssql.test: git-check $(GO_SOURCES)
691
	$(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/tests/integration -o integrations.mssql.test
692

693
integrations.sqlite.test: git-check $(GO_SOURCES)
694
	$(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/tests/integration -o integrations.sqlite.test -tags '$(TEST_TAGS)'
695

696
integrations.cover.test: git-check $(GO_SOURCES)
697
	$(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/tests/integration -coverpkg $(shell echo $(GO_TEST_PACKAGES) | tr ' ' ',') -o integrations.cover.test
698

699
integrations.cover.sqlite.test: git-check $(GO_SOURCES)
700
	$(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)'
701

702
.PHONY: migrations.mysql.test
703
migrations.mysql.test: $(GO_SOURCES) generate-ini-mysql
704
	$(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/tests/integration/migration-test -o migrations.mysql.test
705
	GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mysql.ini ./migrations.mysql.test
706

707
.PHONY: migrations.pgsql.test
708
migrations.pgsql.test: $(GO_SOURCES) generate-ini-pgsql
709
	$(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/tests/integration/migration-test -o migrations.pgsql.test
710
	GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/pgsql.ini ./migrations.pgsql.test
711

712
.PHONY: migrations.mssql.test
713
migrations.mssql.test: $(GO_SOURCES) generate-ini-mssql
714
	$(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/tests/integration/migration-test -o migrations.mssql.test
715
	GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mssql.ini ./migrations.mssql.test
716

717
.PHONY: migrations.sqlite.test
718
migrations.sqlite.test: $(GO_SOURCES) generate-ini-sqlite
719
	$(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/tests/integration/migration-test -o migrations.sqlite.test -tags '$(TEST_TAGS)'
720
	GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/sqlite.ini ./migrations.sqlite.test
721

722
.PHONY: migrations.individual.mysql.test
723
migrations.individual.mysql.test: $(GO_SOURCES)
724
	GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mysql.ini $(GO) test $(GOTESTFLAGS) -tags='$(TEST_TAGS)' -p 1 $(MIGRATE_TEST_PACKAGES)
725

726
.PHONY: migrations.individual.sqlite.test\#%
727
migrations.individual.sqlite.test\#%: $(GO_SOURCES) generate-ini-sqlite
728
	GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/sqlite.ini $(GO) test $(GOTESTFLAGS) -tags '$(TEST_TAGS)' code.gitea.io/gitea/models/migrations/$*
729

730
.PHONY: migrations.individual.pgsql.test
731
migrations.individual.pgsql.test: $(GO_SOURCES)
732
	GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/pgsql.ini $(GO) test $(GOTESTFLAGS) -tags='$(TEST_TAGS)' -p 1 $(MIGRATE_TEST_PACKAGES)
733

734
.PHONY: migrations.individual.pgsql.test\#%
735
migrations.individual.pgsql.test\#%: $(GO_SOURCES) generate-ini-pgsql
736
	GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/pgsql.ini $(GO) test $(GOTESTFLAGS) -tags '$(TEST_TAGS)' code.gitea.io/gitea/models/migrations/$*
737

738
.PHONY: migrations.individual.mssql.test
739
migrations.individual.mssql.test: $(GO_SOURCES) generate-ini-mssql
740
	GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mssql.ini $(GO) test $(GOTESTFLAGS) -tags='$(TEST_TAGS)' -p 1 $(MIGRATE_TEST_PACKAGES)
741

742
.PHONY: migrations.individual.mssql.test\#%
743
migrations.individual.mssql.test\#%: $(GO_SOURCES) generate-ini-mssql
744
	GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mssql.ini $(GO) test $(GOTESTFLAGS) -tags '$(TEST_TAGS)' code.gitea.io/gitea/models/migrations/$*
745

746
.PHONY: migrations.individual.sqlite.test
747
migrations.individual.sqlite.test: $(GO_SOURCES) generate-ini-sqlite
748
	GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/sqlite.ini $(GO) test $(GOTESTFLAGS) -tags='$(TEST_TAGS)' -p 1 $(MIGRATE_TEST_PACKAGES)
749

750
.PHONY: migrations.individual.sqlite.test\#%
751
migrations.individual.sqlite.test\#%: $(GO_SOURCES) generate-ini-sqlite
752
	GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/sqlite.ini $(GO) test $(GOTESTFLAGS) -tags '$(TEST_TAGS)' code.gitea.io/gitea/models/migrations/$*
753

754
e2e.mysql.test: $(GO_SOURCES)
755
	$(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/tests/e2e -o e2e.mysql.test
756

757
e2e.pgsql.test: $(GO_SOURCES)
758
	$(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/tests/e2e -o e2e.pgsql.test
759

760
e2e.mssql.test: $(GO_SOURCES)
761
	$(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/tests/e2e -o e2e.mssql.test
762

763
e2e.sqlite.test: $(GO_SOURCES)
764
	$(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/tests/e2e -o e2e.sqlite.test -tags '$(TEST_TAGS)'
765

766
.PHONY: check
767
check: test
768

769
.PHONY: install $(TAGS_PREREQ)
770
install: $(wildcard *.go)
771
	CGO_CFLAGS="$(CGO_CFLAGS)" $(GO) install -v -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)'
772

773
.PHONY: build
774
build: frontend backend
775

776
.PHONY: frontend
777
frontend: $(WEBPACK_DEST)
778

779
.PHONY: backend
780
backend: go-check generate-backend $(EXECUTABLE)
781

782
# 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
783
.PHONY: generate
784
generate: generate-backend
785

786
.PHONY: generate-backend
787
generate-backend: $(TAGS_PREREQ) generate-go
788

789
.PHONY: generate-go
790
generate-go: $(TAGS_PREREQ)
791
	@echo "Running go generate..."
792
	@CC= GOOS= GOARCH= CGO_ENABLED=0 $(GO) generate -tags '$(TAGS)' ./...
793

794
.PHONY: security-check
795
security-check:
796
	go run $(GOVULNCHECK_PACKAGE) ./...
797

798
$(EXECUTABLE): $(GO_SOURCES) $(TAGS_PREREQ)
799
	CGO_CFLAGS="$(CGO_CFLAGS)" $(GO) build $(GOFLAGS) $(EXTRA_GOFLAGS) -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)' -o $@
800

801
.PHONY: release
802
release: frontend generate release-windows release-linux release-darwin release-freebsd release-copy release-compress vendor release-sources release-check
803

804
$(DIST_DIRS):
805
	mkdir -p $(DIST_DIRS)
806

807
.PHONY: release-windows
808
release-windows: | $(DIST_DIRS)
809
	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) .
810
ifeq (,$(findstring gogit,$(TAGS)))
811
	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 .
812
endif
813

814
.PHONY: release-linux
815
release-linux: | $(DIST_DIRS)
816
	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) .
817

818
.PHONY: release-darwin
819
release-darwin: | $(DIST_DIRS)
820
	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) .
821

822
.PHONY: release-freebsd
823
release-freebsd: | $(DIST_DIRS)
824
	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) .
825

826
.PHONY: release-copy
827
release-copy: | $(DIST_DIRS)
828
	cd $(DIST); for file in `find . -type f -name "*"`; do cp $${file} ./release/; done;
829

830
.PHONY: release-check
831
release-check: | $(DIST_DIRS)
832
	cd $(DIST)/release/; for file in `find . -type f -name "*"`; do echo "checksumming $${file}" && $(SHASUM) `echo $${file} | sed 's/^..//'` > $${file}.sha256; done;
833

834
.PHONY: release-compress
835
release-compress: | $(DIST_DIRS)
836
	cd $(DIST)/release/; for file in `find . -type f -name "*"`; do echo "compressing $${file}" && $(GO) run $(GXZ_PACKAGE) -k -9 $${file}; done;
837

838
.PHONY: release-sources
839
release-sources: | $(DIST_DIRS)
840
	echo $(VERSION) > $(STORED_VERSION_FILE)
841
# bsdtar needs a ^ to prevent matching subdirectories
842
	$(eval EXCL := --exclude=$(shell tar --help | grep -q bsdtar && echo "^")./)
843
# use transform to a add a release-folder prefix; in bsdtar the transform parameter equivalent is -s
844
	$(eval TRANSFORM := $(shell tar --help | grep -q bsdtar && echo "-s '/^./gitea-src-$(VERSION)/'" || echo "--transform 's|^./|gitea-src-$(VERSION)/|'"))
845
	tar $(addprefix $(EXCL),$(TAR_EXCLUDES)) $(TRANSFORM) -czf $(DIST)/release/gitea-src-$(VERSION).tar.gz .
846
	rm -f $(STORED_VERSION_FILE)
847

848
.PHONY: deps
849
deps: deps-frontend deps-backend deps-tools deps-py
850

851
.PHONY: deps-py
852
deps-py: .venv
853

854
.PHONY: deps-frontend
855
deps-frontend: node_modules
856

857
.PHONY: deps-backend
858
deps-backend:
859
	$(GO) mod download
860

861
.PHONY: deps-tools
862
deps-tools:
863
	$(GO) install $(AIR_PACKAGE) & \
864
	$(GO) install $(EDITORCONFIG_CHECKER_PACKAGE) & \
865
	$(GO) install $(GOFUMPT_PACKAGE) & \
866
	$(GO) install $(GOLANGCI_LINT_PACKAGE) & \
867
	$(GO) install $(GXZ_PACKAGE) & \
868
	$(GO) install $(MISSPELL_PACKAGE) & \
869
	$(GO) install $(SWAGGER_PACKAGE) & \
870
	$(GO) install $(XGO_PACKAGE) & \
871
	$(GO) install $(GO_LICENSES_PACKAGE) & \
872
	$(GO) install $(GOVULNCHECK_PACKAGE) & \
873
	$(GO) install $(ACTIONLINT_PACKAGE) & \
874
	$(GO) install $(GOPLS_PACKAGE) & \
875
	wait
876

877
node_modules: package-lock.json
878
	npm install --no-save
879
	@touch node_modules
880

881
.venv: poetry.lock
882
	poetry install
883
	@touch .venv
884

885
.PHONY: update
886
update: update-js update-py
887

888
.PHONY: update-js
889
update-js: node-check | node_modules
890
	npx updates -u -f package.json
891
	rm -rf node_modules package-lock.json
892
	npm install --package-lock
893
	npx nolyfill install
894
	npm install --package-lock
895
	@touch node_modules
896

897
.PHONY: update-py
898
update-py: node-check | node_modules
899
	npx updates -u -f pyproject.toml
900
	rm -rf .venv poetry.lock
901
	poetry install
902
	@touch .venv
903

904
.PHONY: fomantic
905
fomantic:
906
	rm -rf $(FOMANTIC_WORK_DIR)/build
907
	cd $(FOMANTIC_WORK_DIR) && npm install --no-save
908
	cp -f $(FOMANTIC_WORK_DIR)/theme.config.less $(FOMANTIC_WORK_DIR)/node_modules/fomantic-ui/src/theme.config
909
	cp -rf $(FOMANTIC_WORK_DIR)/_site $(FOMANTIC_WORK_DIR)/node_modules/fomantic-ui/src/
910
	$(SED_INPLACE) -e 's/  overrideBrowserslist\r/  overrideBrowserslist: ["defaults"]\r/g' $(FOMANTIC_WORK_DIR)/node_modules/fomantic-ui/tasks/config/tasks.js
911
	cd $(FOMANTIC_WORK_DIR) && npx gulp -f node_modules/fomantic-ui/gulpfile.js build
912
	# fomantic uses "touchstart" as click event for some browsers, it's not ideal, so we force fomantic to always use "click" as click event
913
	$(SED_INPLACE) -e 's/clickEvent[ \t]*=/clickEvent = "click", unstableClickEvent =/g' $(FOMANTIC_WORK_DIR)/build/semantic.js
914
	$(SED_INPLACE) -e 's/\r//g' $(FOMANTIC_WORK_DIR)/build/semantic.css $(FOMANTIC_WORK_DIR)/build/semantic.js
915
	rm -f $(FOMANTIC_WORK_DIR)/build/*.min.*
916

917
.PHONY: webpack
918
webpack: $(WEBPACK_DEST)
919

920
$(WEBPACK_DEST): $(WEBPACK_SOURCES) $(WEBPACK_CONFIGS) package-lock.json
921
	@$(MAKE) -s node-check node_modules
922
	@rm -rf $(WEBPACK_DEST_ENTRIES)
923
	@echo "Running webpack..."
924
	@BROWSERSLIST_IGNORE_OLD_DATA=true npx webpack
925
	@touch $(WEBPACK_DEST)
926

927
.PHONY: svg
928
svg: node-check | node_modules
929
	rm -rf $(SVG_DEST_DIR)
930
	node tools/generate-svg.js
931

932
.PHONY: svg-check
933
svg-check: svg
934
	@git add $(SVG_DEST_DIR)
935
	@diff=$$(git diff --color=always --cached $(SVG_DEST_DIR)); \
936
	if [ -n "$$diff" ]; then \
937
		echo "Please run 'make svg' and 'git add $(SVG_DEST_DIR)' and commit the result:"; \
938
		echo "$${diff}"; \
939
		exit 1; \
940
	fi
941

942
.PHONY: lockfile-check
943
lockfile-check:
944
	npm install --package-lock-only
945
	@diff=$$(git diff --color=always package-lock.json); \
946
	if [ -n "$$diff" ]; then \
947
		echo "package-lock.json is inconsistent with package.json"; \
948
		echo "Please run 'npm install --package-lock-only' and commit the result:"; \
949
		echo "$${diff}"; \
950
		exit 1; \
951
	fi
952

953
.PHONY: update-translations
954
update-translations:
955
	mkdir -p ./translations
956
	cd ./translations && curl -L https://crowdin.com/download/project/gitea.zip > gitea.zip && unzip gitea.zip
957
	rm ./translations/gitea.zip
958
	$(SED_INPLACE) -e 's/="/=/g' -e 's/"$$//g' ./translations/*.ini
959
	$(SED_INPLACE) -e 's/\\"/"/g' ./translations/*.ini
960
	mv ./translations/*.ini ./options/locale/
961
	rmdir ./translations
962

963
.PHONY: generate-license
964
generate-license:
965
	$(GO) run build/generate-licenses.go
966

967
.PHONY: generate-gitignore
968
generate-gitignore:
969
	$(GO) run build/generate-gitignores.go
970

971
.PHONY: generate-images
972
generate-images: | node_modules
973
	npm install --no-save fabric@6 imagemin-zopfli@7
974
	node tools/generate-images.js $(TAGS)
975

976
.PHONY: generate-manpage
977
generate-manpage:
978
	@[ -f gitea ] || make backend
979
	@mkdir -p man/man1/ man/man5
980
	@./gitea docs --man > man/man1/gitea.1
981
	@gzip -9 man/man1/gitea.1 && echo man/man1/gitea.1.gz created
982
	@#TODO A small script that formats config-cheat-sheet.en-us.md nicely for use as a config man page
983

984
.PHONY: docker
985
docker:
986
	docker build --disable-content-trust=false -t $(DOCKER_REF) .
987
# support also build args docker build --build-arg GITEA_VERSION=v1.2.3 --build-arg TAGS="bindata sqlite sqlite_unlock_notify"  .
988

989
# This endif closes the if at the top of the file
990
endif
991

992
# Disable parallel execution because it would break some targets that don't
993
# specify exact dependencies like 'backend' which does currently not depend
994
# on 'frontend' to enable Node.js-less builds from source tarballs.
995
.NOTPARALLEL:
996

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.