-
Notifications
You must be signed in to change notification settings - Fork 104
Expand file tree
/
Copy pathMakefile
More file actions
361 lines (315 loc) · 13.9 KB
/
Makefile
File metadata and controls
361 lines (315 loc) · 13.9 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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
.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
DESKTOP_DIST_DIR := dist/desktop
GOPATH_FIRST := $(shell go env GOPATH | cut -d: -f1)
AIR_BIN := $(shell if command -v air >/dev/null 2>&1; then command -v air; \
elif [ -n "$$(go env GOBIN)" ] && [ -x "$$(go env GOBIN)/air" ]; then printf "%s" "$$(go env GOBIN)/air"; \
elif [ -x "$(GOPATH_FIRST)/bin/air" ]; then printf "%s" "$(GOPATH_FIRST)/bin/air"; \
fi)
.PHONY: build build-release install frontend frontend-dev dev check-air air-install desktop-dev desktop-build desktop-macos-app desktop-macos-dmg desktop-windows-installer desktop-linux-appimage desktop-app test test-short test-postgres test-postgres-ci postgres-up postgres-down test-ssh test-ssh-ci ssh-up ssh-down e2e vet lint lint-ci tidy clean release release-darwin-arm64 release-darwin-amd64 release-linux-amd64 install-hooks ensure-embed-dir dev-snapshot 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
# Build and run agentsview against a fresh snapshot of the prod SQLite DB.
# Prod DB is never written; sqlite3 .backup is WAL-safe even with prod running.
# Prod config.toml is NOT copied, so remote PG push is disabled in the snapshot.
# Overrides:
# PROD_DATA_DIR - source data dir (default: $$HOME/.agentsview)
# SNAPSHOT_DIR - destination dir (default: tmp/prod-snapshot)
# RESNAPSHOT=0 - reuse existing snapshot instead of re-cloning
PROD_DATA_DIR ?= $(HOME)/.agentsview
SNAPSHOT_DIR ?= tmp/prod-snapshot
# Resolve SNAPSHOT_DIR so relative and absolute paths both work.
SNAPSHOT_ABS := $(abspath $(SNAPSHOT_DIR))
# Sentinel file written into a snapshot directory the first time
# we populate it. Subsequent runs require this marker before
# touching any contents, so pointing SNAPSHOT_DIR at an
# unrelated existing directory cannot accidentally delete
# someone's files. The previous version used rm -rf on the
# whole directory; that left dangerous edge cases (e.g.
# SNAPSHOT_DIR=tmp wiping unrelated tmp/ contents) even with a
# denylist, so we now only ever delete a small set of files we
# know we wrote.
SNAPSHOT_MARKER := .agentsview-snapshot
dev-snapshot: build
@if [ ! -f "$(PROD_DATA_DIR)/sessions.db" ]; then \
echo "error: prod sessions.db not found at $(PROD_DATA_DIR)/sessions.db" >&2; \
exit 1; \
fi
@if [ -z "$(SNAPSHOT_ABS)" ]; then \
echo "error: SNAPSHOT_DIR resolved to empty path" >&2; \
exit 1; \
fi
@if [ -d "$(SNAPSHOT_ABS)" ] && [ ! -f "$(SNAPSHOT_ABS)/$(SNAPSHOT_MARKER)" ]; then \
if [ -n "$$(ls -A "$(SNAPSHOT_ABS)" 2>/dev/null)" ]; then \
echo "error: $(SNAPSHOT_ABS) is non-empty and missing the $(SNAPSHOT_MARKER) marker" >&2; \
echo " refusing to touch a directory we did not create" >&2; \
echo " remove the directory manually if you want to reuse this path" >&2; \
exit 1; \
fi; \
fi
@mkdir -p "$(SNAPSHOT_ABS)"
@touch "$(SNAPSHOT_ABS)/$(SNAPSHOT_MARKER)"
@if [ "$${RESNAPSHOT:-1}" = "1" ] || [ ! -f "$(SNAPSHOT_ABS)/sessions.db" ]; then \
echo "Snapshotting $(PROD_DATA_DIR)/sessions.db -> $(SNAPSHOT_ABS)/sessions.db"; \
for f in sessions.db sessions.db-wal sessions.db-shm \
config.toml config.json config.json.bak \
debug.log; do \
rm -f "$(SNAPSHOT_ABS)/$$f"; \
done; \
sqlite3 "$(PROD_DATA_DIR)/sessions.db" \
".backup $(SNAPSHOT_ABS)/sessions.db"; \
else \
echo "Reusing existing snapshot at $(SNAPSHOT_ABS)/sessions.db"; \
fi
AGENT_VIEWER_DATA_DIR="$(SNAPSHOT_ABS)" ./agentsview serve --port 0
# Ensure air is installed for backend live reload
check-air:
@if [ -z "$(AIR_BIN)" ]; then \
echo "air not found. Install with: make air-install" >&2; \
exit 1; \
fi
# Install air for backend live reload
air-install:
go install github.com/air-verse/air@latest
# Run Go server in dev mode with live reload (use with frontend-dev).
# Edits to .go files trigger a rebuild + restart via air.
dev: ensure-embed-dir check-air
"$(AIR_BIN)" -c .air.toml -- $(ARGS)
# Run the Tauri desktop wrapper in development mode
desktop-dev:
cd desktop && npm install && npm run tauri:dev
# Build desktop app bundles via Tauri
desktop-build:
cd desktop && npm install && npm run tauri:build
# Build only the macOS .app bundle (skip DMG packaging).
# Skips updater artifact signing when TAURI_SIGNING_PRIVATE_KEY
# is not set so local builds succeed without release keys.
desktop-macos-app:
cd desktop && npm install && npm run tauri:build:macos-app \
$(if $(TAURI_SIGNING_PRIVATE_KEY),,-- --config '{"bundle":{"createUpdaterArtifacts":false}}')
mkdir -p $(DESKTOP_DIST_DIR)/macos
rm -rf $(DESKTOP_DIST_DIR)/macos/AgentsView.app
cp -R desktop/src-tauri/target/release/bundle/macos/AgentsView.app \
$(DESKTOP_DIST_DIR)/macos/AgentsView.app
@echo "macOS app bundle copied to $(DESKTOP_DIST_DIR)/macos/AgentsView.app"
# Build macOS DMG installer
desktop-macos-dmg:
cd desktop && npm install && npm run tauri:build:macos-dmg
mkdir -p $(DESKTOP_DIST_DIR)/macos
rm -f $(DESKTOP_DIST_DIR)/macos/*.dmg
@dmg_count=$$(find desktop/src-tauri/target/release/bundle/dmg \
-maxdepth 1 -type f -name '*.dmg' | wc -l | tr -d ' '); \
if [ "$$dmg_count" -eq 0 ]; then \
echo "error: no DMG installer found in bundle output" >&2; \
exit 1; \
fi; \
find desktop/src-tauri/target/release/bundle/dmg \
-maxdepth 1 -type f -name '*.dmg' \
-exec cp {} $(DESKTOP_DIST_DIR)/macos/ \;; \
echo "Copied $$dmg_count DMG installer(s) to $(DESKTOP_DIST_DIR)/macos/"
# Build Windows NSIS installer bundle (.exe)
# Run on Windows runner/host.
desktop-windows-installer:
cd desktop && npm install && npm run tauri:build:windows
mkdir -p $(DESKTOP_DIST_DIR)/windows
rm -f $(DESKTOP_DIST_DIR)/windows/*.exe
@exe_count=$$(find desktop/src-tauri/target/release/bundle/nsis \
-maxdepth 1 -type f -name '*.exe' | wc -l | tr -d ' '); \
if [ "$$exe_count" -eq 0 ]; then \
echo "error: no Windows installer (.exe) found in bundle output" >&2; \
exit 1; \
fi; \
find desktop/src-tauri/target/release/bundle/nsis \
-maxdepth 1 -type f -name '*.exe' \
-exec cp {} $(DESKTOP_DIST_DIR)/windows/ \;; \
echo "Copied $$exe_count Windows installer(s) to $(DESKTOP_DIST_DIR)/windows/"
# Build Linux AppImage bundle
# Run on a Linux host.
desktop-linux-appimage:
cd desktop && npm install && npm run tauri:build:linux \
$(if $(TAURI_SIGNING_PRIVATE_KEY),,-- --config '{"bundle":{"createUpdaterArtifacts":false}}')
mkdir -p $(DESKTOP_DIST_DIR)/linux
rm -f $(DESKTOP_DIST_DIR)/linux/*.AppImage
@ai_count=$$(find desktop/src-tauri/target/release/bundle/appimage \
-maxdepth 1 -type f -name '*.AppImage' | wc -l | tr -d ' '); \
if [ "$$ai_count" -eq 0 ]; then \
echo "error: no AppImage found in bundle output" >&2; \
exit 1; \
fi; \
find desktop/src-tauri/target/release/bundle/appimage \
-maxdepth 1 -type f -name '*.AppImage' \
-exec cp {} $(DESKTOP_DIST_DIR)/linux/ \;; \
echo "Copied $$ai_count AppImage(s) to $(DESKTOP_DIST_DIR)/linux/"
# Backward-compatible alias (macOS .app)
desktop-app: desktop-macos-app
# 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
# Start test PostgreSQL container
postgres-up:
docker compose -f docker-compose.test.yml up -d --wait
# Stop test PostgreSQL container
postgres-down:
docker compose -f docker-compose.test.yml down
# Run PostgreSQL integration tests (starts postgres automatically)
test-postgres: ensure-embed-dir postgres-up
@echo "Waiting for postgres to be ready..."
@sleep 2
TEST_PG_URL="postgres://agentsview_test:agentsview_test_password@localhost:5433/agentsview_test?sslmode=disable" \
CGO_ENABLED=1 go test -tags "fts5,pgtest" -v ./internal/postgres/... -count=1
# PostgreSQL integration tests for CI (postgres already running as service)
test-postgres-ci: ensure-embed-dir
CGO_ENABLED=1 go test -tags "fts5,pgtest" -v ./internal/postgres/... -count=1
# Start test SSH container
ssh-up:
docker compose -f docker-compose.test.yml up -d --build --wait sshd
docker cp "$$(docker compose -f docker-compose.test.yml ps -q sshd)":/tmp/test_ssh_key testdata/ssh/test_key
chmod 600 testdata/ssh/test_key
# Stop test SSH container
ssh-down:
docker compose -f docker-compose.test.yml down sshd
# Run SSH integration tests (starts sshd automatically)
test-ssh: ensure-embed-dir ssh-up
TEST_SSH_HOST=localhost TEST_SSH_PORT=2222 TEST_SSH_USER=testuser \
TEST_SSH_KEY=$(CURDIR)/testdata/ssh/test_key \
CGO_ENABLED=1 go test -tags "fts5,sshtest" -v ./internal/ssh/... -count=1
# SSH integration tests for CI (sshd already running)
test-ssh-ci: ensure-embed-dir
CGO_ENABLED=1 go test -tags "fts5,sshtest" -v ./internal/ssh/... -count=1
# Run Playwright E2E tests
e2e:
cd frontend && npx playwright test
# Vet
vet: ensure-embed-dir
go vet -tags fts5 ./...
# Lint Go code and auto-fix where possible (local development)
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 --fix ./...
# Lint Go code without fixing (for CI)
lint-ci: 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/ tmp/
# 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 hooks via prek
install-hooks:
@if ! command -v prek >/dev/null 2>&1; then \
echo "prek not found. Install with: brew install prek" >&2; \
exit 1; \
fi
prek install -f
# 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 with live reload via air (use with frontend-dev)"
@echo " dev-snapshot - Run agentsview against a fresh snapshot of prod sessions.db"
@echo " air-install - Install air for backend live reload"
@echo " frontend - Build frontend SPA"
@echo " frontend-dev - Run Vite dev server"
@echo " desktop-dev - Run Tauri desktop wrapper in dev mode"
@echo " desktop-build - Build Tauri desktop app bundles"
@echo " desktop-macos-app - Build macOS .app bundle only"
@echo " desktop-macos-dmg - Build macOS DMG installer"
@echo " desktop-windows-installer - Build Windows NSIS installer"
@echo " desktop-linux-appimage - Build Linux AppImage"
@echo " desktop-app - Alias for desktop-macos-app"
@echo ""
@echo " test - Run all tests"
@echo " test-short - Run fast tests only"
@echo " test-postgres - Run PostgreSQL integration tests"
@echo " postgres-up - Start test PostgreSQL container"
@echo " postgres-down - Stop test PostgreSQL container"
@echo " test-ssh - Run SSH integration tests"
@echo " ssh-up - Start test SSH container"
@echo " ssh-down - Stop test SSH container"
@echo " e2e - Run Playwright E2E tests"
@echo " vet - Run go vet"
@echo " lint - Run golangci-lint (auto-fix)"
@echo " lint-ci - Run golangci-lint (no fix, for CI)"
@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"