-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
201 lines (171 loc) · 7.41 KB
/
Makefile
File metadata and controls
201 lines (171 loc) · 7.41 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
.PHONY: all build test lint coverage security check clean install-local install-local-force dev fmt tidy
.PHONY: test-unit ci help tools watch install-service uninstall-service
# Build configuration
BINARY_DIR := bin
BINARY_NAME := engram-agent
VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
BUILD_TIME := $(shell date -u '+%Y-%m-%dT%H:%M:%SZ')
LDFLAGS := -ldflags "-X main.Version=$(VERSION) -X main.BuildTime=$(BUILD_TIME)"
# Colors for output
GREEN := \033[0;32m
YELLOW := \033[0;33m
RED := \033[0;31m
NC := \033[0m # No Color
# Default target
all: check build
# =============================================================================
# Build targets
# =============================================================================
build:
@mkdir -p $(BINARY_DIR)
go build $(LDFLAGS) -o $(BINARY_DIR)/$(BINARY_NAME) ./cmd/engram-agent
@echo "$(GREEN)Built: $(BINARY_DIR)/$(BINARY_NAME)$(NC)"
# =============================================================================
# Test targets
# =============================================================================
test-unit:
@echo "$(GREEN)Running unit tests...$(NC)"
go test -v -race ./...
test: test-unit
# =============================================================================
# Code quality targets
# =============================================================================
fmt:
@echo "$(GREEN)Formatting code...$(NC)"
go fmt ./...
@which goimports > /dev/null 2>&1 && goimports -w . || echo "$(YELLOW)goimports not installed, skipping$(NC)"
tidy:
go mod tidy
vet:
@echo "$(GREEN)Running go vet...$(NC)"
go vet ./...
lint:
@echo "$(GREEN)Running golangci-lint...$(NC)"
@which golangci-lint > /dev/null 2>&1 && golangci-lint run ./... || echo "$(YELLOW)golangci-lint not installed, running go vet instead$(NC)" && go vet ./...
security:
@echo "$(GREEN)Running security checks...$(NC)"
@which gosec > /dev/null 2>&1 && gosec -quiet ./... || echo "$(YELLOW)gosec not installed, skipping$(NC)"
coverage:
@echo "$(GREEN)Running tests with coverage...$(NC)"
go test -coverprofile=coverage.out -covermode=atomic ./...
@echo ""
@echo "$(GREEN)Coverage summary:$(NC)"
@go tool cover -func=coverage.out | grep -E "^total:|internal/"
@echo ""
@go tool cover -html=coverage.out -o coverage.html
@echo "$(GREEN)Full report: coverage.html$(NC)"
# =============================================================================
# CI / Golden Pipeline
# =============================================================================
ci: fmt tidy vet lint test-unit coverage build
@echo ""
@echo "$(GREEN)========================================$(NC)"
@echo "$(GREEN) CI Pipeline completed successfully! $(NC)"
@echo "$(GREEN)========================================$(NC)"
check: fmt tidy vet test-unit build
@echo "$(GREEN)Quick check passed!$(NC)"
# =============================================================================
# Utility targets
# =============================================================================
clean:
rm -rf $(BINARY_DIR)
rm -f coverage.out coverage.html
install-local: build
@mkdir -p ~/.local/bin
@if [ -x ~/.local/bin/$(BINARY_NAME) ]; then \
echo "$(YELLOW)Current:$(NC) $$(~/.local/bin/$(BINARY_NAME) version 2>/dev/null || echo 'unknown')"; \
echo "$(GREEN)New:$(NC) $(BINARY_NAME) version $(VERSION) (built $(BUILD_TIME))"; \
echo ""; \
read -p "Replace existing installation? [y/N] " confirm; \
if [ "$$confirm" != "y" ] && [ "$$confirm" != "Y" ]; then \
echo "$(YELLOW)Cancelled$(NC)"; \
exit 1; \
fi; \
else \
echo "$(GREEN)Installing:$(NC) $(BINARY_NAME) version $(VERSION) (built $(BUILD_TIME))"; \
fi
cp $(BINARY_DIR)/$(BINARY_NAME) ~/.local/bin/
@echo "$(GREEN)Installed to ~/.local/bin/$(BINARY_NAME)$(NC)"
install-local-force: build
@mkdir -p ~/.local/bin
cp $(BINARY_DIR)/$(BINARY_NAME) ~/.local/bin/
@echo "$(GREEN)Installed to ~/.local/bin/$(BINARY_NAME)$(NC)"
dev: build
./$(BINARY_DIR)/$(BINARY_NAME)
watch:
find . -name '*.go' | entr -c make build
tools:
@echo "$(GREEN)Installing development tools...$(NC)"
go install golang.org/x/tools/cmd/goimports@latest
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
go install github.com/securego/gosec/v2/cmd/gosec@latest
@echo "$(GREEN)Tools installed!$(NC)"
# =============================================================================
# Service targets
# =============================================================================
SERVICE_FILE := engram-agent.service
SERVICE_DIR := $(HOME)/.config/systemd/user
install-service: install-local-force
@mkdir -p $(SERVICE_DIR)
@echo '[Unit]' > $(SERVICE_DIR)/$(SERVICE_FILE)
@echo 'Description=Engram observation extraction, embedding, and sync agent' >> $(SERVICE_DIR)/$(SERVICE_FILE)
@echo 'Documentation=https://github.com/thassiov/engram-agent' >> $(SERVICE_DIR)/$(SERVICE_FILE)
@echo 'After=engram.service' >> $(SERVICE_DIR)/$(SERVICE_FILE)
@echo '' >> $(SERVICE_DIR)/$(SERVICE_FILE)
@echo '[Service]' >> $(SERVICE_DIR)/$(SERVICE_FILE)
@echo 'Type=notify' >> $(SERVICE_DIR)/$(SERVICE_FILE)
@echo 'ExecStart=%h/.local/bin/$(BINARY_NAME) daemon' >> $(SERVICE_DIR)/$(SERVICE_FILE)
@echo 'Restart=on-failure' >> $(SERVICE_DIR)/$(SERVICE_FILE)
@echo 'RestartSec=10' >> $(SERVICE_DIR)/$(SERVICE_FILE)
@echo 'WatchdogSec=120' >> $(SERVICE_DIR)/$(SERVICE_FILE)
@echo 'Environment=HOME=%h' >> $(SERVICE_DIR)/$(SERVICE_FILE)
@echo '' >> $(SERVICE_DIR)/$(SERVICE_FILE)
@echo '[Install]' >> $(SERVICE_DIR)/$(SERVICE_FILE)
@echo 'WantedBy=default.target' >> $(SERVICE_DIR)/$(SERVICE_FILE)
systemctl --user daemon-reload
systemctl --user enable $(SERVICE_FILE)
systemctl --user restart $(SERVICE_FILE)
@echo ""
@echo "$(GREEN)Service installed and started.$(NC)"
@echo " Status: systemctl --user status $(SERVICE_FILE)"
@echo " Logs: journalctl --user -u $(SERVICE_FILE) -f"
@echo " Stop: systemctl --user stop $(SERVICE_FILE)"
@echo " Disable: systemctl --user disable $(SERVICE_FILE)"
uninstall-service:
-systemctl --user stop $(SERVICE_FILE) 2>/dev/null
-systemctl --user disable $(SERVICE_FILE) 2>/dev/null
rm -f $(SERVICE_DIR)/$(SERVICE_FILE)
systemctl --user daemon-reload
@echo "$(GREEN)Service removed.$(NC)"
help:
@echo "Available targets:"
@echo ""
@echo " $(GREEN)Build:$(NC)"
@echo " build - Build engram-agent binary"
@echo " install-local - Build and install to ~/.local/bin"
@echo " install-local-force - Install without confirmation"
@echo ""
@echo " $(GREEN)Test:$(NC)"
@echo " test - Run unit tests"
@echo " coverage - Generate coverage report"
@echo ""
@echo " $(GREEN)Quality:$(NC)"
@echo " fmt - Format code"
@echo " vet - Run go vet"
@echo " lint - Run golangci-lint"
@echo " security - Run security checks"
@echo " check - Quick check (fmt, vet, test, build)"
@echo ""
@echo " $(GREEN)CI Pipeline:$(NC)"
@echo " ci - Full CI pipeline"
@echo ""
@echo " $(GREEN)Service:$(NC)"
@echo " install-service - Build, install, and start systemd service"
@echo " uninstall-service - Stop and remove systemd service"
@echo ""
@echo " $(GREEN)Utility:$(NC)"
@echo " tools - Install development tools"
@echo " clean - Remove build artifacts"
@echo " dev - Build and run"
@echo " watch - Rebuild on changes (requires entr)"
@echo " help - Show this help"