forked from wesm/agentsview
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
152 lines (128 loc) · 5.06 KB
/
Makefile
File metadata and controls
152 lines (128 loc) · 5.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
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
.DEFAULT_GOAL := help
VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
BUILD_DATE := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
LDFLAGS := -X main.version=$(VERSION) \
-X main.commit=$(COMMIT) \
-X main.buildDate=$(BUILD_DATE)
LDFLAGS_RELEASE := $(LDFLAGS) -s -w
.PHONY: build build-release install frontend frontend-dev dev test test-short e2e vet lint tidy clean release release-darwin-arm64 release-darwin-amd64 release-linux-amd64 install-hooks ensure-embed-dir help
# Ensure go:embed has at least one file (no-op if frontend is built)
ensure-embed-dir:
@mkdir -p internal/web/dist
@test -n "$$(ls internal/web/dist/ 2>/dev/null)" \
|| echo ok > internal/web/dist/stub.html
# Build the binary (debug, with embedded frontend)
build: frontend
CGO_ENABLED=1 go build -tags fts5 -ldflags="$(LDFLAGS)" -o agentsview ./cmd/agentsview
@chmod +x agentsview
# Build with optimizations (release)
build-release: frontend
CGO_ENABLED=1 go build -tags fts5 -ldflags="$(LDFLAGS_RELEASE)" -trimpath -o agentsview ./cmd/agentsview
@chmod +x agentsview
# Install to ~/.local/bin, $GOBIN, or $GOPATH/bin
install: build-release
@if [ -d "$(HOME)/.local/bin" ]; then \
echo "Installing to ~/.local/bin/agentsview"; \
cp agentsview "$(HOME)/.local/bin/agentsview"; \
else \
INSTALL_DIR="$${GOBIN:-$$(go env GOBIN)}"; \
if [ -z "$$INSTALL_DIR" ]; then \
GOPATH_FIRST="$$(go env GOPATH | cut -d: -f1)"; \
INSTALL_DIR="$$GOPATH_FIRST/bin"; \
fi; \
mkdir -p "$$INSTALL_DIR"; \
echo "Installing to $$INSTALL_DIR/agentsview"; \
cp agentsview "$$INSTALL_DIR/agentsview"; \
fi
# Build frontend SPA and copy into embed directory
frontend:
cd frontend && npm install && npm run build
rm -rf internal/web/dist
cp -r frontend/dist internal/web/dist
# Run Vite dev server (use alongside `make dev`)
frontend-dev:
cd frontend && npm run dev
# Run Go server in dev mode (no embedded frontend)
dev: ensure-embed-dir
go run -tags fts5 -ldflags="$(LDFLAGS)" ./cmd/agentsview $(ARGS)
# Run tests
test: ensure-embed-dir
go test -tags fts5 ./... -v -count=1
# Run fast tests only
test-short: ensure-embed-dir
go test -tags fts5 ./... -short -count=1
# Run Playwright E2E tests
e2e:
cd frontend && npx playwright test
# Vet
vet: ensure-embed-dir
go vet -tags fts5 ./...
# Lint Go code with project defaults
lint: ensure-embed-dir
@if ! command -v golangci-lint >/dev/null 2>&1; then \
echo "golangci-lint not found. Install with: go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.10.1" >&2; \
exit 1; \
fi
golangci-lint run ./...
# Tidy dependencies
tidy:
go mod tidy
# Clean build artifacts
clean:
rm -f agentsview agentsv
rm -rf internal/web/dist dist/
# Build release binary for current platform (CGO required for sqlite3)
release: frontend
mkdir -p dist
CGO_ENABLED=1 go build -tags fts5 \
-ldflags="$(LDFLAGS_RELEASE)" -trimpath \
-o dist/agentsview-$$(go env GOOS)-$$(go env GOARCH) ./cmd/agentsview
# Cross-compile targets (require CC set to target cross-compiler)
release-darwin-arm64: frontend
mkdir -p dist
GOOS=darwin GOARCH=arm64 CGO_ENABLED=1 go build -tags fts5 \
-ldflags="$(LDFLAGS_RELEASE)" -trimpath \
-o dist/agentsview-darwin-arm64 ./cmd/agentsview
release-darwin-amd64: frontend
mkdir -p dist
GOOS=darwin GOARCH=amd64 CGO_ENABLED=1 go build -tags fts5 \
-ldflags="$(LDFLAGS_RELEASE)" -trimpath \
-o dist/agentsview-darwin-amd64 ./cmd/agentsview
release-linux-amd64: frontend
mkdir -p dist
GOOS=linux GOARCH=amd64 CGO_ENABLED=1 go build -tags fts5 \
-ldflags="$(LDFLAGS_RELEASE)" -trimpath \
-o dist/agentsview-linux-amd64 ./cmd/agentsview
# Install pre-commit hook, resolving the hooks directory via git so
# this works in both normal repos and linked worktrees
install-hooks:
@hooks_rel=$$(git rev-parse --git-path hooks) && \
hooks_dir=$$(cd "$$(dirname "$$hooks_rel")" && echo "$$PWD/$$(basename "$$hooks_rel")") && \
git config --local core.hooksPath "$$hooks_dir" && \
mkdir -p "$$hooks_dir" && \
cp .githooks/pre-commit "$$hooks_dir/pre-commit" && \
chmod +x "$$hooks_dir/pre-commit" && \
echo "Installed pre-commit hook to $$hooks_dir/pre-commit"
# Show help
help:
@echo "agentsview build targets:"
@echo ""
@echo " build - Build with embedded frontend"
@echo " build-release - Release build (optimized, stripped)"
@echo " install - Build and install to ~/.local/bin or GOPATH"
@echo ""
@echo " dev - Run Go server (use with frontend-dev)"
@echo " frontend - Build frontend SPA"
@echo " frontend-dev - Run Vite dev server"
@echo ""
@echo " test - Run all tests"
@echo " test-short - Run fast tests only"
@echo " e2e - Run Playwright E2E tests"
@echo " vet - Run go vet"
@echo " lint - Run golangci-lint"
@echo " tidy - Tidy go.mod"
@echo ""
@echo " release - Release build for current platform"
@echo " clean - Remove build artifacts"
@echo " install-hooks - Install pre-commit git hooks"