-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
116 lines (95 loc) · 2.97 KB
/
Makefile
File metadata and controls
116 lines (95 loc) · 2.97 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
# Go parameters
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get
GOMOD=$(GOCMD) mod
GOFMT=gofmt
GOLINT=golangci-lint
# Build info
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
BUILD_TIME=$(shell date -u '+%Y-%m-%d_%H:%M:%S')
LDFLAGS=-ldflags "-X main.version=$(VERSION) -X main.buildTime=$(BUILD_TIME)"
# Directories
BUILD_DIR=build
COVERAGE_DIR=coverage
.PHONY: all build clean test coverage benchmark lint fmt help
# Default target
all: fmt lint test build ## Run fmt, lint, test and build
# Build the library and tools
build: ## Build binaries
@echo "Building binaries..."
@mkdir -p $(BUILD_DIR)
$(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/convert ./cmd/convert
# Clean build artifacts
clean: ## Clean build artifacts
@echo "Cleaning..."
$(GOCLEAN)
@rm -rf $(BUILD_DIR)
@rm -rf $(COVERAGE_DIR)
# Run tests
test: ## Run tests
@echo "Running tests..."
$(GOTEST) -v ./...
# Run tests with coverage
coverage: ## Run tests with coverage
@echo "Running tests with coverage..."
@mkdir -p $(COVERAGE_DIR)
$(GOTEST) -coverprofile=$(COVERAGE_DIR)/coverage.out ./...
$(GOCMD) tool cover -html=$(COVERAGE_DIR)/coverage.out -o $(COVERAGE_DIR)/coverage.html
@echo "Coverage report generated: $(COVERAGE_DIR)/coverage.html"
# Run benchmarks
benchmark: ## Run benchmarks
@echo "Running benchmarks..."
$(GOTEST) -bench=. -benchmem ./...
# Run linter
lint: ## Run linter
@echo "Running linter..."
$(GOLINT) run
# Format code
fmt: ## Format code
@echo "Formatting code..."
$(GOFMT) -s -w .
$(GOCMD) mod tidy
# Vet code
vet: ## Vet code
@echo "Vetting code..."
$(GOCMD) vet ./...
# Check for updates
check-updates: ## Check for module updates
@echo "Checking for updates..."
$(GOGET) -u ./...
$(GOMOD) tidy
# Generate documentation
docs: ## Generate documentation
@echo "Generating documentation..."
@$(GOCMD) doc -all . > docs/API.md
# Install development dependencies
install-dev: ## Install development dependencies
@echo "Installing development dependencies..."
$(GOGET) github.com/golangci/golangci-lint/cmd/golangci-lint@latest
# Pre-commit checks
pre-commit: fmt vet lint test ## Run pre-commit checks
# Release preparation
release-check: pre-commit coverage benchmark ## Run all checks for release
# Performance profiling
profile-cpu: ## Run CPU profiling
@echo "Running CPU profiling..."
$(GOTEST) -cpuprofile=cpu.prof -bench=. ./...
$(GOCMD) tool pprof cpu.prof
profile-mem: ## Run memory profiling
@echo "Running memory profiling..."
$(GOTEST) -memprofile=mem.prof -bench=. ./...
$(GOCMD) tool pprof mem.prof
# Generate test data
generate-testdata: ## Generate test data
@echo "Generating test data..."
$(GOBUILD) -o $(BUILD_DIR)/testdata-gen ./tools/testdata-gen
./$(BUILD_DIR)/testdata-gen
# Show help
help: ## Show this help message
@echo 'Usage: make [target]'
@echo ''
@echo 'Targets:'
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf " \033[36m%-15s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)