forked from yarlson/lnk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
186 lines (162 loc) · 6.13 KB
/
Makefile
File metadata and controls
186 lines (162 loc) · 6.13 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
# Variables
BINARY_NAME=lnk
VERSION=$(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
BUILD_TIME=$(shell date +%FT%T%z)
LDFLAGS=-ldflags "-X main.version=$(VERSION) -X main.buildTime=$(BUILD_TIME)"
# Go related variables
GOBASE=$(shell pwd)
GOBIN=$(GOBASE)/bin
GOFILES=$(wildcard *.go)
# Colors for pretty output
RED=\033[0;31m
GREEN=\033[0;32m
YELLOW=\033[0;33m
BLUE=\033[0;34m
NC=\033[0m # No Color
.PHONY: help build test clean install uninstall fmt lint vet tidy run dev cross-compile release goreleaser-check goreleaser-snapshot
## help: Show this help message
help:
@echo "$(BLUE)Lnk CLI - Available targets:$(NC)"
@echo ""
@echo "$(GREEN)Development:$(NC)"
@echo " build Build the binary"
@echo " test Run tests"
@echo " test-v Run tests with verbose output"
@echo " test-cover Run tests with coverage"
@echo " run Run the application"
@echo " dev Development mode with file watching"
@echo ""
@echo "$(GREEN)Code Quality:$(NC)"
@echo " fmt Format Go code"
@echo " lint Run golangci-lint"
@echo " vet Run go vet"
@echo " tidy Tidy Go modules"
@echo " check Run all quality checks (fmt, vet, lint, test)"
@echo ""
@echo "$(GREEN)Installation:$(NC)"
@echo " install Install binary to /usr/local/bin"
@echo " uninstall Remove binary from /usr/local/bin"
@echo ""
@echo "$(GREEN)Release:$(NC)"
@echo " cross-compile Build for multiple platforms (legacy)"
@echo " release Create release builds (legacy)"
@echo " goreleaser-check Validate .goreleaser.yml config"
@echo " goreleaser-snapshot Build snapshot release with GoReleaser"
@echo ""
@echo "$(GREEN)Utilities:$(NC)"
@echo " clean Clean build artifacts"
@echo " deps Install development dependencies"
## build: Build the binary
build:
@echo "$(BLUE)Building $(BINARY_NAME)...$(NC)"
@go build $(LDFLAGS) -o $(BINARY_NAME) .
@echo "$(GREEN)✓ Build complete: $(BINARY_NAME)$(NC)"
## test: Run tests
test:
@echo "$(BLUE)Running tests...$(NC)"
@go test ./...
@echo "$(GREEN)✓ Tests passed$(NC)"
## test-v: Run tests with verbose output
test-v:
@echo "$(BLUE)Running tests (verbose)...$(NC)"
@go test -v ./...
## test-cover: Run tests with coverage
test-cover:
@echo "$(BLUE)Running tests with coverage...$(NC)"
@go test -v -cover ./...
@go test -coverprofile=coverage.out ./
@go tool cover -html=coverage.out -o coverage.html
@echo "$(GREEN)✓ Coverage report generated: coverage.html$(NC)"
## run: Run the application
run: build
@echo "$(BLUE)Running $(BINARY_NAME)...$(NC)"
@./$(BINARY_NAME)
## dev: Development mode with file watching (requires entr)
dev:
@echo "$(YELLOW)Development mode - watching for changes...$(NC)"
@echo "$(YELLOW)Install 'entr' if not available: brew install entr$(NC)"
@find . -name "*.go" | entr -r make run
## fmt: Format Go code
fmt:
@echo "$(BLUE)Formatting code...$(NC)"
@go fmt ./...
@echo "$(GREEN)✓ Code formatted$(NC)"
## lint: Run golangci-lint
lint:
@echo "$(BLUE)Running linter...$(NC)"
@if command -v golangci-lint >/dev/null 2>&1; then \
golangci-lint run; \
echo "$(GREEN)✓ Linting complete$(NC)"; \
else \
echo "$(YELLOW)⚠ golangci-lint not found. Install with: go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest$(NC)"; \
fi
## vet: Run go vet
vet:
@echo "$(BLUE)Running go vet...$(NC)"
@go vet ./...
@echo "$(GREEN)✓ Vet check passed$(NC)"
## tidy: Tidy Go modules
tidy:
@echo "$(BLUE)Tidying modules...$(NC)"
@go mod tidy
@echo "$(GREEN)✓ Modules tidied$(NC)"
## check: Run all quality checks
check: fmt vet lint test
@echo "$(GREEN)✓ All quality checks passed$(NC)"
## install: Install binary to /usr/local/bin
install: build
@echo "$(BLUE)Installing $(BINARY_NAME) to /usr/local/bin...$(NC)"
@sudo cp $(BINARY_NAME) /usr/local/bin/
@echo "$(GREEN)✓ $(BINARY_NAME) installed$(NC)"
## uninstall: Remove binary from /usr/local/bin
uninstall:
@echo "$(BLUE)Uninstalling $(BINARY_NAME)...$(NC)"
@sudo rm -f /usr/local/bin/$(BINARY_NAME)
@echo "$(GREEN)✓ $(BINARY_NAME) uninstalled$(NC)"
## cross-compile: Build for multiple platforms
cross-compile: clean
@echo "$(BLUE)Cross-compiling for multiple platforms...$(NC)"
@mkdir -p dist
@GOOS=linux GOARCH=amd64 go build $(LDFLAGS) -o dist/$(BINARY_NAME)-linux-amd64 .
@GOOS=linux GOARCH=arm64 go build $(LDFLAGS) -o dist/$(BINARY_NAME)-linux-arm64 .
@GOOS=darwin GOARCH=amd64 go build $(LDFLAGS) -o dist/$(BINARY_NAME)-darwin-amd64 .
@GOOS=darwin GOARCH=arm64 go build $(LDFLAGS) -o dist/$(BINARY_NAME)-darwin-arm64 .
@GOOS=windows GOARCH=amd64 go build $(LDFLAGS) -o dist/$(BINARY_NAME)-windows-amd64.exe .
@echo "$(GREEN)✓ Cross-compilation complete. Binaries in dist/$(NC)"
## release: Create release builds with checksums
release: cross-compile
@echo "$(BLUE)Creating release artifacts...$(NC)"
@cd dist && sha256sum * > checksums.txt
@echo "$(GREEN)✓ Release artifacts created in dist/$(NC)"
## clean: Clean build artifacts
clean:
@echo "$(BLUE)Cleaning...$(NC)"
@rm -f $(BINARY_NAME)
@rm -rf dist/
@rm -f coverage.out coverage.html
@echo "$(GREEN)✓ Clean complete$(NC)"
## deps: Install development dependencies
deps:
@echo "$(BLUE)Installing development dependencies...$(NC)"
@go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
@if ! command -v goreleaser >/dev/null 2>&1; then \
echo "$(BLUE)Installing GoReleaser...$(NC)"; \
go install github.com/goreleaser/goreleaser@latest; \
fi
@echo "$(GREEN)✓ Dependencies installed$(NC)"
## goreleaser-check: Validate GoReleaser configuration
goreleaser-check:
@echo "$(BLUE)Validating GoReleaser configuration...$(NC)"
@if command -v goreleaser >/dev/null 2>&1; then \
goreleaser check; \
echo "$(GREEN)✓ GoReleaser configuration is valid$(NC)"; \
else \
echo "$(YELLOW)⚠ GoReleaser not found. Install with: make deps$(NC)"; \
fi
## goreleaser-snapshot: Build snapshot release with GoReleaser
goreleaser-snapshot: goreleaser-check
@echo "$(BLUE)Building snapshot release with GoReleaser...$(NC)"
@goreleaser build --snapshot --clean
@echo "$(GREEN)✓ Snapshot release built in dist/$(NC)"
# Default target
all: check build