Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
150 lines (134 loc) · 5.98 KB
/
Copy pathMakefile
File metadata and controls
150 lines (134 loc) · 5.98 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
.PHONY: build test clean run build-release test-coverage lint fmt deps help coverage coverage-check hooks
COVERAGE_THRESHOLD ?= 50.0
TOOLCHAIN_FROM_MOD := $(shell awk '/^toolchain /{print $$2}' go.mod 2>/dev/null)
COVER_GOTOOLCHAIN := $(if $(TOOLCHAIN_FROM_MOD),$(TOOLCHAIN_FROM_MOD)+auto,auto)
# Build del progetto
build:
@echo "Building proxsave..."
@VERSION=$$( \
if git describe --tags --exact-match >/dev/null 2>&1 && [ -z "$$(git status --porcelain 2>/dev/null)" ]; then \
git describe --tags --abbrev=0 2>/dev/null || echo 0.0.0-dev; \
else \
desc=$$(git describe --tags --long --dirty --always 2>/dev/null || echo dev); \
dirty=""; \
case "$$desc" in *-dirty) dirty=".dirty"; desc=$${desc%-dirty};; esac; \
sha_part=$${desc##*-}; \
sha=$${sha_part#g}; \
rest=$${desc%-*}; \
n=$${rest##*-}; \
tag=$${rest%-*}; \
if [ "$$tag" = "$$desc" ] || [ -z "$$n" ] || [ -z "$$sha" ] || [ "$$sha_part" = "$$desc" ]; then \
echo "0.0.0-dev.0+g$${desc}$$dirty"; \
else \
echo "$$tag-dev.$$n+g$$sha$$dirty"; \
fi; \
fi \
); \
COMMIT=$$(git rev-parse --short HEAD 2>/dev/null || echo dev); \
BUILD_TIME=$$(date -u +"%Y-%m-%dT%H:%M:%SZ"); \
go build -ldflags="-X 'main.buildTime=$$BUILD_TIME' -X 'github.com/tis24dev/proxsave/internal/version.Version=$$VERSION' -X 'github.com/tis24dev/proxsave/internal/version.Commit=$$COMMIT' -X 'github.com/tis24dev/proxsave/internal/version.Date=$$BUILD_TIME' -X 'github.com/tis24dev/proxsave/internal/support.supportEmail=$$EMAIL_SUPPORT'" -o build/proxsave ./cmd/proxsave
# Build ottimizzato per release
build-release:
@echo "Building release..."
@VERSION=$$( \
if git describe --tags --exact-match >/dev/null 2>&1 && [ -z "$$(git status --porcelain 2>/dev/null)" ]; then \
git describe --tags --abbrev=0 2>/dev/null || echo 0.0.0-dev; \
else \
desc=$$(git describe --tags --long --dirty --always 2>/dev/null || echo dev); \
dirty=""; \
case "$$desc" in *-dirty) dirty=".dirty"; desc=$${desc%-dirty};; esac; \
sha_part=$${desc##*-}; \
sha=$${sha_part#g}; \
rest=$${desc%-*}; \
n=$${rest##*-}; \
tag=$${rest%-*}; \
if [ "$$tag" = "$$desc" ] || [ -z "$$n" ] || [ -z "$$sha" ] || [ "$$sha_part" = "$$desc" ]; then \
echo "0.0.0-dev.0+g$${desc}$$dirty"; \
else \
echo "$$tag-dev.$$n+g$$sha$$dirty"; \
fi; \
fi \
); \
COMMIT=$$(git rev-parse --short HEAD 2>/dev/null || echo dev); \
BUILD_TIME=$$(date -u +"%Y-%m-%dT%H:%M:%SZ"); \
go build -ldflags="-s -w -X 'main.buildTime=$$BUILD_TIME' -X 'github.com/tis24dev/proxsave/internal/version.Version=$$VERSION' -X 'github.com/tis24dev/proxsave/internal/version.Commit=$$COMMIT' -X 'github.com/tis24dev/proxsave/internal/version.Date=$$BUILD_TIME' -X 'github.com/tis24dev/proxsave/internal/support.supportEmail=$$EMAIL_SUPPORT'" -o build/proxsave ./cmd/proxsave
# Test
test:
go test -v ./...
# Test con coverage
test-coverage:
GOTOOLCHAIN=$(COVER_GOTOOLCHAIN) go test -coverprofile=coverage.out ./...
GOTOOLCHAIN=$(COVER_GOTOOLCHAIN) go tool cover -html=coverage.out
# Full coverage report (all packages)
coverage:
@echo "Running coverage across all packages..."
@GOTOOLCHAIN=$(COVER_GOTOOLCHAIN) go test -coverpkg=./... -coverprofile=coverage.out ./...
@GOTOOLCHAIN=$(COVER_GOTOOLCHAIN) go tool cover -func=coverage.out | tail -n 1
# Enforce minimum coverage threshold
coverage-check:
@echo "Running coverage check (threshold $(COVERAGE_THRESHOLD)% )..."
@GOTOOLCHAIN=$(COVER_GOTOOLCHAIN) go test -coverpkg=./... -coverprofile=coverage.out ./...
@total=$$(GOTOOLCHAIN=$(COVER_GOTOOLCHAIN) go tool cover -func=coverage.out | grep total: | awk '{print $$3}' | sed 's/%//'); \
echo "Total coverage: $$total%"; \
if awk -v total="$$total" -v threshold="$(COVERAGE_THRESHOLD)" 'BEGIN { exit !(total+0 >= threshold+0) }'; then \
echo "Coverage check passed."; \
else \
echo "Coverage threshold not met (need >= $(COVERAGE_THRESHOLD)% )."; \
exit 1; \
fi
# Lint
lint: check-no-tview check-serverbot-leaf
go vet ./...
@if command -v golangci-lint >/dev/null 2>&1; then \
golangci-lint run ./...; \
else \
echo "golangci-lint not installed"; \
fi
# Guard: the legacy tview/tcell stack was excised (Charm UI replaced it);
# any reappearance is a regression.
check-no-tview:
@if grep -rn "rivo/tview\|gdamore/tcell" --include="*.go" cmd internal pkg 2>/dev/null; then \
echo "ERROR: legacy tview/tcell reference found (the Charm UI replaced them)"; \
exit 1; \
fi
# Guard: internal/serverbot must stay a transport leaf (only logging/version/stdlib).
# Importing health/notify/orchestrator/config/identity would create an import cycle
# and pull endpoint vocabulary back into the shared transport.
check-serverbot-leaf:
@if grep -rEn "tis24dev/proxsave/internal/(health|notify|orchestrator|config|identity)" internal/serverbot/ 2>/dev/null; then \
echo "ERROR: internal/serverbot must not import health/notify/orchestrator/config/identity (leaf transport)"; \
exit 1; \
fi
# Format code
fmt:
go fmt ./...
# Clean build artifacts
clean:
rm -rf build/
rm -f coverage.out
# Run in development
run:
go run ./cmd/proxsave
# Install/update dependencies
deps:
go mod download
go mod tidy
# Enable the local Trojan-source pre-commit hook (CI enforces it regardless).
hooks:
@git config core.hooksPath .githooks
@echo "core.hooksPath set to .githooks; pre-commit Trojan-source guard enabled."
# Help
help:
@echo "Available targets:"
@echo " build - Build the project"
@echo " build-release - Build optimized release binary"
@echo " test - Run tests"
@echo " test-coverage - Run tests with coverage report"
@echo " coverage - Generate coverage profile across all packages"
@echo " coverage-check - Run coverage and enforce minimum threshold"
@echo " lint - Run linters"
@echo " fmt - Format Go code"
@echo " clean - Remove build artifacts"
@echo " run - Run in development mode"
@echo " deps - Download and tidy dependencies"
@echo " hooks - Enable the local pre-commit Trojan-source guard"