-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
251 lines (211 loc) · 7.71 KB
/
Makefile
File metadata and controls
251 lines (211 loc) · 7.71 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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
MAKEFLAGS += --no-print-directory
# Default target when running just 'make'
.DEFAULT_GOAL := help
# Build variables
VERSION ?= dev
COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo "none")
BUILD_DATE := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
GO_VERSION := $(shell go version | cut -d ' ' -f 3)
# Build flags
LDFLAGS := -ldflags "-X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.buildDate=$(BUILD_DATE) -X main.goVersion=$(GO_VERSION)"
.PHONY: all
all: test lint generate build
##@ General
# The help target prints out all targets with their descriptions organized
# beneath their categories. The categories are represented by '##@' and the
# target descriptions by '##'. The awk command is responsible for reading the
# entire set of makefiles included in this invocation, looking for lines of the
# file as xyz: ## something, and then pretty-format the target and help. Then,
# if there's a line with ##@ something, that gets pretty-printed as a category.
# More info on the usage of ANSI control characters for terminal formatting:
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
# More info on the awk command:
# http://linuxcommand.org/lc3_adv_awk.php
.PHONY: help
help: ## Display the list of targets and their descriptions
@awk 'BEGIN {FS = ":.*##"; printf "\n\033[1mUsage:\033[0m\n make \033[36m<target>\033[0m\n"} \
/^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-20s\033[0m %s\n", $$1, $$2 } \
/^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } \
/^###/ { printf " \033[90m%s\033[0m\n", substr($$0, 4) }' $(MAKEFILE_LIST)
##@ Tooling
.PHONY: install-devbox
install-devbox: ## Install Devbox
@echo "Installing Devbox..."
@curl -fsSL https://get.jetify.dev | bash
.PHONY: devbox-update
devbox-update: ## Update Devbox
@devbox update
.PHONY: devbox
devbox: ## Run Devbox shell
@devbox shell
.PHONY: install-air
install-air: ## Install Air for hot-reload development
@echo "Installing Air..."
@go install github.com/air-verse/air@latest
.PHONY: install-pre-commit
install-pre-commit: ## Install pre-commit hooks
@echo "Installing pre-commit..."
@pip install pre-commit || pip3 install pre-commit
@pre-commit install
.PHONY: install-tools
install-tools: ## Install development tools
@echo "Installing development tools..."
@go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
@go install golang.org/x/tools/cmd/goimports@latest
@go install golang.org/x/vuln/cmd/govulncheck@latest
@go install honnef.co/go/tools/cmd/staticcheck@latest
@go install github.com/tetafro/godot/cmd/godot@latest
@go install github.com/princjef/gomarkdoc/cmd/gomarkdoc@latest
@echo "Tools installed successfully"
##@ Install Dependencies
.PHONY: deps
deps: ## Download go modules
@echo "Downloading go modules..."
go mod download
.PHONY: install
install: ## Install the tokenizer binary
@echo "Installing tokenizer binary..."
go install ./cmd/tokenizer
##@ Development
### Use 'make dev' for hot-reload development mode
.PHONY: dev
dev: ## Start development server with hot-reloading (requires Air)
@echo "Starting development server with hot reload..."
@if ! command -v air >/dev/null 2>&1; then \
echo "Air is not installed. Install with: make install-air"; \
exit 1; \
fi
@air
.PHONY: demo
demo: ## Generate demo using VHS
@echo "Generating demo..."
@if ! command -v vhs >/dev/null 2>&1; then \
echo "VHS is not installed. Run 'devbox shell' or install with: brew install vhs"; \
exit 1; \
fi
@if ! command -v tokenizer >/dev/null 2>&1; then \
echo "tokenizer is not installed. Install with: brew install agentstation/tap/tokenizer"; \
exit 1; \
fi
@echo "Checking for JetBrains Mono font..."
@if ! fc-list 2>/dev/null | grep -q "JetBrains Mono" && ! ls ~/Library/Fonts/*JetBrains* /Library/Fonts/*JetBrains* /System/Library/Fonts/*JetBrains* 2>/dev/null | grep -q "JetBrains"; then \
echo "JetBrains Mono font not found."; \
if command -v brew >/dev/null 2>&1; then \
echo "Installing JetBrains Mono font..."; \
brew install --cask font-jetbrains-mono || true; \
else \
echo "Please install JetBrains Mono font manually or the demo will use the default font."; \
fi \
else \
echo "JetBrains Mono font found."; \
fi
@mkdir -p docs
@vhs scripts/demo.tape
@echo "Demo generated: docs/demo.svg"
.PHONY: fmt
fmt: ## Run go fmt
@echo "Running go fmt..."
@go fmt ./...
@go mod tidy
.PHONY: fmt-all
fmt-all: ## Comprehensive formatting with all tools
@echo "Running comprehensive formatting..."
@echo " → Running gofmt..."
@gofmt -w .
@echo " → Running goimports..."
@if command -v goimports >/dev/null 2>&1; then \
goimports -w -local "github.com/agentstation/tokenizer" .; \
else \
echo " goimports not installed, skipping..."; \
fi
@echo " → Running godot..."
@if command -v godot >/dev/null 2>&1; then \
godot -w .; \
else \
echo " godot not installed, skipping..."; \
fi
@echo " → Running golangci-lint with auto-fix..."
@if command -v golangci-lint >/dev/null 2>&1; then \
golangci-lint run --fix; \
else \
echo " golangci-lint not installed, skipping..."; \
fi
@echo " → Running go mod tidy..."
@go mod tidy
@echo "Formatting complete!"
.PHONY: generate
generate: ## Generate and embed go documentation into README.md
@echo "Generating and embedding go documentation into README.md..."
go generate ./...
.PHONY: vet
vet: ## Run go vet
@echo "Running go vet..."
go vet ./...
.PHONY: lint
lint: ## Run golangci-lint
@echo "Running golangci-lint..."
golangci-lint run ./...
##@ Benchmarking, Testing, & Coverage
.PHONY: bench
bench: ## Run Go benchmarks
@echo "Running go benchmarks..."
go test ./... -tags=bench -bench=.
.PHONY: test
test: ## Run Go tests
@echo "Running go tests..."
@go test -v ./...
.PHONY: test-race
test-race: ## Run tests with race detector
@echo "Running tests with race detector..."
@go test -race -v ./...
.PHONY: test-integration
test-integration: ## Run integration tests
@echo "Running integration tests..."
@go test -tags=integration -v ./... -run "Integration"
.PHONY: test-e2e
test-e2e: build ## Run end-to-end tests
@echo "Running end-to-end tests..."
@go test -tags=e2e -v ./cmd/tokenizer -run "E2E"
.PHONY: test-all
test-all: test test-race test-integration test-e2e ## Run all tests
@echo "All tests completed!"
.PHONY: test-cli
test-cli: ## Run CLI-specific tests
@echo "Running CLI tests..."
@go test -v ./cmd/tokenizer/...
.PHONY: coverage
coverage: ## Run tests and generate coverage report
@echo "Running tests and generating coverage report..."
go test -race -coverprofile=coverage.txt -covermode=atomic ./...
##@ Build & Release
.PHONY: build
build: ## Build the CLI binary
@echo "Building tokenizer binary..."
@mkdir -p dist
@go build $(LDFLAGS) -o dist/tokenizer ./cmd/tokenizer
@echo "Binary built: dist/tokenizer"
.PHONY: build-all
build-all: ## Build binaries for all platforms
@echo "Building binaries for all platforms..."
goreleaser build --snapshot --clean
.PHONY: release
release: ## Create a new release (requires version tag)
@echo "Creating release..."
@if [ -z "$$(git describe --tags --exact-match 2>/dev/null)" ]; then \
echo "Error: No tag found. Please create a tag first using 'make tag VERSION=v1.2.3'"; \
exit 1; \
fi
goreleaser release --clean
.PHONY: release-snapshot
release-snapshot: ## Test release process locally (doesn't publish)
@echo "Testing release process locally..."
goreleaser release --snapshot --clean
.PHONY: tag
tag: ## Create and push a new version tag (usage: make tag VERSION=v1.2.3)
@if [ -z "$(VERSION)" ]; then \
echo "Error: VERSION is required. Usage: make tag VERSION=v1.2.3"; \
exit 1; \
fi
@echo "Creating tag $(VERSION)..."
git tag -a $(VERSION) -m "Release $(VERSION)"
@echo "Tag $(VERSION) created. Push with: git push origin $(VERSION)"