-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
83 lines (64 loc) · 2.5 KB
/
Makefile
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
81
82
83
.PHONY: all build test tidy clean pretty install install-tools lint install-hooks
.DEFAULT_GOAL := test_and_build
REQUIRED_GO_VERSION := 1.23
GOLANGCI_LINT_VERSION := v1.62.0
# Determine the Go binary directory
GOBIN_DIR := $(or $(GOBIN), $(shell go env GOBIN))
ifeq ($(GOBIN_DIR),)
GOBIN_DIR := $(shell go env GOPATH)/bin
endif
test_and_build: test build
# Version check
check_version:
@GO_VERSION=$$(go version | awk '{print $$3}' | sed 's/go//'); \
MAJOR_VERSION=$$(echo $$GO_VERSION | cut -d. -f1); \
MINOR_VERSION=$$(echo $$GO_VERSION | cut -d. -f2); \
if [ "$$MAJOR_VERSION" -eq 1 ] && [ "$$MINOR_VERSION" -lt 23 ]; then \
echo "Error: Go version $(REQUIRED_GO_VERSION) or higher is required. Current version is $$GO_VERSION"; \
exit 1; \
else \
echo "Go version is acceptable: $$GO_VERSION"; \
fi
default: check_version build
build:
@echo "Building vt..."
@go build -o vt ./go/vt
test:
go test -count=1 ./go/...
tidy:
go mod tidy
clean:
go clean -i ./...
rm -f vt
# Pretty: formats the code using gofumpt and goimports-reviser
pretty: check-tools
@echo "Running formatting tools..."
@gofumpt -w . >/dev/null 2>&1
@goimports-reviser -recursive -project-name $$(go list -m) -rm-unused -set-alias ./go >/dev/null 2>&1
# Tools installation command
install-tools:
@echo "Installing gofumpt..."
go install mvdan.cc/gofumpt@latest
@echo "Installing goimports-reviser..."
go install github.com/incu6us/goimports-reviser/v3@latest
@echo "Installing golangci-lint..."
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | \
sh -s -- -b $(GOBIN_DIR) $(GOLANGCI_LINT_VERSION)
@echo "All tools installed successfully."
# Ensure tools are available
check-tools:
@command -v gofumpt >/dev/null 2>&1 || { echo "gofumpt not found. Run 'make install-tools' to install it." >&2; exit 1; }
@command -v goimports-reviser >/dev/null 2>&1 || { echo "goimports-reviser not found. Run 'make install-tools' to install it." >&2; exit 1; }
@command -v golangci-lint >/dev/null 2>&1 || { echo "golangci_lint not found. Run 'make install-tools' to install it." >&2; exit 1; }
# Lint: runs golangci-lint
lint: check-tools
@echo "Running golangci-lint..."
@golangci-lint run --config .golangci.yml ./go/...
install-hooks:
@echo "Installing Git hooks..."
@ln -sf ../../git-hooks/pre-commit .git/hooks/pre-commit
@chmod +x .git/hooks/pre-commit
@echo "Pre-commit hook installed successfully."
install: build
@install -m 0755 vt $(GOBIN_DIR)/vt
@echo "vt installed successfully to $(GOBIN_DIR)."