loading up the forgejo repo on tangled to test page performance
1ifeq ($(USE_REPO_TEST_DIR),1)
2
3# This rule replaces the whole Makefile when we're trying to use /tmp repository temporary files
4location = $(CURDIR)/$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
5self := $(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
13else
14
15# This is the "normal" part of the Makefile
16
17DIST := dist
18DIST_DIRS := $(DIST)/binaries $(DIST)/release
19IMPORT := forgejo.org
20
21GO ?= $(shell go env GOROOT)/bin/go
22SHASUM ?= shasum -a 256
23HAS_GO := $(shell hash $(GO) > /dev/null 2>&1 && echo yes)
24COMMA := ,
25DIFF ?= diff --unified
26
27ifeq ($(USE_GOTESTSUM), yes)
28 GOTEST ?= gotestsum --
29 GOTESTCOMPILEDRUNPREFIX ?= gotestsum --raw-command -- go tool test2json -t
30 GOTESTCOMPILEDRUNSUFFIX ?= -test.v=test2json
31else
32 GOTEST ?= $(GO) test
33 GOTESTCOMPILEDRUNPREFIX ?=
34 GOTESTCOMPILEDRUNSUFFIX ?=
35endif
36
37XGO_VERSION := go-1.21.x
38
39AIR_PACKAGE ?= github.com/air-verse/air@v1 # renovate: datasource=go
40EDITORCONFIG_CHECKER_PACKAGE ?= github.com/editorconfig-checker/editorconfig-checker/v3/cmd/editorconfig-checker@v3.2.1 # renovate: datasource=go
41GOFUMPT_PACKAGE ?= mvdan.cc/gofumpt@v0.7.0 # renovate: datasource=go
42GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.1.1 # renovate: datasource=go
43GXZ_PACKAGE ?= github.com/ulikunitz/xz/cmd/gxz@v0.5.11 # renovate: datasource=go
44MISSPELL_PACKAGE ?= github.com/golangci/misspell/cmd/misspell@v0.6.0 # renovate: datasource=go
45SWAGGER_PACKAGE ?= github.com/go-swagger/go-swagger/cmd/swagger@v0.31.0 # renovate: datasource=go
46XGO_PACKAGE ?= src.techknowlogick.com/xgo@latest
47GO_LICENSES_PACKAGE ?= github.com/google/go-licenses@v1.6.0 # renovate: datasource=go
48GOVULNCHECK_PACKAGE ?= golang.org/x/vuln/cmd/govulncheck@v1 # renovate: datasource=go
49DEADCODE_PACKAGE ?= golang.org/x/tools/cmd/deadcode@v0.32.0 # renovate: datasource=go
50GOMOCK_PACKAGE ?= go.uber.org/mock/mockgen@v0.5.1 # renovate: datasource=go
51GOPLS_PACKAGE ?= golang.org/x/tools/gopls@v0.18.1 # renovate: datasource=go
52RENOVATE_NPM_PACKAGE ?= renovate@39.240.1 # renovate: datasource=docker packageName=data.forgejo.org/renovate/renovate
53
54# https://github.com/disposable-email-domains/disposable-email-domains/commits/main/
55DISPOSABLE_EMAILS_SHA ?= 0c27e671231d27cf66370034d7f6818037416989 # renovate: ...
56
57ifeq ($(HAS_GO), yes)
58 CGO_EXTRA_CFLAGS := -DSQLITE_MAX_VARIABLE_NUMBER=32766
59 CGO_CFLAGS ?= $(shell $(GO) env CGO_CFLAGS) $(CGO_EXTRA_CFLAGS)
60endif
61
62GOFLAGS := -v
63EXECUTABLE ?= gitea
64
65ifeq ($(shell sed --version 2>/dev/null | grep -q GNU && echo gnu),gnu)
66 SED_INPLACE := sed -i
67else
68 SED_INPLACE := sed -i ''
69endif
70
71EXTRA_GOFLAGS ?=
72
73MAKE_VERSION := $(shell "$(MAKE)" -v | cat | head -n 1)
74MAKE_EVIDENCE_DIR := .make_evidence
75
76ifeq ($(RACE_ENABLED),true)
77 GOFLAGS += -race
78 GOTESTFLAGS += -race
79endif
80
81STORED_VERSION_FILE := VERSION
82HUGO_VERSION ?= 0.111.3
83
84GITEA_COMPATIBILITY ?= gitea-1.22.0
85
86STORED_VERSION=$(shell cat $(STORED_VERSION_FILE) 2>/dev/null)
87ifneq ($(STORED_VERSION),)
88 FORGEJO_VERSION ?= $(STORED_VERSION)
89else
90 ifneq ($(GITEA_VERSION),)
91 FORGEJO_VERSION ?= $(GITEA_VERSION)
92 FORGEJO_VERSION_API ?= $(GITEA_VERSION)+${GITEA_COMPATIBILITY}
93 else
94 # drop the "g" prefix prepended by git describe to the commit hash
95 FORGEJO_VERSION ?= $(shell git describe --exclude '*-test' --tags --always | sed 's/^v//' | sed 's/\-g/-/')+${GITEA_COMPATIBILITY}
96 endif
97endif
98FORGEJO_VERSION_MAJOR=$(shell echo $(FORGEJO_VERSION) | sed -e 's/\..*//')
99FORGEJO_VERSION_MINOR=$(shell echo $(FORGEJO_VERSION) | sed -E -e 's/^([0-9]+\.[0-9]+).*/\1/')
100
101show-version-full:
102 @echo ${FORGEJO_VERSION}
103
104show-version-major:
105 @echo ${FORGEJO_VERSION_MAJOR}
106
107show-version-minor:
108 @echo ${FORGEJO_VERSION_MINOR}
109
110RELEASE_VERSION ?= ${FORGEJO_VERSION}
111VERSION ?= ${RELEASE_VERSION}
112
113FORGEJO_VERSION_API ?= ${FORGEJO_VERSION}
114
115show-version-api:
116 @echo ${FORGEJO_VERSION_API}
117
118# Strip binaries by default to reduce size, allow overriding for debugging
119STRIP ?= 1
120ifeq ($(STRIP),1)
121 LDFLAGS := $(LDFLAGS) -s -w
122endif
123LDFLAGS := $(LDFLAGS) -X "main.ReleaseVersion=$(RELEASE_VERSION)" -X "main.MakeVersion=$(MAKE_VERSION)" -X "main.Version=$(FORGEJO_VERSION)" -X "main.Tags=$(TAGS)" -X "main.ForgejoVersion=$(FORGEJO_VERSION_API)"
124
125LINUX_ARCHS ?= linux/amd64,linux/386,linux/arm-5,linux/arm-6,linux/arm64
126
127ifeq ($(HAS_GO), yes)
128 GO_TEST_PACKAGES ?= $(filter-out $(shell $(GO) list forgejo.org/models/migrations/...) $(shell $(GO) list forgejo.org/models/forgejo_migrations/...) forgejo.org/tests/integration/migration-test forgejo.org/tests forgejo.org/tests/integration forgejo.org/tests/e2e,$(shell $(GO) list ./...))
129endif
130REMOTE_CACHER_MODULES ?= cache nosql session queue
131GO_TEST_REMOTE_CACHER_PACKAGES ?= $(addprefix forgejo.org/modules/,$(REMOTE_CACHER_MODULES))
132
133FOMANTIC_WORK_DIR := web_src/fomantic
134
135WEBPACK_SOURCES := $(shell find web_src/js web_src/css -type f)
136WEBPACK_CONFIGS := webpack.config.js tailwind.config.js
137WEBPACK_DEST := public/assets/js/index.js public/assets/css/index.css
138WEBPACK_DEST_ENTRIES := public/assets/js public/assets/css public/assets/fonts
139
140BINDATA_DEST := modules/public/bindata.go modules/options/bindata.go modules/templates/bindata.go
141BINDATA_HASH := $(addsuffix .hash,$(BINDATA_DEST))
142
143GENERATED_GO_DEST := modules/charset/invisible_gen.go modules/charset/ambiguous_gen.go
144
145SVG_DEST_DIR := public/assets/img/svg
146
147AIR_TMP_DIR := .air
148
149GO_LICENSE_TMP_DIR := .go-licenses
150GO_LICENSE_FILE := assets/go-licenses.json
151
152TAGS ?=
153TAGS_SPLIT := $(subst $(COMMA), ,$(TAGS))
154TAGS_EVIDENCE := $(MAKE_EVIDENCE_DIR)/tags
155
156TEST_TAGS ?= sqlite sqlite_unlock_notify
157
158TAR_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)
159
160GO_DIRS := build cmd models modules routers services tests
161WEB_DIRS := web_src/js web_src/css
162
163STYLELINT_FILES := web_src/css web_src/js/components/*.vue
164SPELLCHECK_FILES := $(GO_DIRS) $(WEB_DIRS) docs/content templates options/locale/locale_en-US.ini .github $(wildcard *.go *.js *.ts *.vue *.md *.yml *.yaml)
165
166GO_SOURCES := $(wildcard *.go)
167GO_SOURCES += $(shell find $(GO_DIRS) -type f -name "*.go" ! -path modules/options/bindata.go ! -path modules/public/bindata.go ! -path modules/templates/bindata.go)
168GO_SOURCES += $(GENERATED_GO_DEST)
169GO_SOURCES_NO_BINDATA := $(GO_SOURCES)
170
171ifeq ($(HAS_GO), yes)
172 MIGRATION_PACKAGES := $(shell $(GO) list forgejo.org/models/migrations/... forgejo.org/models/forgejo_migrations/...)
173endif
174
175ifeq ($(filter $(TAGS_SPLIT),bindata),bindata)
176 GO_SOURCES += $(BINDATA_DEST)
177 GENERATED_GO_DEST += $(BINDATA_DEST)
178endif
179
180# Force installation of playwright dependencies by setting this flag
181ifdef DEPS_PLAYWRIGHT
182 PLAYWRIGHT_FLAGS += --with-deps
183endif
184
185FORGEJO_API_SPEC := public/assets/forgejo/api.v1.yml
186
187SWAGGER_SPEC := templates/swagger/v1_json.tmpl
188SWAGGER_SPEC_S_TMPL := s|"basePath": *"/api/v1"|"basePath": "{{AppSubUrl \| JSEscape}}/api/v1"|g
189SWAGGER_SPEC_S_JSON := s|"basePath": *"{{AppSubUrl \| JSEscape}}/api/v1"|"basePath": "/api/v1"|g
190SWAGGER_EXCLUDE := code.gitea.io/sdk
191SWAGGER_NEWLINE_COMMAND := -e '$$a\'
192SWAGGER_SPEC_BRANDING := s|Gitea API|Forgejo API|g
193SWAGGER_SPEC_LICENSE := s|"name": "MIT"|"name": "This file is distributed under the MIT license for the purpose of interoperability"|
194
195TEST_MYSQL_HOST ?= mysql:3306
196TEST_MYSQL_DBNAME ?= testgitea?multiStatements=true
197TEST_MYSQL_USERNAME ?= root
198TEST_MYSQL_PASSWORD ?=
199TEST_PGSQL_HOST ?= pgsql:5432
200TEST_PGSQL_DBNAME ?= testgitea
201TEST_PGSQL_USERNAME ?= postgres
202TEST_PGSQL_PASSWORD ?= postgres
203TEST_PGSQL_SCHEMA ?= gtestschema
204
205.PHONY: all
206all: build
207
208.PHONY: help
209help:
210 @echo "Make Routines:"
211 @echo " - \"\" equivalent to \"build\""
212 @echo " - build build everything"
213 @echo " - frontend build frontend files"
214 @echo " - backend build backend files"
215 @echo " - watch watch everything and continuously rebuild"
216 @echo " - watch-frontend watch frontend files and continuously rebuild"
217 @echo " - watch-backend watch backend files and continuously rebuild"
218 @echo " - clean delete backend and integration files"
219 @echo " - clean-all delete backend, frontend and integration files"
220 @echo " - deps install dependencies"
221 @echo " - deps-frontend install frontend dependencies"
222 @echo " - deps-backend install backend dependencies"
223 @echo " - deps-tools install tool dependencies"
224 @echo " - deps-py install python dependencies"
225 @echo " - lint lint everything"
226 @echo " - lint-fix lint everything and fix issues"
227 @echo " - lint-frontend lint frontend files"
228 @echo " - lint-frontend-fix lint frontend files and fix issues"
229 @echo " - lint-backend lint backend files"
230 @echo " - lint-backend-fix lint backend files and fix issues"
231 @echo " - lint-codespell lint typos"
232 @echo " - lint-codespell-fix lint typos and fix them automatically"
233 @echo " - lint-codespell-fix-i lint typos and fix them interactively"
234 @echo " - lint-go lint go files"
235 @echo " - lint-go-fix lint go files and fix issues"
236 @echo " - lint-go-vet lint go files with vet"
237 @echo " - lint-go-gopls lint go files with gopls"
238 @echo " - lint-js lint js files"
239 @echo " - lint-js-fix lint js files and fix issues"
240 @echo " - lint-css lint css files"
241 @echo " - lint-css-fix lint css files and fix issues"
242 @echo " - lint-md lint markdown files"
243 @echo " - lint-swagger lint swagger files"
244 @echo " - lint-templates lint template files"
245 @echo " - lint-renovate lint renovate files"
246 @echo " - lint-yaml lint yaml files"
247 @echo " - lint-spell lint spelling"
248 @echo " - lint-spell-fix lint spelling and fix issues"
249 @echo " - checks run various consistency checks"
250 @echo " - checks-frontend check frontend files"
251 @echo " - checks-backend check backend files"
252 @echo " - test test everything"
253 @echo " - show-version-full show the same version as the API endpoint"
254 @echo " - show-version-major show major release number only"
255 @echo " - test-frontend test frontend files"
256 @echo " - test-frontend-coverage test frontend files and display code coverage"
257 @echo " - test-backend test backend files"
258 @echo " - test-remote-cacher test backend files that use a remote cache"
259 @echo " - test-e2e-sqlite[\#name.test.e2e] test end to end using playwright and sqlite"
260 @echo " - webpack build webpack files"
261 @echo " - svg build svg files"
262 @echo " - fomantic build fomantic files"
263 @echo " - generate run \"go generate\""
264 @echo " - fmt format the Go code"
265 @echo " - generate-license update license files"
266 @echo " - generate-gitignore update gitignore files"
267 @echo " - generate-manpage generate manpage"
268 @echo " - generate-gomock generate gomock files"
269 @echo " - generate-forgejo-api generate the forgejo API from spec"
270 @echo " - forgejo-api-validate check if the forgejo API matches the specs"
271 @echo " - generate-swagger generate the swagger spec from code comments"
272 @echo " - swagger-validate check if the swagger spec is valid"
273 @echo " - go-licenses regenerate go licenses"
274 @echo " - tidy run go mod tidy"
275 @echo " - test[\#TestSpecificName] run unit test"
276 @echo " - test-sqlite[\#TestSpecificName] run integration test for sqlite"
277 @echo " - reproduce-build\#version build a reproducible binary for the specified release version"
278
279###
280# Check system and environment requirements
281###
282
283.PHONY: go-check
284go-check:
285 $(eval MIN_GO_VERSION_STR := $(shell grep -Eo '^go\s+[0-9]+\.[0-9]+' go.mod | cut -d' ' -f2))
286 $(eval MIN_GO_VERSION := $(shell printf "%03d%03d" $(shell echo '$(MIN_GO_VERSION_STR)' | tr '.' ' ')))
287 $(eval GO_VERSION := $(shell printf "%03d%03d" $(shell $(GO) version | grep -Eo '[0-9]+\.[0-9]+' | tr '.' ' ');))
288 @if [ "$(GO_VERSION)" -lt "$(MIN_GO_VERSION)" ]; then \
289 echo "Forgejo requires Go $(MIN_GO_VERSION_STR) or greater to build. You can get it at https://go.dev/dl/"; \
290 exit 1; \
291 fi
292
293.PHONY: git-check
294git-check:
295 @if git lfs >/dev/null 2>&1 ; then : ; else \
296 echo "Forgejo requires git with lfs support to run tests." ; \
297 exit 1; \
298 fi
299
300.PHONY: node-check
301node-check:
302 $(eval MIN_NODE_VERSION_STR := $(shell grep -Eo '"node":.*[0-9.]+"' package.json | sed -n 's/.*[^0-9.]\([0-9.]*\)"/\1/p'))
303 $(eval MIN_NODE_VERSION := $(shell printf "%03d%03d%03d" $(shell echo '$(MIN_NODE_VERSION_STR)' | tr '.' ' ')))
304 $(eval NODE_VERSION := $(shell printf "%03d%03d%03d" $(shell node -v | cut -c2- | tr '.' ' ');))
305 $(eval NPM_MISSING := $(shell hash npm > /dev/null 2>&1 || echo 1))
306 @if [ "$(NODE_VERSION)" -lt "$(MIN_NODE_VERSION)" -o "$(NPM_MISSING)" = "1" ]; then \
307 echo "Forgejo requires Node.js $(MIN_NODE_VERSION_STR) or greater and npm to build. You can get it at https://nodejs.org/en/download/"; \
308 exit 1; \
309 fi
310
311###
312# Basic maintenance, check and lint targets
313###
314
315.PHONY: clean-all
316clean-all: clean
317 rm -rf $(WEBPACK_DEST_ENTRIES) node_modules
318
319.PHONY: clean
320clean:
321 rm -rf $(EXECUTABLE) $(DIST) $(BINDATA_DEST) $(BINDATA_HASH) \
322 integrations*.test \
323 e2e*.test \
324 tests/integration/gitea-integration-* \
325 tests/integration/indexers-* \
326 tests/mysql.ini tests/pgsql.ini man/ \
327 tests/e2e/gitea-e2e-*/ \
328 tests/e2e/indexers-*/ \
329 tests/e2e/reports/ tests/e2e/test-artifacts/ tests/e2e/test-snapshots/
330
331.PHONY: fmt
332fmt:
333 @GOFUMPT_PACKAGE=$(GOFUMPT_PACKAGE) $(GO) run build/code-batch-process.go gitea-fmt -w '{file-list}'
334 $(eval TEMPLATES := $(shell find templates -type f -name '*.tmpl'))
335 @# strip whitespace after '{{' or '(' and before '}}' or ')' unless there is only
336 @# whitespace before it
337 @$(SED_INPLACE) \
338 -e 's/{{[ ]\{1,\}/{{/g' -e '/^[ ]\{1,\}}}/! s/[ ]\{1,\}}}/}}/g' \
339 -e 's/([ ]\{1,\}/(/g' -e '/^[ ]\{1,\})/! s/[ ]\{1,\})/)/g' \
340 $(TEMPLATES)
341
342.PHONY: fmt-check
343fmt-check: fmt
344 @git diff --exit-code --color=always $(GO_SOURCES) templates $(WEB_DIRS) \
345 || (code=$$?; echo "Please run 'make fmt' and commit the result"; exit $${code})
346
347.PHONY: $(TAGS_EVIDENCE)
348$(TAGS_EVIDENCE):
349 @mkdir -p $(MAKE_EVIDENCE_DIR)
350 @echo "$(TAGS)" > $(TAGS_EVIDENCE)
351
352ifneq "$(TAGS)" "$(shell cat $(TAGS_EVIDENCE) 2>/dev/null)"
353TAGS_PREREQ := $(TAGS_EVIDENCE)
354endif
355
356OAPI_CODEGEN_PACKAGE ?= github.com/deepmap/oapi-codegen/cmd/oapi-codegen@v1.12.4
357KIN_OPENAPI_CODEGEN_PACKAGE ?= github.com/getkin/kin-openapi/cmd/validate@v0.114.0
358FORGEJO_API_SERVER = routers/api/forgejo/v1/generated.go
359
360.PHONY: generate-forgejo-api
361generate-forgejo-api: $(FORGEJO_API_SPEC)
362 $(GO) run $(OAPI_CODEGEN_PACKAGE) -package v1 -generate chi-server,types $< > $(FORGEJO_API_SERVER)
363
364.PHONY: forgejo-api-check
365forgejo-api-check: generate-forgejo-api
366 @git diff --exit-code --color=always $(FORGEJO_API_SERVER) \
367 || (code=$$?; echo "Please run 'make generate-forgejo-api' and commit the result"; exit $${code})
368
369.PHONY: forgejo-api-validate
370forgejo-api-validate:
371 $(GO) run $(KIN_OPENAPI_CODEGEN_PACKAGE) $(FORGEJO_API_SPEC)
372
373.PHONY: generate-swagger
374generate-swagger: $(SWAGGER_SPEC)
375
376$(SWAGGER_SPEC): $(GO_SOURCES_NO_BINDATA)
377 $(GO) run $(SWAGGER_PACKAGE) generate spec -x "$(SWAGGER_EXCLUDE)" -o './$(SWAGGER_SPEC)'
378 $(SED_INPLACE) '$(SWAGGER_SPEC_S_TMPL)' './$(SWAGGER_SPEC)'
379 $(SED_INPLACE) $(SWAGGER_NEWLINE_COMMAND) './$(SWAGGER_SPEC)'
380 $(SED_INPLACE) '$(SWAGGER_SPEC_BRANDING)' './$(SWAGGER_SPEC)'
381 $(SED_INPLACE) '$(SWAGGER_SPEC_LICENSE)' './$(SWAGGER_SPEC)'
382
383.PHONY: swagger-check
384swagger-check: generate-swagger
385 @git diff --exit-code --color=always '$(SWAGGER_SPEC)' \
386 || (code=$$?; echo "Please run 'make generate-swagger' and commit the result"; exit $${code})
387
388.PHONY: swagger-validate
389swagger-validate:
390 $(SED_INPLACE) '$(SWAGGER_SPEC_S_JSON)' './$(SWAGGER_SPEC)'
391 $(GO) run $(SWAGGER_PACKAGE) validate './$(SWAGGER_SPEC)'
392 $(SED_INPLACE) '$(SWAGGER_SPEC_S_TMPL)' './$(SWAGGER_SPEC)'
393
394.PHONY: checks
395checks: checks-frontend checks-backend
396
397.PHONY: checks-frontend
398checks-frontend: lockfile-check svg-check
399
400.PHONY: checks-backend
401checks-backend: tidy-check swagger-check fmt-check swagger-validate security-check
402
403.PHONY: lint
404lint: lint-frontend lint-backend lint-spell
405
406.PHONY: lint-fix
407lint-fix: lint-frontend-fix lint-backend-fix lint-spell-fix
408
409.PHONY: lint-frontend
410lint-frontend: lint-js lint-css
411
412.PHONY: lint-frontend-fix
413lint-frontend-fix: lint-js-fix lint-css-fix
414
415.PHONY: lint-backend
416lint-backend: lint-go lint-go-vet lint-editorconfig lint-renovate lint-locale lint-locale-usage lint-disposable-emails
417
418.PHONY: lint-backend-fix
419lint-backend-fix: lint-go-fix lint-go-vet lint-editorconfig lint-disposable-emails-fix
420
421.PHONY: lint-codespell
422lint-codespell: deps-py
423 @poetry run codespell
424
425.PHONY: lint-codespell-fix
426lint-codespell-fix: deps-py
427 @poetry run codespell -w
428
429.PHONY: lint-codespell-fix-i
430lint-codespell-fix-i: deps-py
431 @poetry run codespell -w -i 3 -C 2
432
433.PHONY: lint-js
434lint-js: node_modules
435 npx eslint --color --max-warnings=0
436
437.PHONY: lint-js-fix
438lint-js-fix: node_modules
439 npx eslint --color --max-warnings=0 --fix
440
441.PHONY: lint-css
442lint-css: node_modules
443 npx stylelint --color --max-warnings=0 $(STYLELINT_FILES)
444
445.PHONY: lint-css-fix
446lint-css-fix: node_modules
447 npx stylelint --color --max-warnings=0 $(STYLELINT_FILES) --fix
448
449.PHONY: lint-swagger
450lint-swagger: node_modules
451 npx spectral lint -q -F hint $(SWAGGER_SPEC)
452
453.PHONY: lint-renovate
454lint-renovate: node_modules
455 npx --yes --package $(RENOVATE_NPM_PACKAGE) -- renovate-config-validator --strict > .lint-renovate 2>&1 || true
456 @if grep --quiet --extended-regexp -e '^( WARN:|ERROR:)' .lint-renovate ; then cat .lint-renovate ; rm .lint-renovate ; exit 1 ; fi
457 @rm .lint-renovate
458
459.PHONY: lint-locale
460lint-locale:
461 $(GO) run build/lint-locale/lint-locale.go
462
463.PHONY: lint-locale-usage
464lint-locale-usage:
465 $(GO) run build/lint-locale-usage/lint-locale-usage.go
466
467.PHONY: lint-md
468lint-md: node_modules
469 npx markdownlint docs *.md
470
471.PHONY: lint-spell
472lint-spell: lint-codespell
473 @go run $(MISSPELL_PACKAGE) -error $(SPELLCHECK_FILES)
474
475.PHONY: lint-spell-fix
476lint-spell-fix: lint-codespell-fix
477 @go run $(MISSPELL_PACKAGE) -w $(SPELLCHECK_FILES)
478
479RUN_DEADCODE = $(GO) run $(DEADCODE_PACKAGE) -generated=false -f='{{println .Path}}{{range .Funcs}}{{printf "\t%s\n" .Name}}{{end}}{{println}}' -test forgejo.org
480
481.PHONY: lint-go
482lint-go:
483 $(GO) run $(GOLANGCI_LINT_PACKAGE) run $(GOLANGCI_LINT_ARGS)
484 $(RUN_DEADCODE) > .cur-deadcode-out
485 @$(DIFF) .deadcode-out .cur-deadcode-out \
486 || (code=$$?; echo "Please run 'make lint-go-fix' and commit the result"; exit $${code})
487
488.PHONY: lint-go-fix
489lint-go-fix:
490 $(GO) run $(GOLANGCI_LINT_PACKAGE) run $(GOLANGCI_LINT_ARGS) --fix
491 $(RUN_DEADCODE) > .deadcode-out
492
493.PHONY: lint-go-vet
494lint-go-vet:
495 @echo "Running go vet..."
496 @$(GO) vet ./...
497
498.PHONY: lint-go-gopls
499lint-go-gopls:
500 @echo "Running gopls check..."
501 @GO=$(GO) GOPLS_PACKAGE=$(GOPLS_PACKAGE) tools/lint-go-gopls.sh $(GO_SOURCES_NO_BINDATA)
502
503.PHONY: lint-editorconfig
504lint-editorconfig:
505 $(GO) run $(EDITORCONFIG_CHECKER_PACKAGE) templates .forgejo/workflows
506
507.PHONY: lint-disposable-emails
508lint-disposable-emails:
509 $(GO) run build/generate-disposable-email.go -check -r $(DISPOSABLE_EMAILS_SHA)
510
511.PHONY: lint-disposable-emails-fix
512lint-disposable-emails-fix:
513 $(GO) run build/generate-disposable-email.go -r $(DISPOSABLE_EMAILS_SHA)
514
515.PHONY: lint-templates
516lint-templates: .venv node_modules
517 @node tools/lint-templates-svg.js
518 @poetry run djlint $(shell find templates -type f -iname '*.tmpl')
519
520.PHONY: lint-yaml
521lint-yaml: .venv
522 @poetry run yamllint -s .
523
524.PHONY: security-check
525security-check:
526 go run $(GOVULNCHECK_PACKAGE) -show color ./...
527
528###
529# Development and testing targets
530###
531
532.PHONY: watch
533watch:
534 @bash tools/watch.sh
535
536.PHONY: watch-frontend
537watch-frontend: node-check node_modules
538 @rm -rf $(WEBPACK_DEST_ENTRIES)
539 NODE_ENV=development npx webpack --watch --progress
540
541.PHONY: watch-backend
542watch-backend: go-check
543 GITEA_RUN_MODE=dev $(GO) run $(AIR_PACKAGE) -c .air.toml
544
545.PHONY: test
546test: test-frontend test-backend
547
548.PHONY: test-backend
549test-backend:
550 @echo "Running go test with $(GOTESTFLAGS) -tags '$(TEST_TAGS)'..."
551 @$(GOTEST) $(GOTESTFLAGS) -tags='$(TEST_TAGS)' $(GO_TEST_PACKAGES)
552
553.PHONY: test-remote-cacher
554test-remote-cacher:
555 @echo "Running go test with $(GOTESTFLAGS) -tags '$(TEST_TAGS)'..."
556 @$(GOTEST) $(GOTESTFLAGS) -tags='$(TEST_TAGS)' $(GO_TEST_REMOTE_CACHER_PACKAGES)
557
558.PHONY: test-frontend
559test-frontend: node_modules
560 npx vitest
561
562.PHONY: test-frontend-coverage
563test-frontend-coverage: node_modules
564 npx vitest --coverage --coverage.include 'web_src/**'
565
566.PHONY: test-check
567test-check:
568 @echo "Running test-check...";
569 @diff=$$(git status -s); \
570 if [ -n "$$diff" ]; then \
571 echo "make test-backend has changed files in the source tree:"; \
572 echo "$${diff}"; \
573 echo "You should change the tests to create these files in a temporary directory."; \
574 echo "Do not simply add these files to .gitignore"; \
575 exit 1; \
576 fi
577
578.PHONY: test\#%
579test\#%:
580 @echo "Running go test with -tags '$(TEST_TAGS)'..."
581 @$(GOTEST) $(GOTESTFLAGS) -tags='$(TEST_TAGS)' -run $(subst .,/,$*) $(GO_TEST_PACKAGES)
582
583.PHONY: coverage
584coverage:
585 grep '^\(mode: .*\)\|\(.*:[0-9]\+\.[0-9]\+,[0-9]\+\.[0-9]\+ [0-9]\+ [0-9]\+\)$$' coverage.out > coverage-bodged.out
586 grep '^\(mode: .*\)\|\(.*:[0-9]\+\.[0-9]\+,[0-9]\+\.[0-9]\+ [0-9]\+ [0-9]\+\)$$' integration.coverage.out > integration.coverage-bodged.out
587 $(GO) run build/gocovmerge.go integration.coverage-bodged.out coverage-bodged.out > coverage.all
588
589.PHONY: unit-test-coverage
590unit-test-coverage:
591 @echo "Running unit-test-coverage $(GOTESTFLAGS) -tags '$(TEST_TAGS)'..."
592 @$(GOTEST) $(GOTESTFLAGS) -timeout=20m -tags='$(TEST_TAGS)' -cover -coverprofile coverage.out $(GO_TEST_PACKAGES) && echo "\n==>\033[32m Ok\033[m\n" || exit 1
593
594.PHONY: tidy
595tidy:
596 $(eval MIN_GO_VERSION := $(shell grep -Eo '^go\s+[0-9]+\.[0-9.]+' go.mod | cut -d' ' -f2))
597 $(GO) mod tidy -compat=$(MIN_GO_VERSION)
598 @$(MAKE) --no-print-directory $(GO_LICENSE_FILE)
599
600vendor: go.mod go.sum
601 $(GO) mod vendor
602 @touch vendor
603
604.PHONY: tidy-check
605tidy-check: tidy
606 @git diff --exit-code --color=always go.mod go.sum $(GO_LICENSE_FILE) \
607 || (code=$$?; echo "Please run 'make tidy' and commit the result"; exit $${code})
608
609.PHONY: go-licenses
610go-licenses: $(GO_LICENSE_FILE)
611
612$(GO_LICENSE_FILE): go.mod go.sum
613 -$(GO) run $(GO_LICENSES_PACKAGE) save . --force --ignore forgejo.org --save_path=$(GO_LICENSE_TMP_DIR) 2>/dev/null
614 $(GO) run build/generate-go-licenses.go $(GO_LICENSE_TMP_DIR) $(GO_LICENSE_FILE)
615 @rm -rf $(GO_LICENSE_TMP_DIR)
616
617generate-ini-sqlite:
618 sed -e 's|{{REPO_TEST_DIR}}|${REPO_TEST_DIR}|g' \
619 -e 's|{{TEST_LOGGER}}|$(or $(TEST_LOGGER),test$(COMMA)file)|g' \
620 -e 's|{{TEST_TYPE}}|$(or $(TEST_TYPE),integration)|g' \
621 tests/sqlite.ini.tmpl > tests/sqlite.ini
622
623.PHONY: test-sqlite
624test-sqlite: integrations.sqlite.test generate-ini-sqlite
625 GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/sqlite.ini $(GOTESTCOMPILEDRUNPREFIX) ./integrations.sqlite.test $(GOTESTCOMPILEDRUNSUFFIX)
626
627.PHONY: test-sqlite\#%
628test-sqlite\#%: integrations.sqlite.test generate-ini-sqlite
629 GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/sqlite.ini $(GOTESTCOMPILEDRUNPREFIX) ./integrations.sqlite.test $(GOTESTCOMPILEDRUNSUFFIX) -test.run $(subst .,/,$*)
630
631.PHONY: test-sqlite-migration
632test-sqlite-migration: migrations.sqlite.test migrations.individual.sqlite.test
633
634generate-ini-mysql:
635 sed -e 's|{{TEST_MYSQL_HOST}}|${TEST_MYSQL_HOST}|g' \
636 -e 's|{{TEST_MYSQL_DBNAME}}|${TEST_MYSQL_DBNAME}|g' \
637 -e 's|{{TEST_MYSQL_USERNAME}}|${TEST_MYSQL_USERNAME}|g' \
638 -e 's|{{TEST_MYSQL_PASSWORD}}|${TEST_MYSQL_PASSWORD}|g' \
639 -e 's|{{REPO_TEST_DIR}}|${REPO_TEST_DIR}|g' \
640 -e 's|{{TEST_LOGGER}}|$(or $(TEST_LOGGER),test$(COMMA)file)|g' \
641 -e 's|{{TEST_TYPE}}|$(or $(TEST_TYPE),integration)|g' \
642 tests/mysql.ini.tmpl > tests/mysql.ini
643
644.PHONY: test-mysql
645test-mysql: integrations.mysql.test generate-ini-mysql
646 GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mysql.ini $(GOTESTCOMPILEDRUNPREFIX) ./integrations.mysql.test $(GOTESTCOMPILEDRUNSUFFIX)
647
648.PHONY: test-mysql\#%
649test-mysql\#%: integrations.mysql.test generate-ini-mysql
650 GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mysql.ini $(GOTESTCOMPILEDRUNPREFIX) ./integrations.mysql.test $(GOTESTCOMPILEDRUNSUFFIX) -test.run $(subst .,/,$*)
651
652.PHONY: test-mysql-migration
653test-mysql-migration: migrations.mysql.test migrations.individual.mysql.test
654
655generate-ini-pgsql:
656 sed -e 's|{{TEST_PGSQL_HOST}}|${TEST_PGSQL_HOST}|g' \
657 -e 's|{{TEST_PGSQL_DBNAME}}|${TEST_PGSQL_DBNAME}|g' \
658 -e 's|{{TEST_PGSQL_USERNAME}}|${TEST_PGSQL_USERNAME}|g' \
659 -e 's|{{TEST_PGSQL_PASSWORD}}|${TEST_PGSQL_PASSWORD}|g' \
660 -e 's|{{TEST_PGSQL_SCHEMA}}|${TEST_PGSQL_SCHEMA}|g' \
661 -e 's|{{REPO_TEST_DIR}}|${REPO_TEST_DIR}|g' \
662 -e 's|{{TEST_LOGGER}}|$(or $(TEST_LOGGER),test$(COMMA)file)|g' \
663 -e 's|{{TEST_TYPE}}|$(or $(TEST_TYPE),integration)|g' \
664 -e 's|{{TEST_STORAGE_TYPE}}|$(or $(TEST_STORAGE_TYPE),minio)|g' \
665 tests/pgsql.ini.tmpl > tests/pgsql.ini
666
667.PHONY: test-pgsql
668test-pgsql: integrations.pgsql.test generate-ini-pgsql
669 GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/pgsql.ini $(GOTESTCOMPILEDRUNPREFIX) ./integrations.pgsql.test $(GOTESTCOMPILEDRUNSUFFIX)
670
671.PHONY: test-pgsql\#%
672test-pgsql\#%: integrations.pgsql.test generate-ini-pgsql
673 GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/pgsql.ini $(GOTESTCOMPILEDRUNPREFIX) ./integrations.pgsql.test $(GOTESTCOMPILEDRUNSUFFIX) -test.run $(subst .,/,$*)
674
675.PHONY: test-pgsql-migration
676test-pgsql-migration: migrations.pgsql.test migrations.individual.pgsql.test
677
678.PHONY: playwright
679playwright: deps-frontend
680 npx playwright install $(PLAYWRIGHT_FLAGS)
681
682.PHONY: test-e2e%
683test-e2e%: TEST_TYPE ?= e2e
684 # Clear display env variable. Otherwise, chromium tests can fail.
685 DISPLAY=
686
687.PHONY: test-e2e
688test-e2e: test-e2e-sqlite
689
690.PHONY: test-e2e-sqlite
691test-e2e-sqlite: playwright e2e.sqlite.test generate-ini-sqlite
692 GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/sqlite.ini $(GOTESTCOMPILEDRUNPREFIX) ./e2e.sqlite.test $(GOTESTCOMPILEDRUNSUFFIX) -test.run TestE2e
693
694.PHONY: test-e2e-sqlite\#%
695test-e2e-sqlite\#%: playwright e2e.sqlite.test generate-ini-sqlite
696 GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/sqlite.ini $(GOTESTCOMPILEDRUNPREFIX) ./e2e.sqlite.test $(GOTESTCOMPILEDRUNSUFFIX) -test.run TestE2e/$*
697
698.PHONY: test-e2e-sqlite-firefox\#%
699test-e2e-sqlite-firefox\#%: playwright e2e.sqlite.test generate-ini-sqlite
700 GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/sqlite.ini PLAYWRIGHT_PROJECT=firefox $(GOTESTCOMPILEDRUNPREFIX) ./e2e.sqlite.test $(GOTESTCOMPILEDRUNSUFFIX) -test.run TestE2e/$*
701
702.PHONY: test-e2e-mysql
703test-e2e-mysql: playwright e2e.mysql.test generate-ini-mysql
704 GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mysql.ini $(GOTESTCOMPILEDRUNPREFIX) ./e2e.mysql.test $(GOTESTCOMPILEDRUNSUFFIX) -test.run TestE2e
705
706.PHONY: test-e2e-mysql\#%
707test-e2e-mysql\#%: playwright e2e.mysql.test generate-ini-mysql
708 GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mysql.ini $(GOTESTCOMPILEDRUNPREFIX) ./e2e.mysql.test $(GOTESTCOMPILEDRUNSUFFIX) -test.run TestE2e/$*
709
710.PHONY: test-e2e-pgsql
711test-e2e-pgsql: playwright e2e.pgsql.test generate-ini-pgsql
712 GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/pgsql.ini $(GOTESTCOMPILEDRUNPREFIX) ./e2e.pgsql.test $(GOTESTCOMPILEDRUNSUFFIX) -test.run TestE2e
713
714.PHONY: test-e2e-pgsql\#%
715test-e2e-pgsql\#%: playwright e2e.pgsql.test generate-ini-pgsql
716 GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/pgsql.ini $(GOTESTCOMPILEDRUNPREFIX) ./e2e.pgsql.test $(GOTESTCOMPILEDRUNSUFFIX) -test.run TestE2e/$*
717
718.PHONY: test-e2e-debugserver
719test-e2e-debugserver: e2e.sqlite.test generate-ini-sqlite
720 GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/sqlite.ini ./e2e.sqlite.test -test.run TestDebugserver -test.timeout 24h
721
722.PHONY: bench-sqlite
723bench-sqlite: integrations.sqlite.test generate-ini-sqlite
724 GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/sqlite.ini ./integrations.sqlite.test -test.cpuprofile=cpu.out -test.run DontRunTests -test.bench .
725
726.PHONY: bench-mysql
727bench-mysql: integrations.mysql.test generate-ini-mysql
728 GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mysql.ini ./integrations.mysql.test -test.cpuprofile=cpu.out -test.run DontRunTests -test.bench .
729
730.PHONY: bench-pgsql
731bench-pgsql: integrations.pgsql.test generate-ini-pgsql
732 GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/pgsql.ini ./integrations.pgsql.test -test.cpuprofile=cpu.out -test.run DontRunTests -test.bench .
733
734.PHONY: integration-test-coverage
735integration-test-coverage: integrations.cover.test generate-ini-mysql
736 GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mysql.ini ./integrations.cover.test -test.coverprofile=integration.coverage.out
737
738.PHONY: integration-test-coverage-sqlite
739integration-test-coverage-sqlite: integrations.cover.sqlite.test generate-ini-sqlite
740 GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/sqlite.ini ./integrations.cover.sqlite.test -test.coverprofile=integration.coverage.out
741
742integrations.mysql.test: git-check $(GO_SOURCES)
743 $(GOTEST) $(GOTESTFLAGS) -c forgejo.org/tests/integration -o integrations.mysql.test
744
745integrations.pgsql.test: git-check $(GO_SOURCES)
746 $(GOTEST) $(GOTESTFLAGS) -c forgejo.org/tests/integration -o integrations.pgsql.test
747
748integrations.sqlite.test: git-check $(GO_SOURCES)
749 $(GOTEST) $(GOTESTFLAGS) -c forgejo.org/tests/integration -o integrations.sqlite.test -tags '$(TEST_TAGS)'
750
751integrations.cover.test: git-check $(GO_SOURCES)
752 $(GOTEST) $(GOTESTFLAGS) -c forgejo.org/tests/integration -coverpkg $(shell echo $(GO_TEST_PACKAGES) | tr ' ' ',') -o integrations.cover.test
753
754integrations.cover.sqlite.test: git-check $(GO_SOURCES)
755 $(GOTEST) $(GOTESTFLAGS) -c forgejo.org/tests/integration -coverpkg $(shell echo $(GO_TEST_PACKAGES) | tr ' ' ',') -o integrations.cover.sqlite.test -tags '$(TEST_TAGS)'
756
757.PHONY: migrations.mysql.test
758migrations.mysql.test: $(GO_SOURCES) generate-ini-mysql
759 $(GOTEST) $(GOTESTFLAGS) -c forgejo.org/tests/integration/migration-test -o migrations.mysql.test
760 GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mysql.ini $(GOTESTCOMPILEDRUNPREFIX) ./migrations.mysql.test $(GOTESTCOMPILEDRUNSUFFIX)
761
762.PHONY: migrations.pgsql.test
763migrations.pgsql.test: $(GO_SOURCES) generate-ini-pgsql
764 $(GOTEST) $(GOTESTFLAGS) -c forgejo.org/tests/integration/migration-test -o migrations.pgsql.test
765 GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/pgsql.ini $(GOTESTCOMPILEDRUNPREFIX) ./migrations.pgsql.test $(GOTESTCOMPILEDRUNSUFFIX)
766
767.PHONY: migrations.sqlite.test
768migrations.sqlite.test: $(GO_SOURCES) generate-ini-sqlite
769 $(GOTEST) $(GOTESTFLAGS) -c forgejo.org/tests/integration/migration-test -o migrations.sqlite.test -tags '$(TEST_TAGS)'
770 GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/sqlite.ini $(GOTESTCOMPILEDRUNPREFIX) ./migrations.sqlite.test $(GOTESTCOMPILEDRUNSUFFIX)
771
772.PHONY: migrations.individual.mysql.test
773migrations.individual.mysql.test: $(GO_SOURCES)
774 for pkg in $(MIGRATION_PACKAGES); do \
775 GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mysql.ini $(GOTEST) $(GOTESTFLAGS) -tags '$(TEST_TAGS)' $$pkg || exit 1; \
776 done
777
778.PHONY: migrations.individual.sqlite.test\#%
779migrations.individual.sqlite.test\#%: $(GO_SOURCES) generate-ini-sqlite
780 GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/sqlite.ini $(GOTEST) $(GOTESTFLAGS) -tags '$(TEST_TAGS)' forgejo.org/models/migrations/$*
781
782.PHONY: migrations.individual.pgsql.test
783migrations.individual.pgsql.test: $(GO_SOURCES)
784 for pkg in $(MIGRATION_PACKAGES); do \
785 GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/pgsql.ini $(GOTEST) $(GOTESTFLAGS) -tags '$(TEST_TAGS)' $$pkg || exit 1;\
786 done
787
788.PHONY: migrations.individual.pgsql.test\#%
789migrations.individual.pgsql.test\#%: $(GO_SOURCES) generate-ini-pgsql
790 GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/pgsql.ini $(GOTEST) $(GOTESTFLAGS) -tags '$(TEST_TAGS)' forgejo.org/models/migrations/$*
791
792.PHONY: migrations.individual.sqlite.test
793migrations.individual.sqlite.test: $(GO_SOURCES) generate-ini-sqlite
794 for pkg in $(MIGRATION_PACKAGES); do \
795 GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/sqlite.ini $(GOTEST) $(GOTESTFLAGS) -tags '$(TEST_TAGS)' $$pkg || exit 1; \
796 done
797
798.PHONY: migrations.individual.sqlite.test\#%
799migrations.individual.sqlite.test\#%: $(GO_SOURCES) generate-ini-sqlite
800 GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/sqlite.ini $(GOTEST) $(GOTESTFLAGS) -tags '$(TEST_TAGS)' forgejo.org/models/migrations/$*
801
802e2e.mysql.test: $(GO_SOURCES)
803 $(GOTEST) $(GOTESTFLAGS) -c forgejo.org/tests/e2e -o e2e.mysql.test
804
805e2e.pgsql.test: $(GO_SOURCES)
806 $(GOTEST) $(GOTESTFLAGS) -c forgejo.org/tests/e2e -o e2e.pgsql.test
807
808e2e.sqlite.test: $(GO_SOURCES)
809 $(GOTEST) $(GOTESTFLAGS) -c forgejo.org/tests/e2e -o e2e.sqlite.test -tags '$(TEST_TAGS)'
810
811.PHONY: check
812check: test
813
814###
815# Production / build targets
816###
817
818.PHONY: install $(TAGS_PREREQ)
819install: $(wildcard *.go)
820 CGO_CFLAGS="$(CGO_CFLAGS)" $(GO) install -v -tags '$(TAGS)' -ldflags '$(LDFLAGS)'
821
822.PHONY: build
823build: frontend backend
824
825.PHONY: frontend
826frontend: $(WEBPACK_DEST)
827
828.PHONY: backend
829backend: go-check generate-backend $(EXECUTABLE)
830
831# 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
832.PHONY: generate
833generate: generate-backend
834
835.PHONY: generate-backend
836generate-backend: $(TAGS_PREREQ) generate-go
837
838.PHONY: generate-go
839generate-go: $(TAGS_PREREQ)
840 @echo "Running go generate..."
841 @CC= GOOS= GOARCH= CGO_ENABLED=0 $(GO) generate -tags '$(TAGS)' ./...
842
843.PHONY: merge-locales
844merge-locales:
845 @echo "NOT NEEDED: THIS IS A NOOP AS OF Forgejo 7.0 BUT KEPT FOR BACKWARD COMPATIBILITY"
846
847$(EXECUTABLE): $(GO_SOURCES) $(TAGS_PREREQ)
848 CGO_CFLAGS="$(CGO_CFLAGS)" $(GO) build $(GOFLAGS) $(EXTRA_GOFLAGS) -tags '$(TAGS)' -ldflags '$(LDFLAGS)' -o $@
849
850forgejo: $(EXECUTABLE)
851 ln -f $(EXECUTABLE) forgejo
852
853static-executable: $(GO_SOURCES) $(TAGS_PREREQ)
854 CGO_CFLAGS="$(CGO_CFLAGS)" $(GO) build $(GOFLAGS) $(EXTRA_GOFLAGS) -tags 'netgo osusergo $(TAGS)' -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -o $(EXECUTABLE)
855
856.PHONY: release
857release: frontend generate release-linux release-copy release-compress vendor release-sources release-check
858
859# just the sources, with all assets builtin and frontend resources generated
860sources-tarbal: frontend generate vendor release-sources release-check
861
862$(DIST_DIRS):
863 mkdir -p $(DIST_DIRS)
864
865.PHONY: release-linux
866release-linux: | $(DIST_DIRS)
867 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 forgejo-$(VERSION) .
868ifeq ($(CI),true)
869 cp /build/* $(DIST)/binaries
870endif
871
872.PHONY: release-darwin
873release-darwin: | $(DIST_DIRS)
874 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) .
875
876.PHONY: release-freebsd
877release-freebsd: | $(DIST_DIRS)
878 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) .
879
880.PHONY: release-copy
881release-copy: | $(DIST_DIRS)
882 cd $(DIST); for file in `find . -type f -name "*"`; do cp $${file} ./release/; done;
883
884.PHONY: release-check
885release-check: | $(DIST_DIRS)
886 cd $(DIST)/release/; for file in `find . -type f -name "*"`; do echo "checksumming $${file}" && $(SHASUM) `echo $${file} | sed 's/^..//'` > $${file}.sha256; done;
887
888.PHONY: release-compress
889release-compress: | $(DIST_DIRS)
890 cd $(DIST)/release/; for file in `find . -type f -name "*"`; do echo "compressing $${file}" && $(GO) run $(GXZ_PACKAGE) -k -9 $${file}; done;
891
892.PHONY: release-sources
893release-sources: | $(DIST_DIRS)
894 echo $(VERSION) > $(STORED_VERSION_FILE)
895# bsdtar needs a ^ to prevent matching subdirectories
896 $(eval EXCL := --exclude=$(shell tar --help | grep -q bsdtar && echo "^")./)
897# use transform to a add a release-folder prefix; in bsdtar the transform parameter equivalent is -s
898 $(eval TRANSFORM := $(shell tar --help | grep -q bsdtar && echo "-s '/^./forgejo-src-$(VERSION)/'" || echo "--transform 's|^./|forgejo-src-$(VERSION)/|'"))
899 tar $(addprefix $(EXCL),$(TAR_EXCLUDES)) $(TRANSFORM) -czf $(DIST)/release/forgejo-src-$(VERSION).tar.gz .
900 rm -f $(STORED_VERSION_FILE)
901
902.PHONY: release-docs
903release-docs: | $(DIST_DIRS) docs
904 tar -czf $(DIST)/release/gitea-docs-$(VERSION).tar.gz -C ./docs .
905
906.PHONY: reproduce-build
907reproduce-build:
908# Start building the Dockerfile with the RELEASE_VERSION tag set. GOPROXY is set
909# for convenience, because the default of the Dockerfile is `direct` which can be
910# quite slow.
911 @docker build --build-arg="RELEASE_VERSION=$(RELEASE_VERSION)" --build-arg="GOPROXY=$(shell $(GO) env GOPROXY)" --tag "forgejo-reproducibility" .
912 @id=$$(docker create forgejo-reproducibility); \
913 docker cp $$id:/app/gitea/gitea ./forgejo; \
914 docker rm -v $$id; \
915 docker image rm forgejo-reproducibility:latest
916
917.PHONY: reproduce-build\#%
918reproduce-build\#%:
919 @git switch -d "$*"
920# All the current variables are based on information before the git checkout happened.
921# Call the makefile again, so these variables are correct and can be used for building
922# a reproducible binary. Always execute git switch -, to go back to the previous branch.
923 @make reproduce-build; \
924 (code=$$?; git switch -; exit $${code})
925
926###
927# Dependency management
928###
929
930.PHONY: deps
931deps: deps-frontend deps-backend deps-tools deps-py
932
933.PHONY: deps-py
934deps-py: .venv
935
936.PHONY: deps-frontend
937deps-frontend: node_modules
938
939.PHONY: deps-backend
940deps-backend:
941 $(GO) mod download
942
943.PHONY: deps-tools
944deps-tools:
945 $(GO) install $(AIR_PACKAGE)
946 $(GO) install $(EDITORCONFIG_CHECKER_PACKAGE)
947 $(GO) install $(GOFUMPT_PACKAGE)
948 $(GO) install $(GOLANGCI_LINT_PACKAGE)
949 $(GO) install $(GXZ_PACKAGE)
950 $(GO) install $(MISSPELL_PACKAGE)
951 $(GO) install $(SWAGGER_PACKAGE)
952 $(GO) install $(XGO_PACKAGE)
953 $(GO) install $(GO_LICENSES_PACKAGE)
954 $(GO) install $(GOVULNCHECK_PACKAGE)
955 $(GO) install $(GOMOCK_PACKAGE)
956 $(GO) install $(GOPLS_PACKAGE)
957
958node_modules: package-lock.json
959 npm install --no-save
960 @touch node_modules
961
962.venv: poetry.lock
963 poetry install
964 @touch .venv
965
966.PHONY: fomantic
967fomantic:
968 rm -rf $(FOMANTIC_WORK_DIR)/build
969 cd $(FOMANTIC_WORK_DIR) && npm install --no-save
970 cp -f $(FOMANTIC_WORK_DIR)/theme.config.less $(FOMANTIC_WORK_DIR)/node_modules/fomantic-ui/src/theme.config
971 cp -rf $(FOMANTIC_WORK_DIR)/_site $(FOMANTIC_WORK_DIR)/node_modules/fomantic-ui/src/
972 $(SED_INPLACE) -e 's/ overrideBrowserslist\r/ overrideBrowserslist: ["defaults"]\r/g' $(FOMANTIC_WORK_DIR)/node_modules/fomantic-ui/tasks/config/tasks.js
973 cd $(FOMANTIC_WORK_DIR) && npx gulp -f node_modules/fomantic-ui/gulpfile.js build
974 # fomantic uses "touchstart" as click event for some browsers, it's not ideal, so we force fomantic to always use "click" as click event
975 $(SED_INPLACE) -e 's/clickEvent[ \t]*=/clickEvent = "click", unstableClickEvent =/g' $(FOMANTIC_WORK_DIR)/build/semantic.js
976 $(SED_INPLACE) -e 's/\r//g' $(FOMANTIC_WORK_DIR)/build/semantic.css $(FOMANTIC_WORK_DIR)/build/semantic.js
977 rm -f $(FOMANTIC_WORK_DIR)/build/*.min.*
978
979.PHONY: webpack
980webpack: $(WEBPACK_DEST)
981
982$(WEBPACK_DEST): $(WEBPACK_SOURCES) $(WEBPACK_CONFIGS) package-lock.json
983 @$(MAKE) -s node-check node_modules
984 @rm -rf $(WEBPACK_DEST_ENTRIES)
985 @echo "Running webpack..."
986 @BROWSERSLIST_IGNORE_OLD_DATA=true npx webpack
987 @touch $(WEBPACK_DEST)
988
989.PHONY: svg
990svg: node-check | node_modules
991 rm -rf $(SVG_DEST_DIR)
992 node tools/generate-svg.js
993
994.PHONY: svg-check
995svg-check: svg
996 @git add $(SVG_DEST_DIR)
997 @git diff --exit-code --color=always --cached $(SVG_DEST_DIR) \
998 || (code=$$?; echo "Please run 'make svg' and commit the result"; exit $${code})
999
1000.PHONY: lockfile-check
1001lockfile-check:
1002 npm install --package-lock-only
1003 @git diff --exit-code --color=always package-lock.json \
1004 || (code=$$?; echo "Please run 'npm install --package-lock-only' and commit the result"; exit $${code})
1005
1006.PHONY: generate-license
1007generate-license:
1008 $(GO) run build/generate-licenses.go
1009
1010.PHONY: generate-gitignore
1011generate-gitignore:
1012 $(GO) run build/generate-gitignores.go
1013
1014.PHONY: generate-gomock
1015generate-gomock:
1016 $(GO) run $(GOMOCK_PACKAGE) -package mock -destination ./modules/queue/mock/redisuniversalclient.go forgejo.org/modules/nosql RedisClient
1017
1018.PHONY: generate-images
1019generate-images: | node_modules
1020 node tools/generate-images.js
1021
1022.PHONY: generate-manpage
1023generate-manpage:
1024 @[ -f gitea ] || make backend
1025 @mkdir -p man/man1/ man/man5
1026 @./gitea docs --man > man/man1/gitea.1
1027 @gzip -9 man/man1/gitea.1 && echo man/man1/gitea.1.gz created
1028 @#TODO A small script that formats config-cheat-sheet.en-us.md nicely for use as a config man page
1029
1030# This endif closes the if at the top of the file
1031endif
1032
1033# Disable parallel execution because it would break some targets that don't
1034# specify exact dependencies like 'backend' which does currently not depend
1035# on 'frontend' to enable Node.js-less builds from source tarballs.
1036.NOTPARALLEL: