-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
208 lines (173 loc) · 8.88 KB
/
Makefile
File metadata and controls
208 lines (173 loc) · 8.88 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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# ╔════════════════════════════════════════════════════════════════════════════╗
# ║ TACK MAKEFILE ║
# ╚════════════════════════════════════════════════════════════════════════════╝
#
# Usage: make <target>
# Run 'make help' for a list of available targets
#
.PHONY: all build build-embed clean test test-v test-cover lint fmt fmt-check vet help install dev tidy check
# ─────────────────────────────────────────────────────────────────────────────
# Configuration
# ─────────────────────────────────────────────────────────────────────────────
BINARY_NAME := tack
CMD := ./cmd/cli
MODULE := github.com/whiskeyjimb/tack-cli
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo dev)
COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo none)
BUILDTIME := $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
LDFLAGS := -s -w \
-X $(MODULE)/internal/cli.Version=$(VERSION) \
-X $(MODULE)/internal/cli.Commit=$(COMMIT) \
-X $(MODULE)/internal/cli.BuildTime=$(BUILDTIME)
GOFLAGS ?=
TAGS ?=
# Go commands
GOCMD := go
GOBUILD := $(GOCMD) build
GOCLEAN := $(GOCMD) clean
GOTEST := $(GOCMD) test
GOGET := $(GOCMD) get
GOMOD := $(GOCMD) mod
GOFMT := gofmt
GOVET := $(GOCMD) vet
GOLINT := golangci-lint
# ─────────────────────────────────────────────────────────────────────────────
# Colors and Formatting
# ─────────────────────────────────────────────────────────────────────────────
# Colors
RESET := \033[0m
BOLD := \033[1m
RED := \033[31m
GREEN := \033[32m
YELLOW := \033[33m
BLUE := \033[34m
MAGENTA := \033[35m
CYAN := \033[36m
WHITE := \033[37m
# Styled prefixes
INFO := @printf "$(BOLD)$(CYAN)▸$(RESET) "
SUCCESS := @printf "$(BOLD)$(GREEN)✓$(RESET) "
WARN := @printf "$(BOLD)$(YELLOW)⚠$(RESET) "
ERROR := @printf "$(BOLD)$(RED)✗$(RESET) "
STEP := @printf "$(BOLD)$(MAGENTA)→$(RESET) "
# ═══════════════════════════════════════════════════════════════════════════════
# PRIMARY TARGETS
# ═══════════════════════════════════════════════════════════════════════════════
.DEFAULT_GOAL := help
##@ Primary
all: clean lint test build ## Run full pipeline: clean → lint → test → build
$(SUCCESS)
@printf "$(GREEN)All tasks completed successfully!$(RESET)\n"
build: ## Build the CLI binary
$(INFO)
@printf "Building $(BOLD)$(BINARY_NAME)$(RESET)...\n"
@mkdir -p bin
@CGO_ENABLED=0 $(GOBUILD) $(GOFLAGS) -tags "$(TAGS)" -ldflags "$(LDFLAGS)" -o bin/$(BINARY_NAME) $(CMD)
$(SUCCESS)
@printf "Binary built: $(GREEN)bin/$(BINARY_NAME)$(RESET)\n"
build-embed: TAGS += embed_plugins
build-embed: build ## Build with embedded plugins
install: ## Install to GOBIN
$(INFO)
@printf "Installing $(BOLD)$(BINARY_NAME)$(RESET)...\n"
@CGO_ENABLED=0 $(GOCMD) install $(GOFLAGS) -tags "$(TAGS)" -ldflags "$(LDFLAGS)" $(CMD)
$(SUCCESS)
@printf "Installed to $(GREEN)$(shell $(GOCMD) env GOBIN || $(GOCMD) env GOPATH)/bin/$(BINARY_NAME)$(RESET)\n"
dev: tidy build ## Tidy, build — quick iteration loop
clean: ## Remove build artifacts
$(INFO)
@printf "Cleaning build artifacts...\n"
@rm -rf bin/
@rm -f $(BINARY_NAME)
@$(GOCLEAN) -cache -testcache 2>/dev/null || true
@rm -rf coverage.out coverage.html
$(SUCCESS)
@printf "$(GREEN)Clean complete$(RESET)\n"
# ═══════════════════════════════════════════════════════════════════════════════
# TESTING
# ═══════════════════════════════════════════════════════════════════════════════
##@ Testing
test: ## Run tests
$(INFO)
@printf "Running tests...\n"
@$(GOTEST) ./... -count=1 2>&1 | while IFS= read -r line; do \
case "$$line" in \
ok*) printf " \033[32m✓\033[0m %s\n" "$$line" ;; \
FAIL*) printf " \033[31m✗\033[0m %s\n" "$$line" ;; \
'?'*) printf " \033[2m%s\033[0m\n" "$$line" ;; \
*) printf " %s\n" "$$line" ;; \
esac; \
done
test-v: ## Run tests (verbose)
$(INFO)
@printf "Running tests (verbose)...\n"
@$(GOTEST) -v ./... -count=1
test-cover: ## Run tests with coverage report
$(INFO)
@printf "Running tests with coverage...\n"
@$(GOTEST) ./... -count=1 -coverprofile=coverage.out
@$(GOCMD) tool cover -func=coverage.out | tail -1 | awk '{printf " $(SUCCESS)Coverage: $(BOLD)%s$(RESET)\n", $$3}'
@rm -f coverage.out
# ═══════════════════════════════════════════════════════════════════════════════
# CODE QUALITY
# ═══════════════════════════════════════════════════════════════════════════════
##@ Code Quality
lint: ## Run golangci-lint
$(INFO)
@printf "Running linters...\n"
@$(GOLINT) run ./...
$(SUCCESS)
@printf "$(GREEN)Linting passed$(RESET)\n"
vet: ## Run go vet
$(INFO)
@printf "Running go vet...\n"
@$(GOVET) ./...
$(SUCCESS)
@printf "$(GREEN)Vet passed$(RESET)\n"
fmt: ## Format code
$(INFO)
@printf "Formatting code...\n"
@$(GOFMT) -w .
$(SUCCESS)
@printf "$(GREEN)Code formatted$(RESET)\n"
fmt-check: ## Check formatting (no changes)
$(INFO)
@printf "Checking format...\n"
@test -z "$$($(GOFMT) -l .)" || ($(GOFMT) -l . && printf " $(ERROR)Files need formatting$(RESET)\n" && exit 1)
$(SUCCESS)
@printf "$(GREEN)Format check passed$(RESET)\n"
tidy: ## Tidy and verify dependencies
$(INFO)
@printf "Tidying modules...\n"
@$(GOMOD) tidy
@$(GOMOD) verify >/dev/null
$(SUCCESS)
@printf "$(GREEN)Dependencies tidied$(RESET)\n"
check: fmt-check vet test ## Run all checks (format, vet, test)
# ═══════════════════════════════════════════════════════════════════════════════
# HELP
# ═══════════════════════════════════════════════════════════════════════════════
##@ Help
help: ## Show this help message
@printf "\n"
@printf "$(BOLD)$(CYAN)╔════════════════════════════════════════════════════════════════╗$(RESET)\n"
@printf "$(BOLD)$(CYAN)║$(RESET) $(BOLD)TACK$(RESET) - Makefile Help $(BOLD)$(CYAN)║$(RESET)\n"
@printf "$(BOLD)$(CYAN)╚════════════════════════════════════════════════════════════════╝$(RESET)\n"
@printf "\n"
@printf "$(BOLD)Usage:$(RESET) make $(CYAN)<target>$(RESET)\n\n"
@awk 'BEGIN {FS = ":.*##"; section=""} \
/^##@/ { \
section=substr($$0, 5); \
printf "\n$(BOLD)$(YELLOW)%s$(RESET)\n", section \
} \
/^[a-zA-Z_-]+:.*?##/ { \
if (section != "") { \
printf " $(CYAN)%-18s$(RESET) %s\n", $$1, $$2 \
} \
}' $(MAKEFILE_LIST)
@printf "\n"
@printf "$(BOLD)Examples:$(RESET)\n"
@printf " make build $(WHITE)# Build the binary$(RESET)\n"
@printf " make test $(WHITE)# Run all tests$(RESET)\n"
@printf " make dev $(WHITE)# Quick iteration loop$(RESET)\n"
@printf "\n"