-
-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathMakefile
More file actions
123 lines (110 loc) · 4.64 KB
/
Makefile
File metadata and controls
123 lines (110 loc) · 4.64 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
.PHONY: build test clean run build-release test-coverage lint fmt deps help coverage coverage-check
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'" -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'" -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:
go vet ./...
@command -v golint >/dev/null 2>&1 && golint ./... || echo "golint not installed"
# 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
# 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"