Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
122 lines (99 loc) · 3.92 KB
/
Copy pathMakefile
File metadata and controls
122 lines (99 loc) · 3.92 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
# Makefile for gh-docs
.PHONY: help build test lint clean install coverage coverage-check watch build-all fmt vet
# Default target
.DEFAULT_GOAL := help
# Binary name
BINARY_NAME=docs
# Build directory
BUILD_DIR=./bin
# Coverage threshold (percentage)
COVERAGE_THRESHOLD=70
# Go parameters
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get
GOMOD=$(GOCMD) mod
GOFMT=$(GOCMD) fmt
GOVET=$(GOCMD) vet
# Go packages, excluding npm's node_modules which may ship Go sources
PKGS=$(shell $(GOCMD) list ./... | grep -v /node_modules/)
# Build flags
LDFLAGS=-ldflags "-s -w"
help: ## Display this help message
@echo "Available targets:"
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-15s\033[0m %s\n", $$1, $$2}'
build: ## Build the binary
$(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME) .
@echo "✅ Built $(BINARY_NAME)"
build-all: ## Build for multiple platforms (Linux, Darwin, Windows for AMD64 and ARM64)
@echo "Building for multiple platforms..."
@mkdir -p dist
GOOS=linux GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o dist/$(BINARY_NAME)-linux-amd64 .
GOOS=linux GOARCH=arm64 $(GOBUILD) $(LDFLAGS) -o dist/$(BINARY_NAME)-linux-arm64 .
GOOS=darwin GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o dist/$(BINARY_NAME)-darwin-amd64 .
GOOS=darwin GOARCH=arm64 $(GOBUILD) $(LDFLAGS) -o dist/$(BINARY_NAME)-darwin-arm64 .
GOOS=windows GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o dist/$(BINARY_NAME)-windows-amd64.exe .
GOOS=windows GOARCH=arm64 $(GOBUILD) $(LDFLAGS) -o dist/$(BINARY_NAME)-windows-arm64.exe .
@echo "✅ Built binaries for all platforms in dist/"
test: ## Run tests
$(GOTEST) -v $(PKGS)
coverage: ## Run tests with coverage
$(GOTEST) -v -coverprofile=coverage.txt -covermode=atomic $(PKGS)
$(GOCMD) tool cover -html=coverage.txt -o coverage.html
@echo "✅ Coverage report generated: coverage.html"
@$(MAKE) coverage-check
coverage-check: ## Check if coverage meets the threshold
@echo "Checking coverage against threshold ($(COVERAGE_THRESHOLD)%)..."
@coverage=$$($(GOCMD) tool cover -func=coverage.txt | grep total | awk '{print $$3}' | sed 's/%//'); \
threshold=$(COVERAGE_THRESHOLD); \
if [ -z "$$coverage" ]; then \
echo "❌ Could not determine coverage"; \
exit 1; \
fi; \
coverage_int=$$(printf "%.0f" $$coverage); \
if [ $$coverage_int -ge $$threshold ]; then \
echo "✅ Coverage $$coverage% meets threshold $$threshold%"; \
else \
echo "❌ Coverage $$coverage% is below threshold $$threshold%"; \
exit 1; \
fi
lint: ## Run linter (requires golangci-lint)
@if command -v golangci-lint >/dev/null 2>&1; then \
golangci-lint run ./...; \
else \
echo "⚠️ golangci-lint not installed. Run: make install-lint"; \
fi
install-lint: ## Install golangci-lint
@echo "Installing golangci-lint..."
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin v1.61.0
@echo "✅ golangci-lint installed"
fmt: ## Format code
$(GOFMT) $(PKGS)
@echo "✅ Code formatted"
vet: ## Run go vet
$(GOVET) $(PKGS)
@echo "✅ Vet completed"
clean: ## Remove build artifacts
$(GOCLEAN)
rm -f $(BUILD_DIR)/$(BINARY_NAME)
rm -rf dist
rm -f coverage.txt coverage.html
@echo "✅ Cleaned build artifacts"
install: build ## Install the binary to $GOPATH/bin
cp $(BUILD_DIR)/$(BINARY_NAME) $(shell go env GOPATH)/bin/
@echo "✅ Installed $(BINARY_NAME) to $(shell go env GOPATH)/bin"
watch: ## Watch for changes and rebuild (requires entr)
@if command -v entr >/dev/null 2>&1; then \
echo "👀 Watching for changes... (Press Ctrl+C to stop)"; \
find . -name '*.go' | entr -c make build; \
else \
echo "⚠️ entr not installed. Install it with: apt-get install entr (Linux) or brew install entr (Mac)"; \
fi
tidy: ## Tidy dependencies
$(GOMOD) tidy
@echo "✅ Dependencies tidied"
deps: ## Download dependencies
$(GOMOD) download
@echo "✅ Dependencies downloaded"