-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMakefile
More file actions
182 lines (159 loc) · 5.89 KB
/
Copy pathMakefile
File metadata and controls
182 lines (159 loc) · 5.89 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
# Variables
BINARY_NAME=itemize
GO_FILES=$(shell git ls-files '*.go')
STAGED_GO_FILES=$(shell git diff --cached --name-only --diff-filter=ACMR -- '*.go')
COVERAGE_FILE=coverage.out
COVERAGE_HTML=coverage.html
# Go commands
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOMOD=$(GOCMD) mod
GOFMT=gofmt
GOVET=$(GOCMD) vet
# Colors for output
RED=\033[0;31m
GREEN=\033[0;32m
YELLOW=\033[1;33m
NC=\033[0m # No Color
.PHONY: all build clean test coverage fmt check-fmt check-fmt-staged lint vet deps help install-tools install-hooks pre-commit pre-commit-local release version run-costco
## help: Display this help message
help:
@echo "Available targets:"
@grep -E '^##' Makefile | sed 's/## //'
## all: Run pre-commit checks and build
all: pre-commit build
@echo "$(GREEN)Build complete!$(NC)"
## build: Build the CLI binary
build:
@echo "$(GREEN)Building $(BINARY_NAME)...$(NC)"
$(GOBUILD) -v -o $(BINARY_NAME) ./cmd/itemize
@echo "$(GREEN)Build complete!$(NC)"
## clean: Remove build artifacts and temporary files
clean:
@echo "$(YELLOW)Cleaning...$(NC)"
$(GOCLEAN)
rm -f $(BINARY_NAME)
rm -f $(COVERAGE_FILE) $(COVERAGE_HTML)
rm -rf dist/
@echo "$(GREEN)Clean complete!$(NC)"
## test: Run all tests
test:
@echo "$(GREEN)Running tests...$(NC)"
$(GOTEST) -v -race -timeout 30s ./...
@echo "$(GREEN)Tests complete!$(NC)"
## coverage: Run tests with coverage report
coverage:
@echo "$(GREEN)Running tests with coverage...$(NC)"
$(GOTEST) -v -race -coverprofile=$(COVERAGE_FILE) -covermode=atomic ./...
@echo "$(GREEN)Generating coverage report...$(NC)"
$(GOCMD) tool cover -html=$(COVERAGE_FILE) -o $(COVERAGE_HTML)
@echo "$(GREEN)Coverage report generated: $(COVERAGE_HTML)$(NC)"
@echo "Coverage summary:"
@$(GOCMD) tool cover -func=$(COVERAGE_FILE) | grep total | awk '{print "Total coverage: " $$3}'
## fmt: Format code
fmt:
@echo "$(GREEN)Formatting code...$(NC)"
$(GOFMT) -s -w $(GO_FILES)
@if command -v goimports &> /dev/null; then \
goimports -w $(GO_FILES); \
elif [ -f "$$(go env GOPATH)/bin/goimports" ]; then \
$$(go env GOPATH)/bin/goimports -w $(GO_FILES); \
else \
echo "$(YELLOW)goimports not installed, skipping...$(NC)"; \
fi
@echo "$(GREEN)Formatting complete!$(NC)"
## check-fmt: Verify Go files are gofmt-formatted
check-fmt:
@echo "$(GREEN)Checking Go formatting...$(NC)"
@unformatted="$$(gofmt -l $(GO_FILES))"; \
if [ -n "$$unformatted" ]; then \
echo "$(RED)Go files need formatting:$(NC)"; \
echo "$$unformatted"; \
echo "Run: make fmt"; \
exit 1; \
fi
@echo "$(GREEN)Formatting check passed!$(NC)"
## check-fmt-staged: Verify staged Go files are gofmt-formatted
check-fmt-staged:
@echo "$(GREEN)Checking staged Go formatting...$(NC)"
@if [ -n "$(STAGED_GO_FILES)" ]; then \
unformatted="$$(gofmt -l $(STAGED_GO_FILES))"; \
if [ -n "$$unformatted" ]; then \
echo "$(RED)Staged Go files need formatting:$(NC)"; \
echo "$$unformatted"; \
echo "Run: gofmt -w $$unformatted"; \
exit 1; \
fi; \
else \
echo "$(YELLOW)No staged Go files to check.$(NC)"; \
fi
@echo "$(GREEN)Staged formatting check passed!$(NC)"
## lint: Run golangci-lint using the repo config
lint:
@echo "$(GREEN)Running golangci-lint...$(NC)"
@if ! command -v golangci-lint >/dev/null 2>&1; then \
echo "$(RED)golangci-lint is not installed.$(NC)"; \
echo "Install v2.4.0+ or run: brew install golangci-lint"; \
exit 1; \
fi
golangci-lint run --timeout=5m
@echo "$(GREEN)Lint complete!$(NC)"
## vet: Run go vet
vet:
@echo "$(GREEN)Running go vet...$(NC)"
$(GOVET) ./...
@echo "$(GREEN)Vet complete!$(NC)"
## deps: Download and tidy dependencies
deps:
@echo "$(GREEN)Downloading dependencies...$(NC)"
$(GOMOD) download
@echo "$(GREEN)Tidying dependencies...$(NC)"
$(GOMOD) tidy
@echo "$(GREEN)Dependencies updated!$(NC)"
## pre-commit-local: Run local pre-commit checks without modifying files
pre-commit-local: check-fmt-staged lint vet
@echo "$(GREEN)Running tests...$(NC)"
$(GOTEST) ./...
@echo "$(GREEN)Pre-commit checks passed!$(NC)"
## pre-commit: Run full pre-commit checks (format, lint, vet, race tests)
pre-commit: fmt lint vet test
@echo "$(GREEN)Pre-commit checks passed!$(NC)"
## release: Build release binaries for multiple platforms
release:
@echo "$(GREEN)Building release binaries...$(NC)"
@mkdir -p dist
GOOS=darwin GOARCH=amd64 $(GOBUILD) -o dist/$(BINARY_NAME)-darwin-amd64 ./cmd/itemize
GOOS=darwin GOARCH=arm64 $(GOBUILD) -o dist/$(BINARY_NAME)-darwin-arm64 ./cmd/itemize
GOOS=linux GOARCH=amd64 $(GOBUILD) -o dist/$(BINARY_NAME)-linux-amd64 ./cmd/itemize
GOOS=linux GOARCH=arm64 $(GOBUILD) -o dist/$(BINARY_NAME)-linux-arm64 ./cmd/itemize
GOOS=windows GOARCH=amd64 $(GOBUILD) -o dist/$(BINARY_NAME)-windows-amd64.exe ./cmd/itemize
@echo "$(GREEN)Release binaries built in dist/$(NC)"
## version: Display version information
version:
@echo "$(GREEN)Version information:$(NC)"
@go version
@echo "Module: $$(go list -m)"
@echo "Git commit: $$(git rev-parse --short HEAD 2>/dev/null || echo 'unknown')"
@echo "Build date: $$(date -u +%Y-%m-%d_%H:%M:%S)"
## run-costco: Run Costco sync in dry-run mode (safe testing)
run-costco:
@echo "$(GREEN)Running Costco sync (dry-run)...$(NC)"
$(GOCMD) run ./cmd/itemize costco -dry-run -verbose
## install-hooks: Install versioned git hooks for this checkout
install-hooks:
@echo "$(GREEN)Installing git hooks...$(NC)"
@git config core.hooksPath .githooks
@chmod +x .githooks/pre-commit scripts/pre-commit.sh
@echo "$(GREEN)Git hooks installed. Use ITEMIZE_SKIP_PRECOMMIT=1 to bypass once.$(NC)"
## install-tools: Install development tools (goimports, golangci-lint)
install-tools:
@echo "$(GREEN)Installing development tools...$(NC)"
@echo "Installing goimports..."
@go install golang.org/x/tools/cmd/goimports@latest
@echo "Installing golangci-lint..."
@go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.4.0
@echo "$(GREEN)Tools installation complete!$(NC)"
# Default target
.DEFAULT_GOAL := help