File: Makefile

package info (click to toggle)
golang-code.forgejo-f3-gof3 3.11.0-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 1,952 kB
  • sloc: sh: 100; makefile: 65
file content (80 lines) | stat: -rw-r--r-- 3,246 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
GO ?= $(shell go env GOROOT)/bin/go

DIFF ?= diff --unified

EDITORCONFIG_CHECKER_PACKAGE ?= github.com/editorconfig-checker/editorconfig-checker/v3/cmd/editorconfig-checker@v3.3.0 # renovate: datasource=go
GOFUMPT_PACKAGE ?= mvdan.cc/gofumpt@v0.8.0 # renovate: datasource=go
GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.1.6 # renovate: datasource=go
UNCOVER_PACKAGE ?= github.com/gregoryv/uncover/cmd/uncover@latest
MISSPELL_PACKAGE ?= github.com/golangci/misspell/cmd/misspell@v0.7.0 # renovate: datasource=go
DEADCODE_PACKAGE ?= golang.org/x/tools/cmd/deadcode@v0.33.0 # renovate: datasource=go
GOMOCK_PACKAGE ?= go.uber.org/mock/mockgen@v0.5.2 # renovate: datasource=go

SCHEMAS_VERSION ?= v4

DEADCODE_ARGS ?= -generated=false -test -f='{{println .Path}}{{range .Funcs}}{{printf "\t%s\n" .Name}}{{end}}{{println}}' code.forgejo.org/f3/gof3/v3/...

VERSION ?= $(shell git describe --tags --always | sed 's/-/+/' | sed 's/^v//')

LDFLAGS := $(LDFLAGS) -X "code.forgejo.org/f3/gof3/v3/cmd.Version=$(VERSION)"

EXECUTABLE := f3-cli

GO_DIRS = cmd f3 forges logger main options tree util
GO_SOURCES = $(shell find $(GO_DIRS) -type f -name "*.go")

$(EXECUTABLE): $(GO_SOURCES)
	$(GO) build -tags 'netgo osusergo' -ldflags '-extldflags -static -s -w $(LDFLAGS)' -o $@ code.forgejo.org/f3/gof3/v3/main

.PHONY: deps-backend
deps-backend:
	$(GO) mod download
	$(GO) install $(GOFUMPT_PACKAGE)
	$(GO) install $(EDITORCONFIG_CHECKER_PACKAGE)
	$(GO) install $(GOLANGCI_LINT_PACKAGE)
	$(GO) install $(UNCOVER_PACKAGE)
	$(GO) install $(MISSPELL_PACKAGE)
	$(GO) install $(DEADCODE_PACKAGE)
	$(GO) install $(GOMOCK_PACKAGE)

.PHONY: lint
lint:
	@if ! $(MAKE) lint-run ; then echo "Please run 'make lint-fix' and commit the result" ; exit 1 ; fi

.PHONY: lint-run
lint-run: lint-schemas lint-editorconfig
	$(GO) run $(GOLANGCI_LINT_PACKAGE) run $(GOLANGCI_LINT_ARGS)
	$(GO) run $(DEADCODE_PACKAGE) $(DEADCODE_ARGS) > .cur-deadcode-out
	$(DIFF) .deadcode-out .cur-deadcode-out

.PHONY: lint-editorconfig
lint-editorconfig:
	$(GO) run $(EDITORCONFIG_CHECKER_PACKAGE) --exclude '.*~$$' .forgejo/workflows

.PHONY: lint-schemas
lint-schemas:
	status=0 ; for schema in f3/schemas/*.json ; do if ! jq '.|empty' $$schema ; then status=1 ; echo $$schema error ; fi ; done ; exit $$status
	d=`mktemp -d` ; trap "rm -fr $$d" EXIT ; git clone --quiet https://code.forgejo.org/f3/f3-schemas $$d/schemas ; ( cd $$d/schemas ; git checkout --quiet $(SCHEMAS_VERSION) ) ; diff --exclude '.*' -ru $$d/schemas f3/schemas

.PHONY: lint-schemas-fix
lint-schemas-fix:
	d=`mktemp -d` ; trap "rm -fr $$d" EXIT ; git clone --quiet https://code.forgejo.org/f3/f3-schemas $$d/schemas ; ( cd $$d/schemas ; git checkout --quiet $(SCHEMAS_VERSION) ) ; cp $$d/schemas/* f3/schemas

.PHONY: lint-fix
lint-fix: lint-schemas-fix
	$(GO) run $(GOLANGCI_LINT_PACKAGE) run $(GOLANGCI_LINT_ARGS) --fix
	$(GO) run $(DEADCODE_PACKAGE) $(DEADCODE_ARGS) > .deadcode-out

.PHONY: fmt
fmt:
	GOFUMPT_PACKAGE=$(GOFUMPT_PACKAGE) gofumpt -extra -w .

SPELLCHECK_FILES = $(GO_DIRS)

.PHONY: lint-spell
lint-spell:
	@$(GO) run $(MISSPELL_PACKAGE) -error $(SPELLCHECK_FILES)

.PHONY: lint-spell-fix
lint-spell-fix:
	@$(GO) run $(MISSPELL_PACKAGE) -w $(SPELLCHECK_FILES)