-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathMakefile
More file actions
173 lines (145 loc) · 5.68 KB
/
Makefile
File metadata and controls
173 lines (145 loc) · 5.68 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
.PHONY: help all build test test-race test-coverage treemap test-verbose lint fmt fmt-check vet clean deps tidy check benchmark docs install-tools version info ci pre-commit update-deps
# Variables
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get
GOMOD=$(GOCMD) mod
GOFMT=gofmt
GOVET=$(GOCMD) vet
COVERAGE_FILE=coverage.out
COVERAGE_HTML=coverage.html
# Colors for terminal output
COLOR_RESET=\033[0m
COLOR_BOLD=\033[1m
COLOR_GREEN=\033[32m
COLOR_YELLOW=\033[33m
COLOR_BLUE=\033[34m
# Default target
all: fmt-check vet lint test
## help: Display this help message
help:
@printf "$(COLOR_BOLD)RingBuffer - Makefile Commands$(COLOR_RESET)\n"
@printf "\n"
@printf "$(COLOR_BOLD)Usage:$(COLOR_RESET)\n"
@printf " make $(COLOR_GREEN)<target>$(COLOR_RESET)\n"
@printf "\n"
@printf "$(COLOR_BOLD)Available targets:$(COLOR_RESET)\n"
@grep -E '^## ' $(MAKEFILE_LIST) | sed 's/## / /' | sed 's/://'
@printf "\n"
## build: Build project
build:
@echo "$(COLOR_BLUE)Building...$(COLOR_RESET)"
$(GOBUILD) -v ./...
## test: Run all tests
test:
@echo "$(COLOR_BLUE)Running tests...$(COLOR_RESET)"
$(GOTEST) -v ./...
## test-short: Run tests in short mode
test-short:
@echo "$(COLOR_BLUE)Running tests (short mode)...$(COLOR_RESET)"
$(GOTEST) -short ./...
## test-race: Run tests with race detector
test-race:
@echo "$(COLOR_BLUE)Running tests with race detector...$(COLOR_RESET)"
$(GOTEST) -race ./...
## test-coverage: Run tests with coverage report
test-coverage:
@echo "$(COLOR_BLUE)Running tests with coverage...$(COLOR_RESET)"
$(GOTEST) -coverprofile=$(COVERAGE_FILE) -covermode=atomic ./...
@echo "$(COLOR_GREEN)Coverage report generated: $(COVERAGE_FILE)$(COLOR_RESET)"
$(GOCMD) tool cover -html=$(COVERAGE_FILE) -o $(COVERAGE_HTML)
@echo "$(COLOR_GREEN)HTML coverage report: $(COVERAGE_HTML)$(COLOR_RESET)"
## treemap: Generate SVG coverage treemap
treemap: test-coverage
@which go-cover-treemap > /dev/null || (echo "$(COLOR_YELLOW)go-cover-treemap not found. Run 'go install github.com/nikandfor/go-cover-treemap@latest'$(COLOR_RESET)" && exit 1)
go-cover-treemap -coverprofile $(COVERAGE_FILE) > coverage.svg
@echo "$(COLOR_GREEN)SVG coverage report: coverage.svg$(COLOR_RESET)"
## test-verbose: Run tests with verbose output
test-verbose:
@echo "$(COLOR_BLUE)Running tests (verbose)...$(COLOR_RESET)"
$(GOTEST) -v -count=1 ./...
## benchmark: Run benchmarks
benchmark:
@echo "$(COLOR_BLUE)Running benchmarks...$(COLOR_RESET)"
$(GOTEST) -bench=. -benchmem ./...
## lint: Run golangci-lint
lint:
@echo "$(COLOR_BLUE)Running linter...$(COLOR_RESET)"
@which golangci-lint > /dev/null || (echo "$(COLOR_YELLOW)golangci-lint not found. Run 'make install-tools'$(COLOR_RESET)" && exit 1)
golangci-lint run ./...
## fmt: Format all Go files
fmt:
@echo "$(COLOR_BLUE)Formatting code...$(COLOR_RESET)"
$(GOFMT) -s -w .
@echo "$(COLOR_GREEN)Code formatted successfully$(COLOR_RESET)"
## fmt-check: Check if code is formatted
fmt-check:
@echo "$(COLOR_BLUE)Checking code formatting...$(COLOR_RESET)"
@test -z "$$($(GOFMT) -l .)" || (echo "$(COLOR_YELLOW)The following files need formatting:$(COLOR_RESET)" && $(GOFMT) -l . && exit 1)
@echo "$(COLOR_GREEN)All files are properly formatted$(COLOR_RESET)"
## vet: Run go vet
vet:
@echo "$(COLOR_BLUE)Running go vet...$(COLOR_RESET)"
$(GOVET) ./...
## check: Run fmt-check, vet, and lint
check: fmt-check vet lint
@echo "$(COLOR_GREEN)All checks passed!$(COLOR_RESET)"
## clean: Clean build artifacts and test cache
clean:
@echo "$(COLOR_BLUE)Cleaning...$(COLOR_RESET)"
$(GOCLEAN)
rm -f $(COVERAGE_FILE) $(COVERAGE_HTML) coverage.svg
rm -rf ./bin
@echo "$(COLOR_GREEN)Clean complete$(COLOR_RESET)"
## deps: Download dependencies
deps:
@echo "$(COLOR_BLUE)Downloading dependencies...$(COLOR_RESET)"
$(GOMOD) download
@echo "$(COLOR_GREEN)Dependencies downloaded$(COLOR_RESET)"
## tidy: Tidy and verify dependencies
tidy:
@echo "$(COLOR_BLUE)Tidying dependencies...$(COLOR_RESET)"
$(GOMOD) tidy
$(GOMOD) verify
@echo "$(COLOR_GREEN)Dependencies tidied$(COLOR_RESET)"
## install-tools: Install development tools
install-tools:
@echo "$(COLOR_BLUE)Installing development tools...$(COLOR_RESET)"
@which golangci-lint > /dev/null || (echo "Installing golangci-lint..." && \
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest)
@which go-cover-treemap > /dev/null || (echo "Installing go-cover-treemap..." && \
go install github.com/nikandfor/go-cover-treemap@latest)
@echo "$(COLOR_GREEN)Tools installed$(COLOR_RESET)"
## docs: Generate documentation
docs:
@echo "$(COLOR_BLUE)Generating documentation...$(COLOR_RESET)"
@echo "Open http://localhost:6060/pkg/github.com/smallnest/ringbuffer/ in your browser"
godoc -http=:6060
## example: Run example
example:
@echo "$(COLOR_BLUE)Running example...$(COLOR_RESET)"
$(GOCMD) run example_test.go
## ci: Run continuous integration checks
ci: deps check test-race test-coverage
@echo "$(COLOR_GREEN)CI checks passed!$(COLOR_RESET)"
## pre-commit: Run pre-commit checks (fmt, vet, lint, test)
pre-commit: fmt vet lint test
@echo "$(COLOR_GREEN)Pre-commit checks passed!$(COLOR_RESET)"
## update-deps: Update all dependencies to latest versions
update-deps:
@echo "$(COLOR_BLUE)Updating dependencies...$(COLOR_RESET)"
$(GOGET) -u ./...
$(GOMOD) tidy
@echo "$(COLOR_GREEN)Dependencies updated$(COLOR_RESET)"
## version: Display Go version
version:
@$(GOCMD) version
## info: Display project information
info:
@printf "$(COLOR_BOLD)Project Information$(COLOR_RESET)\n"
@printf " Name: RingBuffer\n"
@printf " Module: github.com/smallnest/ringbuffer\n"
@printf " Go Version: $$($(GOCMD) version | cut -d' ' -f3)\n"
@printf " Files: $$($(GOCMD) list ./... | wc -l | tr -d ' ')\n"