-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
142 lines (111 loc) · 4.26 KB
/
Makefile
File metadata and controls
142 lines (111 loc) · 4.26 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
# Build configuration
BINARY_NAME := flashduty
BUILD_DIR := bin
GOLANGCI_LINT_VERSION := v2.2.1
GOLANGCI_LINT := $(BUILD_DIR)/golangci-lint
GCI_VERSION := v0.13.5
GCI := $(BUILD_DIR)/gci
# Go parameters
GOCMD := go
GOBUILD := $(GOCMD) build
GOTEST := $(GOCMD) test
GOFMT := gofmt
MODULE := $(shell go list -m)
# Build metadata
VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo "none")
DATE := $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
LDFLAGS := -ldflags "-s -w -X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.date=$(DATE)"
# Default target
.PHONY: all
all: check
# ============================================================================
# Development targets
# ============================================================================
.PHONY: build
build: ## Build the binary
$(GOBUILD) -v $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME) ./cmd/flashduty
.PHONY: run
run: build ## Build and run the CLI
./$(BUILD_DIR)/$(BINARY_NAME)
# ============================================================================
# Quality assurance targets
# ============================================================================
FMT_DIRS := cmd internal
.PHONY: fmt
fmt: $(GCI) ## Format Go source code and sort imports
$(GOFMT) -s -w $(FMT_DIRS)
$(GCI) write --skip-generated -s standard -s default -s "prefix($(MODULE))" $(FMT_DIRS)
.PHONY: gci
gci: $(GCI) ## Sort imports using gci
$(GCI) write --skip-generated -s standard -s default -s "prefix($(MODULE))" $(FMT_DIRS)
.PHONY: lint
lint: $(GOLANGCI_LINT) ## Run golangci-lint
$(GOLANGCI_LINT) run
.PHONY: lint-fix
lint-fix: $(GOLANGCI_LINT) ## Run golangci-lint with auto-fix
$(GOLANGCI_LINT) run --fix
.PHONY: test
test: ## Run unit tests
$(GOTEST) -race ./...
.PHONY: test-v
test-v: ## Run unit tests with verbose output
$(GOTEST) -race -v ./...
.PHONY: test-cover
test-cover: ## Run unit tests with coverage
$(GOTEST) -race -cover ./...
# ============================================================================
# Pre-push check (recommended before pushing)
# ============================================================================
.PHONY: check
check: fmt lint test build ## Run all checks (fmt, lint, test, build) - recommended before pushing
.PHONY: ci
ci: check ## Alias for check
# ============================================================================
# Dependency management
# ============================================================================
.PHONY: deps
deps: ## Download Go dependencies
$(GOCMD) mod download
.PHONY: deps-tidy
deps-tidy: ## Tidy Go modules
$(GOCMD) mod tidy
.PHONY: deps-verify
deps-verify: ## Verify Go dependencies
$(GOCMD) mod verify
# ============================================================================
# Tools installation
# ============================================================================
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
$(GOLANGCI_LINT): $(BUILD_DIR)
@if [ ! -f "$(GOLANGCI_LINT)" ]; then \
echo "Installing golangci-lint $(GOLANGCI_LINT_VERSION)..."; \
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s $(GOLANGCI_LINT_VERSION); \
fi
$(GCI): $(BUILD_DIR)
@if [ ! -f "$(GCI)" ]; then \
echo "Installing gci $(GCI_VERSION)..."; \
GOBIN=$(CURDIR)/$(BUILD_DIR) $(GOCMD) install github.com/daixiang0/gci@$(GCI_VERSION); \
fi
.PHONY: tools
tools: $(GOLANGCI_LINT) $(GCI) ## Install required tools
# ============================================================================
# Cleanup
# ============================================================================
.PHONY: clean
clean: ## Remove build artifacts
rm -rf $(BUILD_DIR)
# ============================================================================
# Help
# ============================================================================
.PHONY: help
help: ## Display this help message
@echo "Available targets:"
@echo ""
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-15s\033[0m %s\n", $$1, $$2}'
@echo ""
@echo "Quick start:"
@echo " make check - Run all pre-push checks (recommended before pushing)"
@echo " make lint - Run linter only"
@echo " make test - Run unit tests only"