-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
132 lines (99 loc) · 3.21 KB
/
Makefile
File metadata and controls
132 lines (99 loc) · 3.21 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
# Makefile for git-context
.PHONY: help build run test test-verbose test-coverage lint fmt clean install check all
# Default target
.DEFAULT_GOAL := help
# Binary name
BINARY_NAME=git-context
BINARY_PATH=./bin/$(BINARY_NAME)
# Go parameters
GOCMD=go
GOBUILD=$(GOCMD) build
GORUN=$(GOCMD) run
GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get
GOMOD=$(GOCMD) mod
GOFMT=gofmt
GOLINT=golangci-lint
help: ## Display this help message
@echo "Available targets:"
@echo ""
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-20s\033[0m %s\n", $$1, $$2}'
##@ Development
run: ## Run the application
@echo "Running application..."
@$(GORUN) .
build: ## Build the binary
@echo "Building binary..."
@mkdir -p bin
@$(GOBUILD) -o $(BINARY_PATH) -v .
@echo "Binary created at $(BINARY_PATH)"
install: ## Install the binary to GOPATH/bin
@echo "Installing binary..."
@$(GOCMD) install .
@echo "Binary installed to $(shell go env GOPATH)/bin/$(BINARY_NAME)"
##@ Testing
test: ## Run tests
@echo "Running tests..."
@$(GOTEST) -v -race ./...
test-verbose: ## Run tests with verbose output
@echo "Running tests (verbose)..."
@$(GOTEST) -v -race -count=1 ./...
test-coverage: ## Run tests with coverage report
@echo "Running tests with coverage..."
@$(GOTEST) -v -race -coverprofile=coverage.out -covermode=atomic ./...
@$(GOCMD) tool cover -html=coverage.out -o coverage.html
@echo "Coverage report generated: coverage.html"
test-coverage-view: test-coverage ## Run tests with coverage and open HTML report
@echo "Opening coverage report in browser..."
@open coverage.html || xdg-open coverage.html 2>/dev/null || echo "Please open coverage.html manually"
bench: ## Run benchmarks
@echo "Running benchmarks..."
@$(GOTEST) -bench=. -benchmem ./...
##@ Code Quality
lint: ## Run linter
@echo "Running golangci-lint..."
@$(GOLINT) run
lint-fix: ## Run linter with auto-fix
@echo "Running golangci-lint with auto-fix..."
@$(GOLINT) run --fix
fmt: ## Format code
@echo "Formatting code..."
@$(GOFMT) -s -w .
@echo "Code formatted"
vet: ## Run go vet
@echo "Running go vet..."
@$(GOCMD) vet ./...
check: fmt vet lint test ## Run all checks (fmt, vet, lint, test)
@echo "All checks passed!"
##@ Dependencies
deps: ## Download dependencies
@echo "Downloading dependencies..."
@$(GOMOD) download
@$(GOMOD) tidy
deps-upgrade: ## Upgrade dependencies
@echo "Upgrading dependencies..."
@$(GOGET) -u ./...
@$(GOMOD) tidy
deps-verify: ## Verify dependencies
@echo "Verifying dependencies..."
@$(GOMOD) verify
##@ Cleanup
clean: ## Remove build artifacts and coverage reports
@echo "Cleaning up..."
@rm -rf bin/
@rm -f coverage.out coverage.html
@rm -f $(BINARY_NAME)
@echo "Cleanup complete"
clean-all: clean ## Remove build artifacts, coverage reports, and Go cache
@echo "Cleaning Go cache..."
@$(GOCMD) clean -cache -testcache -modcache
@echo "Full cleanup complete"
##@ Utilities
mod-graph: ## Show module dependency graph
@$(GOMOD) graph
mod-why: ## Show why a package is needed (usage: make mod-why PKG=github.com/pkg/name)
@$(GOMOD) why $(PKG)
version: ## Show Go version
@$(GOCMD) version
all: fmt lint test build ## Run fmt, lint, test, and build
@echo "Build complete!"