-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathMakefile
More file actions
149 lines (127 loc) · 6.22 KB
/
Copy pathMakefile
File metadata and controls
149 lines (127 loc) · 6.22 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
.PHONY: help build build-frontend build-backend run swagger migrate test clean install-tools dev build-docker-pixi build-docker-uv build-docker test-pkgmgr build-all build-desktop
# Variables
BINARY_NAME=nebi
FRONTEND_DIR=frontend
BUILD_DIR=bin
VERSION=$(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
COMMIT=$(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
LDFLAGS=-ldflags "-s -w -X main.Version=$(VERSION) -X main.Commit=$(COMMIT)"
BUILDFLAGS=-trimpath
help: ## Show this help message
@echo 'Usage: make [target]'
@echo ''
@echo 'Available targets:'
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-15s\033[0m %s\n", $$1, $$2}'
install-tools: ## Install development tools (swag, air, golangci-lint)
@echo "Installing swag..."
@go install github.com/swaggo/swag/cmd/swag@latest
@echo "Installing air..."
@go install github.com/air-verse/air@latest
@echo "Installing golangci-lint v2.12.2..."
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$(go env GOPATH)/bin v2.12.2
@echo "Tools installed successfully"
swagger: ## Generate Swagger documentation
@echo "Generating Swagger docs..."
@PATH="$$PATH:$$(go env GOPATH)/bin"; command -v swag >/dev/null 2>&1 || { echo "swag not found, installing..."; go install github.com/swaggo/swag/cmd/swag@latest; }
@PATH="$$PATH:$$(go env GOPATH)/bin" swag init -g serve.go -d cmd/nebi,internal/api,internal/service,internal/models,internal/limits,internal/metrics,internal/auth -o internal/swagger --packageName swagger --exclude output,cross-platform-example
@echo "Swagger docs generated at /internal/swagger"
build-frontend: ## Build frontend and copy to internal/web/dist
@echo "Building frontend..."
@cd $(FRONTEND_DIR) && npm install && npm run build
@echo "Copying frontend build to internal/web/dist..."
@rm -rf internal/web/dist
@cp -r $(FRONTEND_DIR)/dist internal/web/dist
@echo "Frontend build complete"
build-backend: swagger ## Build nebi binary
@echo "Building nebi..."
@mkdir -p $(BUILD_DIR)
@go build $(BUILDFLAGS) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME) ./cmd/nebi
@echo "Build complete: $(BUILD_DIR)/$(BINARY_NAME)"
build: build-frontend build-backend ## Build complete single binary (frontend + backend)
@echo "Single binary build complete: $(BUILD_DIR)/$(BINARY_NAME)"
run: build ## Run the server (without hot reload)
@echo "Starting nebi server..."
@if [ -f .env ]; then \
echo "✓ Loading environment variables from .env..."; \
fi
@bash -c 'set -a; [ -f .env ] && source .env; set +a; $(BUILD_DIR)/$(BINARY_NAME) serve'
dev: swagger ## Run with hot reload (frontend + backend)
@echo "Starting nebi in development mode with hot reload..."
@if [ ! -d "frontend/node_modules" ]; then \
echo "Frontend dependencies not found. Installing..."; \
cd frontend && npm install; \
fi
@echo ""
@if [ -f .env ]; then \
echo "✓ Loading environment variables from .env..."; \
else \
echo "⚠️ Warning: .env file not found. Using defaults."; \
fi
@echo "🚀 Starting services..."
@echo " Frontend: http://localhost:8461"
@echo " Backend: http://localhost:8460"
@echo " API Docs: http://localhost:8460/docs"
@echo ""
@echo "Press Ctrl+C to stop all services"
@echo ""
@command -v air >/dev/null 2>&1 || { echo "air not found, installing..."; go install github.com/air-verse/air@latest; }
@bash -c 'export PATH="$$PATH:$$(go env GOPATH)/bin"; set -a; [ -f .env ] && source .env; set +a; trap "kill 0" EXIT; (cd frontend && npm run dev) & air'
migrate: ## Run database migrations
@echo "Running migrations..."
@go run cmd/nebi/main.go serve
test: ## Run tests (unit + e2e)
@echo "Running tests..."
@go test -tags=e2e -v ./...
clean: ## Clean build artifacts
@echo "Cleaning..."
@rm -rf bin/
@rm -rf internal/swagger/
@rm -rf internal/web/dist
@rm -rf $(FRONTEND_DIR)/dist
@rm -f nebi.db
@echo "Clean complete"
tidy: ## Tidy go.mod
@echo "Tidying go.mod..."
@go mod tidy
fmt: ## Format Go code
@echo "Formatting code..."
@go fmt ./...
vet: ## Run go vet
@echo "Running go vet..."
@go vet ./...
lint: fmt ## Run formatters and linters (matches CI)
@echo "Running golangci-lint..."
@command -v golangci-lint >/dev/null 2>&1 || { echo "golangci-lint not found, installing..."; curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$(go env GOPATH)/bin v2.12.2; }
@PATH="$$PATH:$$(go env GOPATH)/bin" golangci-lint run ./...
@echo "Lint complete"
build-docker-pixi: ## Build pixi Docker image
@echo "Building pixi Docker image..."
@docker build -f docker/pixi.Dockerfile -t nebi-pixi:latest .
@echo "Docker image built: nebi-pixi:latest"
build-docker-uv: ## Build uv Docker image
@echo "Building uv Docker image..."
@docker build -f docker/uv.Dockerfile -t nebi-uv:latest .
@echo "Docker image built: nebi-uv:latest"
build-docker: build-docker-pixi build-docker-uv ## Build all Docker images
@echo "All Docker images built successfully"
test-pkgmgr: ## Test package manager operations
@echo "Running package manager tests..."
@go test -v ./internal/pkgmgr/...
build-all: build-frontend ## Build binaries for all platforms
@echo "Building for all platforms..."
@mkdir -p $(BUILD_DIR)
@echo "Building linux/amd64..."
@GOOS=linux GOARCH=amd64 go build $(BUILDFLAGS) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-linux-amd64 ./cmd/nebi
@echo "Building linux/arm64..."
@GOOS=linux GOARCH=arm64 go build $(BUILDFLAGS) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-linux-arm64 ./cmd/nebi
@echo "Building darwin/amd64..."
@GOOS=darwin GOARCH=amd64 go build $(BUILDFLAGS) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-darwin-amd64 ./cmd/nebi
@echo "Building darwin/arm64..."
@GOOS=darwin GOARCH=arm64 go build $(BUILDFLAGS) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-darwin-arm64 ./cmd/nebi
@echo "Building windows/amd64..."
@GOOS=windows GOARCH=amd64 go build $(BUILDFLAGS) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-windows-amd64.exe ./cmd/nebi
@echo "All platform builds complete"
build-desktop: build-frontend ## Build Wails desktop app with version info
@echo "Building desktop app..."
@wails build -ldflags "-X main.Version=$(VERSION) -X main.Commit=$(COMMIT)"
@echo "Desktop app built: build/bin/Nebi.app"