-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
127 lines (108 loc) · 4.43 KB
/
Makefile
File metadata and controls
127 lines (108 loc) · 4.43 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
# Makefile for MarkGo
# Variables
BINARY_NAME=markgo
MAIN_PATH=./cmd/markgo
BUILD_DIR=./build
DOCKER_IMAGE=markgo
DOCKER_TAG=latest
# Go parameters
GOCMD=go
GOBUILD=$(GOCMD) build
GOTEST=$(GOCMD) test
GOMOD=$(GOCMD) mod
GOFMT=gofmt
GOBIN=$(shell $(GOCMD) env GOBIN)
GOLINT=$(or $(shell command -v golangci-lint 2>/dev/null),$(GOBIN)/golangci-lint)
# Build flags
VERSION=$(shell git describe --tags --always --dirty 2>/dev/null || echo "v2.0.0")
GIT_COMMIT=$(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
BUILD_TIME=$(shell date -u '+%Y-%m-%d_%H:%M:%S')
LDFLAGS=-ldflags "-s -w \
-X 'github.com/1mb-dev/markgo/internal/constants.AppVersion=$(VERSION)' \
-X 'github.com/1mb-dev/markgo/internal/constants.GitCommit=$(GIT_COMMIT)' \
-X 'github.com/1mb-dev/markgo/internal/constants.BuildTime=$(BUILD_TIME)'"
BUILD_FLAGS=-trimpath
.PHONY: help build build-release clean test test-race coverage lint fmt run dev docker install tidy
# Default target
help: ## Show this help message
@echo "MarkGo - Available targets:"
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf " \033[36m%-15s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
# Build targets
build: ## Build unified CLI binary (includes all commands)
@echo "Building $(BINARY_NAME)..."
@mkdir -p $(BUILD_DIR)
CGO_ENABLED=0 $(GOBUILD) $(BUILD_FLAGS) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME) $(MAIN_PATH)
@echo "✓ Build complete: $(BUILD_DIR)/$(BINARY_NAME)"
build-release: ## Build for all platforms (Linux, macOS, Windows)
@echo "Building release binaries..."
@mkdir -p $(BUILD_DIR)
@echo " Linux amd64..."
@CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GOBUILD) $(BUILD_FLAGS) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-linux-amd64 $(MAIN_PATH)
@echo " macOS amd64..."
@CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 $(GOBUILD) $(BUILD_FLAGS) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-darwin-amd64 $(MAIN_PATH)
@echo " macOS arm64..."
@CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 $(GOBUILD) $(BUILD_FLAGS) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-darwin-arm64 $(MAIN_PATH)
@echo " Windows amd64..."
@CGO_ENABLED=0 GOOS=windows GOARCH=amd64 $(GOBUILD) $(BUILD_FLAGS) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-windows-amd64.exe $(MAIN_PATH)
@echo "✓ Release builds complete"
# Development targets
run: ## Run the server
@echo "Running $(BINARY_NAME)..."
$(GOCMD) run $(MAIN_PATH)
dev: ## Run in development mode with live reload (requires: go install github.com/air-verse/air@latest)
@echo "Starting development server with live reload..."
ENVIRONMENT=development air -c .air.toml
install: ## Install server binary to GOPATH/bin
@echo "Installing $(BINARY_NAME)..."
$(GOCMD) install $(LDFLAGS) $(MAIN_PATH)
# Testing targets
test: ## Run all tests
@echo "Running tests..."
$(GOTEST) -v ./...
test-race: ## Run tests with race detector
@echo "Running tests with race detection..."
$(GOTEST) -race -v ./...
coverage: ## Generate test coverage report
@echo "Generating coverage report..."
$(GOTEST) -v -coverprofile=coverage.out ./...
$(GOCMD) tool cover -html=coverage.out -o coverage.html
@echo "✓ Coverage report: coverage.html"
@$(GOCMD) tool cover -func=coverage.out | grep total
# Code quality targets
fmt: ## Format code with gofmt
@echo "Formatting code..."
$(GOFMT) -s -w .
$(GOCMD) fmt ./...
@echo "✓ Code formatted"
lint: ## Run linter (requires golangci-lint)
@echo "Running linter..."
@if [ ! -x "$(GOLINT)" ] && ! command -v golangci-lint > /dev/null 2>&1; then \
echo "Error: golangci-lint not found."; \
echo "Install: go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest"; \
exit 1; \
fi
$(GOLINT) run
@echo "✓ Lint complete"
# Dependency management
tidy: ## Tidy and verify dependencies
@echo "Tidying dependencies..."
$(GOMOD) tidy
$(GOMOD) verify
@echo "✓ Dependencies tidied"
# Docker targets
docker: ## Build and run Docker container
@echo "Building Docker image..."
docker build -t $(DOCKER_IMAGE):$(DOCKER_TAG) .
@echo "Running Docker container..."
docker run -p 3000:3000 $(DOCKER_IMAGE):$(DOCKER_TAG)
# Utility targets
clean: ## Clean build artifacts
@echo "Cleaning build artifacts..."
@rm -rf $(BUILD_DIR)
@rm -f coverage.out coverage.html
@echo "✓ Clean complete"
# Note: For benchmarks, profiling, and other advanced tasks, use go test directly:
# Benchmarks: go test -bench=. -benchmem ./...
# CPU Profile: go test -cpuprofile=cpu.prof ./...
# Mem Profile: go test -memprofile=mem.prof ./...
# Profiling: go tool pprof cpu.prof