-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathMakefile
More file actions
137 lines (109 loc) · 4.73 KB
/
Copy pathMakefile
File metadata and controls
137 lines (109 loc) · 4.73 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
SHELL := /bin/bash
# Resolve each tool from $PATH first, then fall back to its common install
# location. Override any of them explicitly, e.g. `make GO=/opt/go/bin/go build`.
# `tool <name> <fallback>` = the binary on PATH if present, else the fallback.
tool = $(shell command -v $(1) 2>/dev/null || echo $(2))
GO ?= $(call tool,go,$(HOME)/.local/sdk/go/bin/go)
BUN ?= $(call tool,bun,$(HOME)/.bun/bin/bun)
# air lives in GOPATH/bin after `make install`; if GOPATH can't be read, use the
# conventional ~/go.
GOPATH ?= $(shell $(GO) env GOPATH 2>/dev/null || echo $(HOME)/go)
AIR ?= $(call tool,air,$(GOPATH)/bin/air)
PREFIX ?= $(HOME)/.local
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo 0.1.0-dev)
COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo dev)
DATE ?= $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
LDFLAGS := -s -w \
-X github.com/enowdev/antares/internal/version.Version=$(VERSION) \
-X github.com/enowdev/antares/internal/version.Commit=$(COMMIT) \
-X github.com/enowdev/antares/internal/version.Date=$(DATE)
.PHONY: help
help: ## Show this help
@grep -hE '^[a-zA-Z_-]+:.*?## ' $(MAKEFILE_LIST) \
| awk 'BEGIN{FS=":.*?## "}{printf " \033[36m%-14s\033[0m %s\n", $$1, $$2}'
# ---- development ------------------------------------------------------------
.PHONY: dev
dev: ## Run backend (Air hot reload) and frontend (Vite HMR) together
@echo "Antares dev: API :8787 · Web :5173"
@trap 'kill 0' EXIT INT TERM; \
$(MAKE) dev-api & \
$(MAKE) dev-web & \
wait
.PHONY: dev-api
dev-api: ## Backend with hot reload
@$(AIR) -c .air.toml
.PHONY: dev-web
dev-web: ## Frontend dev server with HMR
@cd web && $(BUN) x vite
.PHONY: tui
tui: ## Hot-reload the TUI preview in the foreground (real terminal)
@./scripts/tui-dev.sh
.PHONY: install
install: ## Install toolchain deps (no sudo)
@$(GO) mod download
@$(GO) install github.com/air-verse/air@latest
@cd web && $(BUN) install
# ---- build ------------------------------------------------------------------
.PHONY: build
build: build-web ## Build the shipped `antares` binary with the dashboard embedded
@$(GO) build -trimpath -ldflags "$(LDFLAGS)" -o bin/antares ./cmd/antares
@echo "built bin/antares ($(VERSION))"
.PHONY: build-web
build-web: ## Build the dashboard into internal/server/dist
@cd web && $(BUN) run build
@rm -rf internal/server/dist
@cp -r web/dist internal/server/dist
# `//go:embed all:dist` requires at least one tracked file; the placeholder
# is committed as internal/server/dist/.gitkeep so a clean checkout can
# `go build` without a prior `bun run build`. `cp -r web/dist ...` above
# blows the placeholder away, so restore it here — narrowly, no broad
# cleanup of anything else the dashboard produced.
@touch internal/server/dist/.gitkeep
.PHONY: build-fixture
build-fixture: ## Build the smoke-only fixture helper (cmd/smokefixture)
@$(GO) build -trimpath -o bin/smokefixture ./cmd/smokefixture
.PHONY: build-api
build-api: ## Build the backend only (no dashboard)
@$(GO) build -trimpath -ldflags "$(LDFLAGS)" -o bin/antares ./cmd/antares
.PHONY: install-cli
install-cli: build ## Build (with dashboard) and install `antares` to $(PREFIX)/bin
@mkdir -p $(PREFIX)/bin
@cp bin/antares $(PREFIX)/bin/antares.new
@mv -f $(PREFIX)/bin/antares.new $(PREFIX)/bin/antares
@echo "installed $(PREFIX)/bin/antares ($(VERSION))"
@case ":$$PATH:" in *":$(PREFIX)/bin:"*) echo "run 'antares' from anywhere (open a new shell if it's not found yet)";; \
*) echo "note: add $(PREFIX)/bin to your PATH — e.g. echo 'export PATH=\"$(PREFIX)/bin:\$$PATH\"' >> ~/.bashrc";; esac
# ---- quality ----------------------------------------------------------------
.PHONY: test
test: ## Run Go tests
@$(GO) test ./...
.PHONY: vet
vet: ## Run go vet
@$(GO) vet ./...
.PHONY: typecheck
typecheck: ## Typecheck the frontend
@cd web && $(BUN) x tsc -b --noEmit
.PHONY: web-test
web-test: ## Run frontend regression tests
@cd web && $(BUN) test
.PHONY: smoke
smoke: build build-fixture ## Build antares + the smoke fixture, then load every dashboard route in a real browser
@$(BUN) scripts/smoke-run.mjs
.PHONY: check
check: vet test typecheck web-test ## Run every check (add `make smoke` for the browser pass)
.PHONY: fmt
fmt: ## Format Go sources
@$(GO) fmt ./...
.PHONY: sync-models
sync-models: ## Refresh internal/providers/models_generated.json from models.dev
@$(GO) run ./scripts/sync-models-dev.go
.PHONY: release
release: ## Cross-compile release binaries for all platforms into dist/release
@VERSION="$(VERSION)" GO="$(GO)" BUN="$(BUN)" ./scripts/release-build.sh
.PHONY: clean
clean: ## Remove build artefacts
@rm -rf bin .air web/dist dist
@echo "cleaned"
.PHONY: doctor
doctor: ## Diagnose the local setup
@$(GO) run ./cmd/antares doctor