-
Notifications
You must be signed in to change notification settings - Fork 72
Expand file tree
/
Copy pathMakefile
More file actions
111 lines (92 loc) · 3.06 KB
/
Makefile
File metadata and controls
111 lines (92 loc) · 3.06 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
.PHONY: build install install-dev test test-v clean check-clean tag goreleaser-snapshot fmt fmt-check fmt-check-all lint lint-all
# Default target
all: build
LINT_BASE ?= main
# Build the binary
build:
go build -o bin/sidecar ./cmd/sidecar
# Install to GOBIN
install:
go install ./cmd/sidecar
# Install with version info from git
install-dev:
$(eval VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev"))
@echo "Installing sidecar with Version=$(VERSION)"
go install -ldflags "-X main.Version=$(VERSION)" ./cmd/sidecar
# Run tests
test:
go test ./...
# Run tests with verbose output
test-v:
go test -v ./...
# Clean build artifacts
clean:
rm -rf bin/
go clean
# Check for clean working tree
check-clean:
@if [ -n "$$(git status --porcelain)" ]; then \
echo "Error: Working tree is not clean"; \
git status --short; \
exit 1; \
fi
# Create a new version tag
# Usage: make tag VERSION=v0.1.0
tag: check-clean
ifndef VERSION
$(error VERSION is required. Usage: make tag VERSION=v0.1.0)
endif
@if ! echo "$(VERSION)" | grep -qE '^v[0-9]+\.[0-9]+\.[0-9]+$$'; then \
echo "Error: VERSION must match vX.Y.Z format (got: $(VERSION))"; \
exit 1; \
fi
@echo "Creating tag $(VERSION)"
git tag -a $(VERSION) -m "Release $(VERSION)"
@echo "Tag $(VERSION) created. Run 'git push origin $(VERSION)' to trigger the release."
# Show version that would be used
version:
@git describe --tags --always --dirty 2>/dev/null || echo "dev"
# Format code
fmt:
go fmt ./...
# Check formatting for changed Go files only (merge-base with LINT_BASE)
fmt-check:
@files="$$(git diff --name-only --diff-filter=ACMRTUXB $(LINT_BASE)...HEAD -- '*.go')"; \
if [ -z "$$files" ]; then \
echo "No changed Go files to check."; \
exit 0; \
fi; \
unformatted="$$(echo "$$files" | xargs gofmt -l)"; \
if [ -n "$$unformatted" ]; then \
echo "Unformatted changed Go files:"; \
echo "$$unformatted"; \
exit 1; \
fi
# Check formatting across all Go files
fmt-check-all:
@unformatted="$$(find . -name '*.go' -not -path './vendor/*' -not -path './website/*' -print0 | xargs -0 gofmt -l)"; \
if [ -n "$$unformatted" ]; then \
echo "Unformatted Go files:"; \
echo "$$unformatted"; \
exit 1; \
fi
# Run linter
lint:
golangci-lint run --new-from-merge-base=$(LINT_BASE) ./...
# Run linter across the full codebase (includes legacy debt)
lint-all:
golangci-lint run ./...
# Build for multiple platforms (local testing only — GoReleaser handles release builds)
build-all:
GOOS=darwin GOARCH=amd64 go build -o bin/sidecar-darwin-amd64 ./cmd/sidecar
GOOS=darwin GOARCH=arm64 go build -o bin/sidecar-darwin-arm64 ./cmd/sidecar
GOOS=linux GOARCH=amd64 go build -o bin/sidecar-linux-amd64 ./cmd/sidecar
GOOS=linux GOARCH=arm64 go build -o bin/sidecar-linux-arm64 ./cmd/sidecar
# Test GoReleaser locally (creates snapshot build without publishing)
goreleaser-snapshot:
goreleaser release --snapshot --clean
# Install pre-commit hooks
install-hooks:
@chmod +x scripts/pre-commit.sh
@ln -sf ../../scripts/pre-commit.sh .git/hooks/pre-commit
@echo "✅ pre-commit hook installed"