-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
158 lines (135 loc) · 4.96 KB
/
Makefile
File metadata and controls
158 lines (135 loc) · 4.96 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
# Makefile for grove-core
BINARY_NAME=core
E2E_BINARY_NAME=tend
BIN_DIR=bin
VERSION_PKG=github.com/grovetools/core/version
# --- Tool versions ---
# Kept in sync with .tool-versions (for asdf/mise). Override via env if needed.
GOFUMPT_VERSION ?= v0.9.2
GOLANGCI_VERSION ?= v1.64.8
# --- Versioning ---
# For dev builds, we construct a version string from git info.
# For release builds, VERSION is passed in by the CI/CD pipeline (e.g., VERSION=v1.2.3)
GIT_COMMIT ?= $(shell git rev-parse --short HEAD)
GIT_BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)
GIT_DIRTY ?= $(shell test -n "`git status --porcelain`" && echo "-dirty")
BUILD_DATE ?= $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
# If VERSION is not set, default to a dev version string
VERSION ?= $(GIT_BRANCH)-$(GIT_COMMIT)$(GIT_DIRTY)
# Go LDFLAGS to inject version info at compile time
LDFLAGS = -ldflags="\
-X '$(VERSION_PKG).Version=$(VERSION)' \
-X '$(VERSION_PKG).Commit=$(GIT_COMMIT)' \
-X '$(VERSION_PKG).Branch=$(GIT_BRANCH)' \
-X '$(VERSION_PKG).BuildDate=$(BUILD_DATE)'"
.PHONY: all build test clean fmt fmt-check vet lint run check dev build-all schema help setup
all: build
setup:
@echo "Configuring git blame to ignore formatting commits..."
@git config blame.ignoreRevsFile .git-blame-ignore-revs
@echo "Installing dev tools..."
@command -v gofumpt > /dev/null || go install mvdan.cc/gofumpt@$(GOFUMPT_VERSION)
@command -v golangci-lint > /dev/null || go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_VERSION)
@echo "Installing git pre-commit hook..."
@hooks_dir="$$(git rev-parse --git-path hooks)"; \
mkdir -p "$$hooks_dir"; \
cp scripts/pre-commit "$$hooks_dir/pre-commit"; \
chmod +x "$$hooks_dir/pre-commit"
@echo "Done. Run 'make check' to verify."
schema:
@echo "Generating base schema..."
@go generate ./config/...
@echo "Generating logging schema..."
@go generate ./logging/...
@echo "Composing final schemas..."
@go run ./tools/schema-composer/
build: schema
@mkdir -p $(BIN_DIR)
@echo "Building $(BINARY_NAME) version $(VERSION)..."
@go build $(LDFLAGS) -o $(BIN_DIR)/$(BINARY_NAME) ./cmd/core
test:
@echo "Running tests..."
@go test -v ./...
clean:
@echo "Cleaning..."
@go clean
@rm -rf $(BIN_DIR)
@rm -f $(BINARY_NAME)
@rm -f $(E2E_BINARY_NAME)
@rm -f coverage.out
fmt:
@echo "Formatting code..."
@if command -v gofumpt > /dev/null; then \
gofumpt -w .; \
else \
echo "gofumpt not installed. Install with: go install mvdan.cc/gofumpt@latest"; \
exit 1; \
fi
fmt-check:
@if ! command -v gofumpt > /dev/null; then \
echo "gofumpt not installed. Run 'make setup'."; \
exit 1; \
fi
@unformatted="$$(gofumpt -l . 2>/dev/null)"; \
if [ -n "$$unformatted" ]; then \
echo "Unformatted files (run 'make fmt'):"; \
echo "$$unformatted" | sed 's/^/ /'; \
exit 1; \
fi
vet:
@echo "Running go vet..."
@go vet ./...
lint:
@echo "Running linter..."
@if command -v golangci-lint > /dev/null; then \
golangci-lint run; \
else \
echo "golangci-lint not installed. Install with: go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest"; \
fi
# Run the CLI
run: build
@$(BIN_DIR)/$(BINARY_NAME) $(ARGS)
# Run all checks
check: fmt-check vet lint test
# Development build with race detector
dev:
@mkdir -p $(BIN_DIR)
@echo "Building $(BINARY_NAME) with race detector..."
@go build -race $(LDFLAGS) -o $(BIN_DIR)/$(BINARY_NAME) ./cmd/core
# Cross-compilation targets
PLATFORMS ?= darwin/amd64 darwin/arm64 linux/amd64 linux/arm64
DIST_DIR ?= dist
build-all:
@echo "Building for multiple platforms into $(DIST_DIR)..."
@mkdir -p $(DIST_DIR)
@for platform in $(PLATFORMS); do \
os=$$(echo $$platform | cut -d'/' -f1); \
arch=$$(echo $$platform | cut -d'/' -f2); \
output_name="$(BINARY_NAME)-$${os}-$${arch}"; \
echo " -> Building $${output_name} version $(VERSION)"; \
GOOS=$$os GOARCH=$$arch go build $(LDFLAGS) -o $(DIST_DIR)/$${output_name} ./cmd/core; \
done
# --- E2E Testing ---
# Run E2E tests. Depends on the main 'core' binary.
# The global tend binary will automatically build the project-specific test runner.
# Pass arguments via ARGS, e.g., make test-e2e ARGS="-i"
test-e2e: build
@echo "Running E2E tests..."
@go build -o $(BIN_DIR)/$(E2E_BINARY_NAME) ./tests/e2e/
@tend run -p $(ARGS)
# Show available targets
help:
@echo "Available targets:"
@echo " make setup - One-time contributor setup (git config, install gofumpt)"
@echo " make build - Build the binary"
@echo " make schema - Generate JSON schemas"
@echo " make test - Run tests"
@echo " make clean - Clean build artifacts"
@echo " make fmt - Format code"
@echo " make vet - Run go vet"
@echo " make lint - Run linter"
@echo " make run ARGS=.. - Run the CLI with arguments"
@echo " make check - Run all checks"
@echo " make dev - Build with race detector"
@echo " make build-all - Build for multiple platforms"
@echo " make test-e2e ARGS=...- Run E2E tests (e.g., ARGS=\"-i core-config-layering\")"