-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
132 lines (119 loc) · 4.02 KB
/
Makefile
File metadata and controls
132 lines (119 loc) · 4.02 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
.PHONY: build test lint fmt check clean install dry-run generate
# Load .env file if exists
-include .env
BINARY_NAME=anilist-mal-sync
LINT_VERSION=v2.10.1
DOCKER_LINT_CMD=docker run --rm -v $(PWD):/app -w /app golangci/golangci-lint:$(LINT_VERSION)
VERSION=$(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
LDFLAGS=-ldflags "-X main.version=$(VERSION)"
.DEFAULT_GOAL := help
# Install all development tools
install:
@echo "🔧 Installing development tools..."
@echo ""
@echo "Installing golangci-lint $(LINT_VERSION)..."
@which golangci-lint > /dev/null 2>&1 || \
brew install golangci/tap/golangci-lint
@echo "✓ golangci-lint installed"
@echo ""
@echo "Installing gofumpt..."
@which gofumpt > /dev/null 2>&1 || \
go install mvdan.cc/gofumpt@latest
@echo "✓ gofumpt installed"
@echo ""
@echo "Installing goimports..."
@which goimports > /dev/null 2>&1 || \
go install golang.org/x/tools/cmd/goimports@latest
@echo "✓ goimports installed"
@echo ""
@echo "Installing gci (import organizer)..."
@which gci > /dev/null 2>&1 || \
go install github.com/daixiang0/gci@latest
@echo "✓ gci installed"
@echo ""
@echo "Installing govulncheck (vulnerability scanner)..."
@which govulncheck > /dev/null 2>&1 || \
go install golang.org/x/vuln/cmd/govulncheck@latest
@echo "✓ govulncheck installed"
@echo ""
@echo "✅ All development tools installed successfully!"
@echo ""
@echo "Available commands:"
@echo " make build - Build the application"
@echo " make test - Run tests"
@echo " make generate - Generate mocks"
@echo " make fmt - Format code"
@echo " make lint - Run linter"
@echo " make clean - Clean build artifacts"
# Build the application
build:
go build $(LDFLAGS) -o $(BINARY_NAME) .
# Run sync in dry-run mode (reads ANILIST_MAL_SYNC_CONFIG from .env file)
dry-run:
@if [ -n "$(ANILIST_MAL_SYNC_CONFIG)" ]; then \
go run . -c "$(ANILIST_MAL_SYNC_CONFIG)" sync -d --verbose --all; \
else \
go run . sync -d --verbose --all; \
fi
# Run tests
test:
go test ./... -v -race
# Generate mocks using mockgen
generate:
@echo "🔧 Generating mocks..."
@go generate ./...
@echo "✓ Mocks generated"
# Format code with gofumpt
fmt:
@echo "Formatting code with gofumpt..."
@gofumpt -l -w .
@echo "Formatting complete!"
# Run linter using Docker
lint:
@echo "Running golangci-lint $(LINT_VERSION) in Docker..."
# $(DOCKER_LINT_CMD) golangci-lint run --new
golangci-lint run --new
# Run all checks (same as Git hooks: format + imports + lint + vet + test)
check: generate
@echo "🔍 Running all checks..."
@echo ""
@echo "1️⃣ Formatting code with gofumpt..."
@gofumpt -l -w .
@echo "✓ Format complete"
@echo ""
@echo "2️⃣ Organizing imports with goimports..."
@goimports -w .
@echo "✓ Imports organized"
@echo ""
@echo "3️⃣ Running go vet..."
@go vet ./...
@echo "✓ Vet complete"
@echo ""
@echo "4️⃣ Running golangci-lint..."
@golangci-lint run --timeout=5m
@echo "✓ Lint complete"
@echo ""
@echo "5️⃣ Running tests..."
@go test ./... -v
@echo "✓ Tests complete"
@echo ""
@echo "✅ All checks passed!"
# Clean build artifacts, temporary files and test cache
clean:
@echo "Cleaning build artifacts and temporary files..."
@rm -f $(BINARY_NAME)
@go clean -testcache
@echo "Cleanup complete!"
# Show help
help:
@echo "Available commands:"
@echo " install - Install all development tools (brew + go install)"
@echo " build - Build the application"
@echo " dry-run - Run sync in dry-run mode (reads ANILIST_MAL_SYNC_CONFIG from .env)"
@echo " test - Run tests"
@echo " generate - Generate mocks using mockgen"
@echo " fmt - Format code with gofumpt"
@echo " lint - Run linter (golangci-lint $(LINT_VERSION))"
@echo " check - Run all checks (generate + format + imports + lint + vet + test)"
@echo " clean - Remove build artifacts, temporary files and clean test cache"
@echo " help - Show this help message"