Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
354 lines (298 loc) · 17.1 KB
/
Copy pathMakefile
File metadata and controls
354 lines (298 loc) · 17.1 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
# HotPlex Worker Gateway - Development Makefile
# Not for production service management.
#
# make help Show commands
# make quickstart First-time setup
# make dev Start dev environment
# make check Quality check (CI)
# ─────────────────────────────────────────────────────────────────────────────
# Configuration
# ─────────────────────────────────────────────────────────────────────────────
BINARY_NAME := hotplex
BUILD_DIR := bin
MAIN_PATH := ./cmd/hotplex
CONFIG_DIR := configs
LOG_DIR := logs
GO_VERSION := $(shell go version | cut -d' ' -f3)
GOOS := $(shell go env GOOS)
GOARCH := $(shell go env GOARCH)
GIT_SHA := $(shell git rev-parse --short=8 HEAD 2>/dev/null || echo "unknown")
BUILD_TIME := $(shell date '+%Y-%m-%dT%H:%M:%S%z')
LDFLAGS := -s -w -X main.version=v1.16.0 -X main.buildTime=$(BUILD_TIME)
BUILD_OPTS := -trimpath
GATEWAY_PID := $(HOME)/.hotplex/.pids/gateway.pid
GATEWAY_LOG := $(LOG_DIR)/hotplex.log
WEB_CHAT_PID := $(HOME)/.hotplex/.pids/hotplex-webchat.pid
WEB_CHAT_PORT := 3000
WEB_CHAT_LOG := $(CURDIR)/$(LOG_DIR)/webchat.log
WEB_CHAT_DIR := webchat
WEB_CHAT_OUT := internal/webchat/out
GRACE_PERIOD := 7
# ─────────────────────────────────────────────────────────────────────────────
# Color
# ─────────────────────────────────────────────────────────────────────────────
RESET := \033[0m
BOLD := \033[1m
DIM := \033[2m
RED := \033[31m
GREEN := \033[32m
YELLOW := \033[33m
CYAN := \033[36m
# ─────────────────────────────────────────────────────────────────────────────
# PHONY
# ─────────────────────────────────────────────────────────────────────────────
.PHONY: all help quickstart hooks check-tools build build-windows build-one run
.PHONY: dev dev-start dev-stop dev-status dev-logs dev-reset
.PHONY: gateway-start gateway-stop gateway-status gateway-logs
.PHONY: webchat-dev webchat-stop webchat-embed webchat-rebuild
.PHONY: docs-build docs-clean docs-lint
.PHONY: test test-short lint fmt quality check clean
# ─────────────────────────────────────────────────────────────────────────────
# Default
# ─────────────────────────────────────────────────────────────────────────────
all: help
# ─────────────────────────────────────────────────────────────────────────────
# Setup
# ─────────────────────────────────────────────────────────────────────────────
quickstart: hooks
@if command -v go > /dev/null 2>&1; then \
$(MAKE) check-tools build test-short; \
echo ""; \
echo " $(GREEN)✓ Developer setup complete$(RESET)"; \
echo ""; \
echo " make dev Start dev environment"; \
echo " make run Run gateway"; \
echo " make help Show all commands"; \
echo ""; \
else \
echo ""; \
echo " $(GREEN)✓ Quickstart complete$(RESET)"; \
echo ""; \
echo " $(DIM)Go not detected — skipping build & tests.$(RESET)"; \
echo ""; \
echo " $(BOLD)Next steps:$(RESET)"; \
echo " 1. Download binary from releases"; \
echo " 2. Run $(CYAN)hotplex onboard$(RESET) to configure"; \
echo " 3. Run $(CYAN)hotplex gateway start$(RESET) to launch"; \
echo ""; \
fi
check-tools:
@$(call check-tool, go, "Go")
@$(call check-tool, golangci-lint, "golangci-lint")
@$(call check-tool, goimports, "goimports")
hooks:
@echo "$(CYAN)Installing git hooks...$(RESET)"
@for hook in scripts/git-hooks/*; do \
name=$$(basename "$$hook"); \
target=".git/hooks/$$name"; \
if [ -L "$$target" ]; then \
echo " $(GREEN)✓$(RESET) $$name (symlink exists)"; \
elif [ -f "$$target" ]; then \
echo " $(YELLOW)⚠$(RESET) $$name (regular file, skipping — remove manually and re-run)"; \
else \
ln -s "$(PWD)/$$hook" "$$target" && \
echo " $(GREEN)✓$(RESET) $$name → $$hook"; \
fi; \
done
@echo " $(DIM)Pre-push runs: fmt → lint → vet → mod verify → build → test$(RESET)"
define check-tool
@if command -v $(1) > /dev/null 2>&1; then \
echo " $(GREEN)✓$(RESET) $(2)"; \
else \
echo " $(YELLOW)⚠$(RESET) $(2) $(DIM)(missing)$(RESET)"; \
fi
endef
# ─────────────────────────────────────────────────────────────────────────────
# Build
# ─────────────────────────────────────────────────────────────────────────────
build: docs-build webchat-embed
@echo "$(CYAN)Building...$(RESET)"
@mkdir -p $(BUILD_DIR) $(LOG_DIR)
@CGO_ENABLED=0 go build $(BUILD_OPTS) -ldflags="$(LDFLAGS)" \
-o $(BUILD_DIR)/$(BINARY_NAME)-$(GOOS)-$(GOARCH) $(MAIN_PATH)
@echo " $(GREEN)✓$(RESET) $(BUILD_DIR)/$(BINARY_NAME)-$(GOOS)-$(GOARCH)"
build-windows:
@echo "$(CYAN)Cross-compiling for Windows...$(RESET)"
@mkdir -p $(BUILD_DIR)
@$(MAKE) build-one GOOS=windows GOARCH=amd64 SUFFIX=.exe --no-print-directory
@$(MAKE) build-one GOOS=windows GOARCH=arm64 SUFFIX=.exe --no-print-directory
build-one:
@CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) go build $(BUILD_OPTS) -ldflags="$(LDFLAGS)" \
-o $(BUILD_DIR)/$(BINARY_NAME)-$(GOOS)-$(GOARCH)$(SUFFIX) $(MAIN_PATH)
@echo " $(GREEN)✓$(RESET) $(BUILD_DIR)/$(BINARY_NAME)-$(GOOS)-$(GOARCH)$(SUFFIX)"
run: build
@./$(BUILD_DIR)/$(BINARY_NAME)-$(GOOS)-$(GOARCH) \
gateway start -c $(CONFIG_DIR)/config-dev.yaml
# ─────────────────────────────────────────────────────────────────────────────
# Test
# ─────────────────────────────────────────────────────────────────────────────
test:
@echo "$(CYAN)Testing...$(RESET)"
@GORACE="history_size=5" go test -race -timeout 15m ./...
@echo " $(GREEN)✓ Tests passed$(RESET)"
test-short:
@echo "$(CYAN)Testing...$(RESET)"
@GORACE="history_size=5" go test -short -race -timeout 5m ./...
@echo " $(GREEN)✓ Tests passed$(RESET)"
coverage:
@echo "$(CYAN)Generating coverage report...$(RESET)"
@go test -timeout=15m -coverprofile=coverage.out -covermode=atomic \
$$(go list ./... | grep -v -e 'internal/worker/proc' -e 'internal/worker/pi' -e 'cmd/hotplex')
@echo ""
@echo "$(BOLD)Per-package coverage:$(RESET)"
@go tool cover -func=coverage.out | grep -v "^total:" | sort -t: -k3 -n
@echo ""
@TOTAL=$$(go tool cover -func=coverage.out | tail -1 | grep -oP '\d+\.\d+') ; \
echo " $(BOLD)Total: $${TOTAL}%$(RESET)"
test-slack-e2e:
@echo "$(CYAN)Running Slack semi-automated E2E tests...$(RESET)"
@test -n "$$SLACK_BOT_TOKEN" || (echo " $(RED)SLACK_BOT_TOKEN required$(RESET)"; exit 1)
@test -n "$$SLACK_APP_TOKEN" || (echo " $(RED)SLACK_APP_TOKEN required$(RESET)"; exit 1)
@go test -v -tags=slack_e2e -timeout 30m ./internal/messaging/slack/...
# ─────────────────────────────────────────────────────────────────────────────
# Quality
# ─────────────────────────────────────────────────────────────────────────────
lint:
@echo "$(CYAN)Linting...$(RESET)"
@golangci-lint run ./...
fmt:
@echo "$(CYAN)Formatting...$(RESET)"
@go fmt ./...
@if command -v goimports > /dev/null 2>&1; then goimports -w .; fi
quality: fmt lint test
@echo ""
@echo " $(GREEN)✓ All checks passed$(RESET)"
@echo ""
check: quality build
@echo " $(GREEN)✓ CI check passed$(RESET)"
# ─────────────────────────────────────────────────────────────────────────────
# Dev Environment
# ─────────────────────────────────────────────────────────────────────────────
dev: dev-start
@echo ""
@echo " $(DIM)─────────────────────────────────────$(RESET)"
@echo " $(GREEN)✓ Dev environment ready$(RESET)"
@echo ""
@printf " make %-12s %s\n" "dev-logs" "View logs"
@printf " make %-12s %s\n" "dev-status" "Check status"
@printf " make %-12s %s\n" "dev-stop" "Stop all"
@echo ""
dev-start: gateway-start
@$(MAKE) webchat-dev || echo " $(YELLOW)⚠$(RESET) Webchat skipped (run 'cd webchat && pnpm install' to fix)"
dev-stop: webchat-stop gateway-stop
@echo " $(GREEN)✓ Dev environment stopped$(RESET)"
dev-status:
@./scripts/dev.sh status all
dev-logs:
@./scripts/dev.sh logs all
dev-reset: dev-stop dev-start
# ─────────────────────────────────────────────────────────────────────────────
# Gateway
# ─────────────────────────────────────────────────────────────────────────────
gateway-start: build
@./scripts/dev.sh start gateway
gateway-stop:
@./scripts/dev.sh stop gateway
gateway-status:
@./scripts/dev.sh status gateway
gateway-logs:
@./scripts/dev.sh logs gateway
# ─────────────────────────────────────────────────────────────────────────────
# Webchat
# ─────────────────────────────────────────────────────────────────────────────
webchat-dev:
@./scripts/dev.sh start webchat
webchat-stop:
@./scripts/dev.sh stop webchat
webchat-embed:
@if [ ! -d $(WEB_CHAT_OUT)/_next ]; then \
echo "$(CYAN)Building webchat for embedding...$(RESET)"; \
cd $(WEB_CHAT_DIR) && pnpm install --frozen-lockfile && pnpm build && \
rm -rf ../$(WEB_CHAT_OUT).tmp && cp -r out ../$(WEB_CHAT_OUT).tmp && \
rm -rf ../$(WEB_CHAT_OUT) && mv ../$(WEB_CHAT_OUT).tmp ../$(WEB_CHAT_OUT); \
fi
webchat-rebuild:
@echo "$(CYAN)Rebuilding webchat...$(RESET)"
@cd $(WEB_CHAT_DIR) && pnpm build && \
rm -rf ../$(WEB_CHAT_OUT).tmp && cp -r out ../$(WEB_CHAT_OUT).tmp && \
rm -rf ../$(WEB_CHAT_OUT) && mv ../$(WEB_CHAT_OUT).tmp ../$(WEB_CHAT_OUT)
@echo " $(GREEN)✓$(RESET) Webchat rebuilt"
# ─────────────────────────────────────────────────────────────────────────────
# Documentation
# ─────────────────────────────────────────────────────────────────────────────
docs-build:
@echo "$(CYAN)Building documentation...$(RESET)"
@go run cmd/build-docs/main.go
@echo " $(GREEN)✓$(RESET) Documentation built"
docs-clean:
@rm -rf internal/docs/out
@echo " $(GREEN)✓$(RESET) Documentation cleaned"
docs-lint: docs-build
@echo "$(CYAN)Docs link validation passed$(RESET)"
# ─────────────────────────────────────────────────────────────────────────────
# Clean
# ─────────────────────────────────────────────────────────────────────────────
clean:
@go clean
@rm -rf $(BUILD_DIR)
@rm -f coverage.out
@echo " $(GREEN)✓$(RESET) Cleaned"
# ─────────────────────────────────────────────────────────────────────────────
# Help
# ─────────────────────────────────────────────────────────────────────────────
help:
@echo ""
@echo " $(CYAN)━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━$(RESET)"
@echo " $(CYAN) ⚡ HotPlex Worker$(RESET) $(GIT_SHA) $(GOOS)/$(GOARCH)"
@echo " $(CYAN)━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━$(RESET)"
@echo ""
@echo " $(BOLD)⚡ Start"
@printf " $(CYAN)make %-15s$(RESET) %s\n" "dev" "Start all services (gateway + webchat)"
@printf " $(CYAN)make %-15s$(RESET) %s\n" "dev-start" "Start individually"
@echo ""
@echo " $(BOLD)⏹ Stop"
@printf " $(CYAN)make %-15s$(RESET) %s\n" "dev-stop" "Stop all services"
@printf " $(CYAN)make %-15s$(RESET) %s\n" "gateway-stop" "Stop gateway"
@printf " $(CYAN)make %-15s$(RESET) %s\n" "webchat-stop" "Stop webchat"
@echo ""
@echo " $(BOLD)🔧 Build"
@printf " $(CYAN)make %-15s$(RESET) %s\n" "build" "Build binary"
@printf " $(CYAN)make %-15s$(RESET) %s\n" "build-windows" "Cross-compile for Windows"
@printf " $(CYAN)make %-15s$(RESET) %s\n" "run" "Build and run (foreground)"
@echo ""
@echo " $(BOLD)🧪 Test & Quality"
@printf " $(CYAN)make %-15s$(RESET) %s\n" "test" "All tests (race, 15m)"
@printf " $(CYAN)make %-15s$(RESET) %s\n" "test-short" "Short tests (5m)"
@printf " $(CYAN)make %-15s$(RESET) %s\n" "lint" "Run linter"
@printf " $(CYAN)make %-15s$(RESET) %s\n" "fmt" "Format code"
@printf " $(CYAN)make %-15s$(RESET) %s\n" "quality" "fmt + lint + test"
@printf " $(CYAN)make %-15s$(RESET) %s\n" "check" "quality + build (CI)"
@echo ""
@echo " $(BOLD)📊 Status & Logs"
@printf " $(CYAN)make %-15s$(RESET) %s\n" "dev-status" "All services"
@printf " $(CYAN)make %-15s$(RESET) %s\n" "gateway-status" "Gateway"
@printf " $(CYAN)make %-15s$(RESET) %s\n" "dev-logs" "View all logs"
@printf " $(CYAN)make %-15s$(RESET) %s\n" "gateway-logs" "Gateway logs"
@echo ""
@echo " $(BOLD)📖 Documentation"
@printf " $(CYAN)make %-15s$(RESET) %s\n" "docs-build" "Build static HTML docs"
@printf " $(CYAN)make %-15s$(RESET) %s\n" "docs-clean" "Remove generated docs"
@echo ""
@echo " $(BOLD)🔄 Workflow"
@printf " $(CYAN)make %-15s$(RESET) %s\n" "dev-reset" "Restart all services"
@printf " $(CYAN)make %-15s$(RESET) %s\n" "quickstart" "First-time setup"
@echo ""
@echo " $(BOLD)🧹 Other"
@printf " $(CYAN)make %-15s$(RESET) %s\n" "clean" "Clean artifacts"
@printf " $(CYAN)make %-15s$(RESET) %s\n" "check-tools" "Check dev tools"
@printf " $(CYAN)make %-15s$(RESET) %s\n" "hooks" "Install git hooks"
@echo ""
@echo " $(DIM)Try: make dev | make test | make check"
@echo ""
# Catch-all
%:
@echo ""
@echo " $(RED)Unknown: make $@$(RESET)"
@echo " make help Show commands"
@echo ""
@exit 1