Skip to content

Commit 2e16c7d

Browse files
build: add Makefile for common development tasks (#66)
Targets: build, install, clean, test, test-verbose, test-race, test-cover, bench, fmt, vet, lint, check, docker-build, docker-run, release-dry, release, config-init, run-api, run-serve, deps, help. make help lists all targets with descriptions. Co-authored-by: Ona <no-reply@ona.com>
1 parent 1c67071 commit 2e16c7d

2 files changed

Lines changed: 124 additions & 0 deletions

File tree

Makefile

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
BINARY := distill
2+
GO := go
3+
GOFLAGS :=
4+
LDFLAGS := -s -w
5+
BUILD_DIR := .
6+
7+
.DEFAULT_GOAL := build
8+
9+
# ── Build ─────────────────────────────────────────────────────────────────────
10+
11+
.PHONY: build
12+
build: ## Build the distill binary
13+
$(GO) build $(GOFLAGS) -ldflags "$(LDFLAGS)" -o $(BUILD_DIR)/$(BINARY) .
14+
15+
.PHONY: install
16+
install: ## Install distill to $GOPATH/bin
17+
$(GO) install $(GOFLAGS) -ldflags "$(LDFLAGS)" .
18+
19+
.PHONY: clean
20+
clean: ## Remove build artifacts
21+
rm -f $(BUILD_DIR)/$(BINARY)
22+
23+
# ── Test ──────────────────────────────────────────────────────────────────────
24+
25+
.PHONY: test
26+
test: ## Run all tests
27+
$(GO) test ./...
28+
29+
.PHONY: test-verbose
30+
test-verbose: ## Run all tests with verbose output
31+
$(GO) test -v ./...
32+
33+
.PHONY: test-race
34+
test-race: ## Run tests with race detector
35+
$(GO) test -race ./...
36+
37+
.PHONY: test-cover
38+
test-cover: ## Run tests and show coverage
39+
$(GO) test -coverprofile=coverage.out ./...
40+
$(GO) tool cover -func=coverage.out
41+
rm -f coverage.out
42+
43+
.PHONY: bench
44+
bench: ## Run benchmarks
45+
$(GO) test -bench=. -benchmem ./...
46+
47+
# ── Code quality ──────────────────────────────────────────────────────────────
48+
49+
.PHONY: fmt
50+
fmt: ## Format all Go source files
51+
$(GO) fmt ./...
52+
53+
.PHONY: vet
54+
vet: ## Run go vet
55+
$(GO) vet ./...
56+
57+
.PHONY: lint
58+
lint: ## Run golangci-lint (requires golangci-lint in PATH)
59+
golangci-lint run ./...
60+
61+
.PHONY: check
62+
check: fmt vet test ## Run fmt, vet, and test
63+
64+
# ── Docker ────────────────────────────────────────────────────────────────────
65+
66+
.PHONY: docker-build
67+
docker-build: ## Build the Docker image
68+
docker build -t $(BINARY):latest .
69+
70+
.PHONY: docker-run
71+
docker-run: ## Run the Docker container (API mode, port 8080)
72+
docker run --rm -p 8080:8080 \
73+
-e OPENAI_API_KEY="$$OPENAI_API_KEY" \
74+
$(BINARY):latest api
75+
76+
# ── Release ───────────────────────────────────────────────────────────────────
77+
78+
.PHONY: release-dry
79+
release-dry: ## Dry-run goreleaser (snapshot, no publish)
80+
goreleaser release --snapshot --clean
81+
82+
.PHONY: release
83+
release: ## Run goreleaser (requires GITHUB_TOKEN)
84+
goreleaser release --clean
85+
86+
# ── Dev helpers ───────────────────────────────────────────────────────────────
87+
88+
.PHONY: config-init
89+
config-init: build ## Generate a default distill.yaml
90+
./$(BINARY) config init
91+
92+
.PHONY: run-api
93+
run-api: build ## Start the API server on :8080
94+
./$(BINARY) api
95+
96+
.PHONY: run-serve
97+
run-serve: build ## Start the serve command
98+
./$(BINARY) serve
99+
100+
.PHONY: deps
101+
deps: ## Download and tidy Go modules
102+
$(GO) mod download
103+
$(GO) mod tidy
104+
105+
# ── Help ──────────────────────────────────────────────────────────────────────
106+
107+
.PHONY: help
108+
help: ## List all available targets
109+
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) \
110+
| awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-20s\033[0m %s\n", $$1, $$2}' \
111+
| sort

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,19 @@ cd distill
105105
go build -o distill .
106106
```
107107

108+
## Development
109+
110+
```bash
111+
make build # compile ./distill
112+
make test # go test ./...
113+
make check # fmt + vet + test
114+
make test-cover # test with coverage report
115+
make bench # run benchmarks
116+
make lint # golangci-lint (requires golangci-lint in PATH)
117+
make docker-build # build Docker image
118+
make help # list all targets
119+
```
120+
108121
## Quick Start
109122

110123
### 1. Standalone API (No Vector DB Required)

0 commit comments

Comments
 (0)