forked from compozy/compozy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
216 lines (183 loc) · 9.54 KB
/
Makefile
File metadata and controls
216 lines (183 loc) · 9.54 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
-include .env
# Makefile for Compozy
# -----------------------------------------------------------------------------
# Go Parameters & Setup
# -----------------------------------------------------------------------------
GOCMD=$(shell which go)
GOVERSION ?= $(shell awk '/^go /{print $$2}' go.mod 2>/dev/null || echo "1.26")
BUN_VERSION ?= $(shell cat .bun-version 2>/dev/null || echo "1.3.11")
BUNCMD=$(shell which bun)
GOBUILD=$(GOCMD) build
GOTEST=$(GOCMD) test
GOFMT=gofmt -s -w
BINARY_NAME=compozy
BINARY_DIR=bin
SRC_DIRS=./...
GOLANGCI_LINT_VERSION=v2.11.4
GOTESTSUM_VERSION=v1.13.0
LINTCMD=$(GOCMD) run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)
GOTESTSUMCMD=$(GOCMD) run gotest.tools/gotestsum@$(GOTESTSUM_VERSION)
# Colors for output
RED := \033[0;31m
GREEN := \033[0;32m
YELLOW := \033[0;33m
NC := \033[0m # No Color
# -----------------------------------------------------------------------------
# Build Variables
# -----------------------------------------------------------------------------
GIT_COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
VERSION := $(shell git describe --tags --match="v*" --always 2>/dev/null || echo "unknown")
# Build flags for injecting version info (aligned with GoReleaser format)
BUILD_DATE := $(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
MODULE_PATH := $(shell $(GOCMD) list -m 2>/dev/null)
ifeq ($(MODULE_PATH),)
MODULE_PATH := github.com/compozy/compozy
endif
LDFLAGS := -X $(MODULE_PATH)/internal/version.Version=$(VERSION) -X $(MODULE_PATH)/internal/version.Commit=$(GIT_COMMIT) -X $(MODULE_PATH)/internal/version.Date=$(BUILD_DATE)
.PHONY: all test lint fmt clean build install deps help verify tidy test-coverage test-nocache check-go-version check-bun-version setup link-skills build-extension-sdks publish-extension-sdks go-build frontend-bootstrap frontend-lint frontend-typecheck frontend-test frontend-build frontend-e2e frontend-verify dev
# -----------------------------------------------------------------------------
# Setup & Version Checks
# -----------------------------------------------------------------------------
check-go-version:
@echo "Checking Go version..."
@GO_VERSION=$$($(GOCMD) version 2>/dev/null | awk '{print $$3}' | sed 's/go//'); \
REQUIRED_VERSION=$(GOVERSION); \
if [ -z "$$GO_VERSION" ]; then \
echo "$(RED)Error: Go is not available$(NC)"; \
echo "Please ensure Go $(GOVERSION) is installed via mise"; \
exit 1; \
elif CURRENT_NUM=$$(echo "$$GO_VERSION" | awk -F. '{maj=$$1+0; min=($$2==""?0:$$2)+0; pat=($$3==""?0:$$3)+0; printf "%03d%03d%03d", maj, min, pat}'); \
REQUIRED_NUM=$$(echo "$$REQUIRED_VERSION" | awk -F. '{maj=$$1+0; min=($$2==""?0:$$2)+0; pat=($$3==""?0:$$3)+0; printf "%03d%03d%03d", maj, min, pat}'); \
[ "$$CURRENT_NUM" -lt "$$REQUIRED_NUM" ]; then \
echo "$(YELLOW)Warning: Go version $$GO_VERSION found, but $(GOVERSION) is required$(NC)"; \
echo "Please update Go to version $(GOVERSION) with: mise use go@$(GOVERSION)"; \
exit 1; \
else \
echo "$(GREEN)Go version $$GO_VERSION is compatible$(NC)"; \
fi
check-bun-version:
@echo "Checking Bun version..."
@if [ -z "$(BUNCMD)" ]; then \
echo "$(RED)Error: Bun is not available$(NC)"; \
echo "Please install Bun $(BUN_VERSION) or newer before running frontend verification"; \
exit 1; \
fi
@REQUIRED_VERSION=$(BUN_VERSION); \
CURRENT_VERSION=$$($(BUNCMD) --version 2>/dev/null | tr -d '\n'); \
if [ -z "$$CURRENT_VERSION" ]; then \
echo "$(RED)Error: Unable to determine Bun version$(NC)"; \
exit 1; \
elif CURRENT_NUM=$$(echo "$$CURRENT_VERSION" | awk -F. '{maj=$$1; min=$$2; pat=$$3; gsub(/[^0-9]/, "", maj); gsub(/[^0-9]/, "", min); gsub(/[^0-9]/, "", pat); printf "%03d%03d%03d", (maj==""?0:maj)+0, (min==""?0:min)+0, (pat==""?0:pat)+0}'); \
REQUIRED_NUM=$$(echo "$$REQUIRED_VERSION" | awk -F. '{maj=$$1; min=$$2; pat=$$3; gsub(/[^0-9]/, "", maj); gsub(/[^0-9]/, "", min); gsub(/[^0-9]/, "", pat); printf "%03d%03d%03d", (maj==""?0:maj)+0, (min==""?0:min)+0, (pat==""?0:pat)+0}'); \
[ "$$CURRENT_NUM" -lt "$$REQUIRED_NUM" ]; then \
echo "$(YELLOW)Warning: Bun version $$CURRENT_VERSION found, but $$REQUIRED_VERSION or newer is required$(NC)"; \
echo "Please upgrade Bun to at least $$REQUIRED_VERSION before running frontend verification"; \
exit 1; \
else \
echo "$(GREEN)Bun version $$CURRENT_VERSION is compatible (minimum $$REQUIRED_VERSION)$(NC)"; \
fi
link-skills:
@bash scripts/link-skills.sh
setup: check-go-version deps link-skills
@echo "$(GREEN)Setup complete! You can now run 'make build' or 'make verify'$(NC)"
# -----------------------------------------------------------------------------
# Main Targets
# -----------------------------------------------------------------------------
all: test lint fmt
clean:
rm -rf $(BINARY_DIR)/
$(GOCMD) clean
build: frontend-build go-build
go-build: check-go-version
mkdir -p $(BINARY_DIR)
$(GOBUILD) -ldflags "$(LDFLAGS)" -o $(BINARY_DIR)/$(BINARY_NAME) ./cmd/compozy
chmod +x $(BINARY_DIR)/$(BINARY_NAME)
build-extension-sdks:
npm run build --workspace @compozy/extension-sdk --workspace @compozy/create-extension
publish-extension-sdks: verify build-extension-sdks
npm publish --workspace @compozy/extension-sdk --access public
npm publish --workspace @compozy/create-extension --access public
install: build
$(GOCMD) install -ldflags "$(LDFLAGS)" ./cmd/compozy
# -----------------------------------------------------------------------------
# Code Quality & Formatting
# -----------------------------------------------------------------------------
lint:
$(LINTCMD) run --fix --allow-parallel-runners
@echo "Linting completed successfully"
fmt:
@echo "Formatting code..."
$(LINTCMD) fmt
@echo "Formatting completed successfully"
# -----------------------------------------------------------------------------
# Frontend Verification
# -----------------------------------------------------------------------------
frontend-bootstrap: check-bun-version
$(BUNCMD) run frontend:bootstrap
frontend-lint: frontend-bootstrap
$(BUNCMD) run frontend:lint
frontend-typecheck: frontend-bootstrap
$(BUNCMD) run frontend:typecheck
frontend-test: frontend-bootstrap
$(BUNCMD) run frontend:test
frontend-build: frontend-bootstrap
$(BUNCMD) run frontend:build
frontend-e2e: frontend-build go-build
$(BUNCMD) run frontend:e2e
frontend-verify: frontend-lint frontend-typecheck frontend-test frontend-build
# -----------------------------------------------------------------------------
# Verification Pipeline (BLOCKING GATE for any change)
# -----------------------------------------------------------------------------
verify: frontend-verify fmt lint test go-build frontend-e2e
@echo "$(GREEN)All verification checks passed$(NC)"
# -----------------------------------------------------------------------------
# Development & Dependencies
# -----------------------------------------------------------------------------
dev: go-build
./$(BINARY_DIR)/$(BINARY_NAME) daemon start --foreground --web-dev-proxy http://127.0.0.1:3000
tidy:
@echo "Tidying modules..."
$(GOCMD) mod tidy
deps: check-go-version
@echo "Installing Go dependencies..."
@echo "Installing gotestsum..."
@$(GOCMD) install gotest.tools/gotestsum@$(GOTESTSUM_VERSION)
@echo "Installing golangci-lint v2..."
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/install.sh | sh -s -- -b $$($(GOCMD) env GOPATH)/bin $(GOLANGCI_LINT_VERSION)
@echo "$(GREEN)All dependencies installed successfully$(NC)"
# -----------------------------------------------------------------------------
# Testing
# -----------------------------------------------------------------------------
test:
@$(GOTESTSUMCMD) --format pkgname -- -race -parallel=4 ./...
test-coverage:
@$(GOTESTSUMCMD) --format pkgname -- -race -parallel=4 -coverprofile=coverage.out -covermode=atomic ./...
test-nocache:
@$(GOTESTSUMCMD) --format pkgname -- -race -count=1 -parallel=4 ./...
# -----------------------------------------------------------------------------
# Help
# -----------------------------------------------------------------------------
help:
@echo "Available targets:"
@echo " make build - Build the compozy binary"
@echo " make build-extension-sdks - Build the npm extension SDK and scaffolder packages"
@echo " make install - Build and install to GOPATH/bin"
@echo " make frontend-bootstrap - Install Bun dependencies for the frontend workspaces"
@echo " make frontend-lint - Run frontend lint/format checks"
@echo " make frontend-typecheck - Run frontend workspace typechecks"
@echo " make frontend-test - Run frontend workspace tests"
@echo " make frontend-build - Build frontend workspaces and restore web/dist placeholder"
@echo " make frontend-e2e - Run Playwright against the daemon-served embedded UI"
@echo " make dev - Start ./bin/compozy with the Vite dev proxy; run `bun run --cwd web dev` separately"
@echo " make test - Run tests with race detector"
@echo " make lint - Run golangci-lint"
@echo " make fmt - Format code"
@echo " make verify - Run frontend verification, Go verification, and daemon-served Playwright"
@echo " make deps - Install development dependencies"
@echo " make tidy - Tidy Go modules"
@echo " make clean - Remove build artifacts"
@echo " make setup - Full setup (check Go version + deps)"
@echo " make publish-extension-sdks - Publish the npm extension SDK and scaffolder packages"
@echo " make test-coverage - Run tests with coverage"
@echo " make test-nocache - Run tests without cache"
@echo " make help - Show this help"