-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
186 lines (156 loc) · 5.47 KB
/
Copy pathMakefile
File metadata and controls
186 lines (156 loc) · 5.47 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
# Dateline - Date/Time Parser for Go
# Makefile for building, testing, and running the project
# Variables
BINARY_NAME = dateline
BINARY_PATH = ./$(BINARY_NAME)
CMD_PATH = ./cmd/dateline
PKG_PATH = ./...
TEST_TIMEOUT = 30s
# Default target
.PHONY: all
all: build
# Build targets
.PHONY: build
build: ## Build the dateline CLI binary
@echo "Building $(BINARY_NAME)..."
go build -o $(BINARY_NAME) $(CMD_PATH)
@echo "Built $(BINARY_PATH)"
.PHONY: build-all
build-all: build ## Build all binaries (same as build for this project)
.PHONY: install
install: ## Install the dateline binary to $GOPATH/bin
@echo "Installing $(BINARY_NAME)..."
go install $(CMD_PATH)
# Run targets
.PHONY: run
run: build ## Build and run the CLI (reads from stdin)
@echo "Starting dateline (Ctrl+D to exit)..."
$(BINARY_PATH)
.PHONY: run-example
run-example: build ## Run with example input
@echo "Testing with example input..."
@echo "Meeting scheduled for 2024-03-15 at 2:30 PM" | $(BINARY_PATH)
.PHONY: run-json
run-json: build ## Run with JSON output example
@echo "Testing JSON output..."
@echo "File created on March 15, 2024" | $(BINARY_PATH) -json
.PHONY: run-remove
run-remove: build ## Run with date removal example
@echo "Testing date removal..."
@echo "Error occurred on 2024-03-15 - please investigate" | $(BINARY_PATH) -remove
# Test targets
.PHONY: test
test: ## Run Go unit tests
@echo "Running Go tests..."
go test -timeout $(TEST_TIMEOUT) -v $(PKG_PATH)
.PHONY: test-coverage
test-coverage: ## Run tests with coverage report
@echo "Running tests with coverage..."
go test -timeout $(TEST_TIMEOUT) -coverprofile=coverage.out $(PKG_PATH)
go tool cover -html=coverage.out -o coverage.html
@echo "Coverage report generated: coverage.html"
.PHONY: test-race
test-race: ## Run tests with race detection
@echo "Running tests with race detection..."
go test -timeout $(TEST_TIMEOUT) -race -v $(PKG_PATH)
.PHONY: test-formats
test-formats: build ## Run comprehensive format tests
@echo "Running comprehensive format tests..."
./test-all-formats.sh
.PHONY: test-quick
test-quick: build ## Run quick format tests
@echo "Running quick format tests..."
./test.sh
# Code quality targets
.PHONY: fmt
fmt: ## Format Go code
@echo "Formatting code..."
go fmt $(PKG_PATH)
.PHONY: vet
vet: ## Run go vet
@echo "Running go vet..."
go vet $(PKG_PATH)
.PHONY: lint
lint: ## Run golangci-lint (requires golangci-lint to be installed)
@echo "Running golangci-lint..."
@command -v golangci-lint >/dev/null 2>&1 || { echo "golangci-lint not found. Install with: go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest"; exit 1; }
golangci-lint run
.PHONY: check
check: fmt vet ## Run code formatting and vetting
# Development targets
.PHONY: dev
dev: check test build ## Full development cycle: format, vet, test, build
.PHONY: clean
clean: ## Clean build artifacts
@echo "Cleaning up..."
rm -f $(BINARY_NAME)
rm -f coverage.out coverage.html
go clean
.PHONY: deps
deps: ## Download dependencies
@echo "Downloading dependencies..."
go mod download
go mod tidy
.PHONY: upgrade-deps
upgrade-deps: ## Upgrade dependencies
@echo "Upgrading dependencies..."
go get -u ./...
go mod tidy
# Benchmark targets
.PHONY: bench
bench: ## Run benchmarks
@echo "Running benchmarks..."
go test -bench=. -benchmem $(PKG_PATH)
.PHONY: profile
profile: build ## Run with profiling (requires input file)
@echo "Running with CPU profiling..."
@echo "Usage: make profile INPUT=file.txt"
@if [ -z "$(INPUT)" ]; then echo "Please specify INPUT file: make profile INPUT=yourfile.txt"; exit 1; fi
go tool pprof -http=localhost:8080 <(go run -cpuprofile=/dev/stdout $(CMD_PATH) < $(INPUT))
# Documentation targets
.PHONY: doc
doc: ## Generate and serve documentation
@echo "Starting documentation server at http://localhost:6060/pkg/dateline/"
godoc -http=:6060
# Release targets
.PHONY: build-release
build-release: ## Build release binaries for multiple platforms
@echo "Building release binaries..."
@mkdir -p dist
GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o dist/$(BINARY_NAME)-linux-amd64 $(CMD_PATH)
GOOS=darwin GOARCH=amd64 go build -ldflags="-s -w" -o dist/$(BINARY_NAME)-darwin-amd64 $(CMD_PATH)
GOOS=darwin GOARCH=arm64 go build -ldflags="-s -w" -o dist/$(BINARY_NAME)-darwin-arm64 $(CMD_PATH)
GOOS=windows GOARCH=amd64 go build -ldflags="-s -w" -o dist/$(BINARY_NAME)-windows-amd64.exe $(CMD_PATH)
@echo "Release binaries built in dist/ directory"
.PHONY: clean-release
clean-release: ## Clean release artifacts
@echo "Cleaning release artifacts..."
rm -rf dist/
# Utility targets
.PHONY: version
version: build ## Show version information
@echo "Dateline version information:"
@echo "Binary: $(BINARY_PATH)"
@$(BINARY_PATH) -h | head -1
.PHONY: demo
demo: build ## Run interactive demo
@echo "=== Dateline Interactive Demo ==="
@echo "Try these examples (Ctrl+D to exit):"
@echo " Meeting on 2024-03-15 at 2:30 PM"
@echo " [15/Mar/2024:14:30:45 +0000]"
@echo " Q1 2024"
@echo " yesterday"
@echo " 1710510645"
@echo ""
$(BINARY_PATH)
.PHONY: help
help: ## Show this help message
@echo "Dateline Makefile - Available targets:"
@echo ""
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-20s\033[0m %s\n", $$1, $$2}'
@echo ""
@echo "Examples:"
@echo " make build # Build the binary"
@echo " make test-formats # Run comprehensive format tests"
@echo " make run-example # Test with sample input"
@echo " make demo # Interactive demo"