-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathMakefile
More file actions
93 lines (79 loc) · 2.84 KB
/
Copy pathMakefile
File metadata and controls
93 lines (79 loc) · 2.84 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
.PHONY: help build test test-coverage fmt lint vet tidy clean find-deadcode staticcheck check eval eval-check-deps
help:
@echo "Available targets:"
@echo " build - Build the acr binary with version information"
@echo " test - Run all unit tests"
@echo " test-coverage - Run tests with coverage"
@echo " fmt - Format Go source code"
@echo " lint - Run golangci-lint v2"
@echo " vet - Run go vet"
@echo " tidy - Tidy go modules"
@echo " clean - Clean build artifacts and test cache"
@echo " find-deadcode - Run dead code analysis"
@echo " staticcheck - Run staticcheck"
@echo " check - Run all quality checks (fmt, lint, vet, staticcheck, tests)"
@echo " eval - Run eval tests (requires bats-core)"
build:
@echo "Building acr with version information..."
@mkdir -p bin
@VERSION=$$(git describe --tags --always --dirty 2>/dev/null || echo "dev"); \
COMMIT=$$(git rev-parse --short HEAD 2>/dev/null || echo "none"); \
DATE=$$(date -u +"%Y-%m-%dT%H:%M:%SZ"); \
if ! go build -ldflags "-X main.version=$$VERSION -X main.commit=$$COMMIT -X main.date=$$DATE" -o bin/acr ./cmd/acr; then \
echo "Build failed"; \
exit 1; \
fi; \
echo "Built versioned acr binary to bin/ (version: $$VERSION)"
test:
@echo "Running unit tests..."
@go test ./...
@echo "Unit tests passed!"
test-coverage:
@echo "Running unit tests with coverage..."
@go clean -testcache
@go test -covermode=atomic -coverprofile=coverage.out ./...
@go tool cover -func=coverage.out > coverage.txt
@awk 'END{printf "Total coverage: %s\n", $$3}' coverage.txt
@go tool cover -html=coverage.out -o coverage.html
@echo "Unit tests passed! Coverage report: coverage.html (see also coverage.txt)"
fmt:
@echo "Formatting Go source code..."
@go fmt ./...
@echo "Formatting complete!"
lint:
@echo "Running golangci-lint v2..."
@go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.8.0 run --timeout=10m ./...
@echo "Linting passed!"
vet:
@echo "Running go vet..."
@go vet ./...
@echo "Vet passed!"
tidy:
@echo "Tidying go modules..."
@go mod tidy
@echo "Modules tidied!"
clean:
@echo "Cleaning build artifacts and caches..."
@rm -rf bin
@rm -f coverage.out coverage.html coverage.txt
@go clean
@go clean -testcache
@echo "Build artifacts and test cache cleaned"
find-deadcode:
@echo "Search for dead code..."
@go run golang.org/x/tools/cmd/deadcode@latest ./...
@echo "Done"
staticcheck:
@echo "Running staticcheck..."
@go run honnef.co/go/tools/cmd/staticcheck@latest ./...
@echo "Staticcheck passed!"
check: fmt lint vet staticcheck test
eval-check-deps:
@command -v bats >/dev/null 2>&1 || { \
echo "bats-core is required but not installed."; \
echo "Install with: brew install bats-core"; \
exit 1; \
}
eval: eval-check-deps build
@echo "Running eval tests..."
@bats bats/tests/