This repository was archived by the owner on Sep 2, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
216 lines (190 loc) · 6.52 KB
/
Copy pathMakefile
File metadata and controls
216 lines (190 loc) · 6.52 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
.PHONY: all build test lint fmt clean fuzz fuzz-short fuzz-long benchmark cover release release-verify checksum sign help
# Variables
GO := go
GOFLAGS := -v
VERSION := $(shell grep -oP 'Version = "\K[^"]+' internal/version/version.go 2>/dev/null || echo "0.1.0")
BINARY_NAME := lattice
SERVER_BINARY_NAME := lattice-server
PREFIX := .
CMD_DIR := $(PREFIX)/cmd
BUILD_DIR := $(PREFIX)/bin
DIST_DIR := $(PREFIX)/dist
COVERAGE_DIR := $(PREFIX)/coverage
# all builds everything
all: build
# build compiles all packages
build:
@echo "Building..."
@mkdir -p $(BUILD_DIR)
$(GO) build $(GOFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME) $(CMD_DIR)/lattice
$(GO) build $(GOFLAGS) -o $(BUILD_DIR)/$(SERVER_BINARY_NAME) $(CMD_DIR)/lattice-server
# test runs all tests
test:
@echo "Running tests..."
$(GO) test -race -count=1 ./...
# test-verbose runs tests with verbose output
test-verbose:
@echo "Running tests (verbose)..."
$(GO) test -v -race -count=1 ./...
# cover runs tests with coverage
cover:
@echo "Running tests with coverage..."
@mkdir -p $(COVERAGE_DIR)
$(GO) test -race -coverprofile=$(COVERAGE_DIR)/coverage.out -covermode=atomic ./...
$(GO) tool cover -html=$(COVERAGE_DIR)/coverage.out -o $(COVERAGE_DIR)/coverage.html
@echo "Coverage report: $(COVERAGE_DIR)/coverage.html"
# lint runs all linters
lint:
@echo "Running linters..."
@if command -v golangci-lint >/dev/null 2>&1; then \
golangci-lint run ./...; \
else \
echo "golangci-lint not installed. Run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest"; \
exit 1; \
fi
# fmt formats code and checks for formatting issues
fmt:
@echo "Formatting code..."
@if command -v gofumpt >/dev/null 2>&1; then \
gofumpt -w -extra .; \
else \
echo "gofumpt not installed. Run: go install mvdan.cc/gofumpt@latest"; \
fi
$(GO) fmt ./...
# fmt-check checks if code is formatted
fmt-check:
@echo "Checking formatting..."
@if command -v gofumpt >/dev/null 2>&1; then \
gofumpt -extra -l . | grep -q . && echo "Code is not formatted. Run 'make fmt'" && exit 1 || true; \
fi
# vet runs go vet
vet:
@echo "Running go vet..."
$(GO) vet ./...
# clean removes build artifacts
clean:
@echo "Cleaning..."
rm -rf $(BUILD_DIR)
rm -rf $(COVERAGE_DIR)
rm -rf $(PREFIX)/testdata/corpora
# fuzz runs fuzz tests for a short time
fuzz-short:
@echo "Running fuzz tests (short)..."
$(GO) test -fuzz=Fuzz -fuzztime=10s ./...
# fuzz runs fuzz tests for a long time
fuzz-long:
@echo "Running fuzz tests (long)..."
$(GO) test -fuzz=Fuzz -fuzztime=5m ./...
# fuzz generates corpora for fuzz tests
fuzz-generate:
@echo "Generating fuzz corpora..."
@mkdir -p $(PREFIX)/testdata/corpora
$(GO) test -fuzz=Fuzz -fuzztime=30s ./...
# benchmark runs benchmarks
benchmark:
@echo "Running benchmarks..."
$(GO) test -bench=. -benchmem ./...
# race runs tests with race detector
race:
@echo "Running tests with race detector..."
$(GO) test -race -count=1 ./...
# deps verifies dependencies
deps:
@echo "Verifying dependencies..."
$(GO) mod verify
$(GO) mod tidy
# update-deps updates dependencies
update-deps:
@echo "Updating dependencies..."
$(GO) get -u ./...
$(GO) mod tidy
# release builds release artifacts
release: clean test lint
@echo "Building release artifacts for version $(VERSION)..."
@mkdir -p $(DIST_DIR)
@for os in darwin linux windows; do \
for arch in amd64 arm64; do \
if [ "$$os" = "windows" ] && [ "$$arch" = "arm64" ]; then continue; fi; \
echo "Building $$os-$$arch..."; \
EXT=""; \
if [ "$$os" = "windows" ]; then EXT=".exe"; fi; \
GOOS=$$os GOARCH=$$arch CGO_ENABLED=0 $(GO) build \
-ldflags="-s -w -X main.Version=$(VERSION)" \
-o $(DIST_DIR)/$(BINARY_NAME)-$(VERSION)-$$os-$$arch$$EXT \
$(CMD_DIR)/lattice; \
GOOS=$$os GOARCH=$$arch CGO_ENABLED=0 $(GO) build \
-ldflags="-s -w -X main.Version=$(VERSION)" \
-o $(DIST_DIR)/$(SERVER_BINARY_NAME)-$(VERSION)-$$os-$$arch$$EXT \
$(CMD_DIR)/lattice-server; \
done; \
done
@echo "Creating source tarball..."
@git archive --format=tar.gz --prefix="lattice-$(VERSION)/" \
-o $(DIST_DIR)/lattice-$(VERSION).tar.gz HEAD
@$(MAKE) checksum
# release-verify verifies release artifacts
release-verify: release
@echo "Verifying release artifacts..."
@cd $(DIST_DIR) && sha256sum -c SHA256SUMS
@echo "All artifacts verified!"
# checksum generates SHA256 checksums
checksum:
@echo "Generating checksums..."
@cd $(DIST_DIR) && sha256sum * > SHA256SUMS
@echo "Checksums generated:"
@cat $(DIST_DIR)/SHA256SUMS
# sign signs release artifacts with GPG
sign:
@echo "Signing release artifacts..."
@if command -v gpg >/dev/null 2>&1; then \
cd $(DIST_DIR) && \
gpg --detach-sign --armor SHA256SUMS && \
echo "Signed: SHA256SUMS.asc"; \
else \
echo "GPG not found. Install GPG to sign releases."; \
exit 1; \
fi
# tag creates a git tag for the current version
tag:
@echo "Creating git tag v$(VERSION)..."
@git tag -a "v$(VERSION)" -m "Release v$(VERSION)"
@echo "Tag created. Push with: git push origin v$(VERSION)"
# tag-verify verifies the current git tag
tag-verify:
@echo "Verifying tag v$(VERSION)..."
@if git tag -v "v$(VERSION)" 2>/dev/null; then \
echo "Tag signature verified!"; \
else \
echo "Tag is not signed or signature verification failed."; \
exit 1; \
fi
# ci runs CI checks
ci: fmt-check vet lint test
# help shows available targets
help:
@echo "Available targets:"
@echo " all - Build everything"
@echo " build - Compile binaries"
@echo " test - Run tests"
@echo " test-verbose - Run tests with verbose output"
@echo " cover - Run tests with coverage"
@echo " lint - Run linters"
@echo " fmt - Format code"
@echo " fmt-check - Check formatting"
@echo " vet - Run go vet"
@echo " clean - Remove build artifacts"
@echo " fuzz-short - Run fuzz tests (10s)"
@echo " fuzz-long - Run fuzz tests (5m)"
@echo " fuzz-generate - Generate fuzz corpora"
@echo " benchmark - Run benchmarks"
@echo " race - Run tests with race detector"
@echo " deps - Verify dependencies"
@echo " update-deps - Update dependencies"
@echo " release - Build release artifacts"
@echo " release-verify - Verify release artifacts"
@echo " checksum - Generate SHA256 checksums"
@echo " sign - Sign release artifacts (GPG)"
@echo " tag - Create git tag"
@echo " tag-verify - Verify git tag signature"
@echo " ci - Run CI checks"
@echo " help - Show this help message"