-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
245 lines (206 loc) · 6.71 KB
/
Copy pathMakefile
File metadata and controls
245 lines (206 loc) · 6.71 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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
# Dash-Porter Makefile
# Variables
BINARY_NAME=dash-porter
VERSION?=1.0.0
BUILD_DIR=build
DIST_DIR=dist
GO_VERSION=1.19
# Go parameters
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get
GOMOD=$(GOCMD) mod
# Build flags
LDFLAGS=-ldflags "-X main.Version=$(VERSION) -X main.BuildTime=$(shell date -u '+%Y-%m-%d_%H:%M:%S')"
.PHONY: all build clean test test-coverage lint fmt help install dev deps
# Default target
all: clean deps lint test build
# Build the application
build:
@echo "Building $(BINARY_NAME)..."
@mkdir -p $(BUILD_DIR)
$(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME) .
@echo "Build complete: $(BUILD_DIR)/$(BINARY_NAME)"
# Build for multiple platforms
build-all: clean deps
@echo "Building for multiple platforms..."
@mkdir -p $(DIST_DIR)
# Linux AMD64
GOOS=linux GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o $(DIST_DIR)/$(BINARY_NAME)-linux-amd64 .
# Linux ARM64
GOOS=linux GOARCH=arm64 $(GOBUILD) $(LDFLAGS) -o $(DIST_DIR)/$(BINARY_NAME)-linux-arm64 .
# macOS AMD64
GOOS=darwin GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o $(DIST_DIR)/$(BINARY_NAME)-darwin-amd64 .
# macOS ARM64 (Apple Silicon)
GOOS=darwin GOARCH=arm64 $(GOBUILD) $(LDFLAGS) -o $(DIST_DIR)/$(BINARY_NAME)-darwin-arm64 .
# Windows AMD64
GOOS=windows GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o $(DIST_DIR)/$(BINARY_NAME)-windows-amd64.exe .
@echo "Multi-platform build complete in $(DIST_DIR)/"
# Install dependencies
deps:
@echo "Installing dependencies..."
$(GOMOD) download
$(GOMOD) tidy
# Run tests
test:
@echo "Running tests..."
$(GOTEST) -v ./...
# Run tests with coverage
test-coverage:
@echo "Running tests with coverage..."
$(GOTEST) -v -coverprofile=coverage.out ./...
$(GOCMD) tool cover -html=coverage.out -o coverage.html
@echo "Coverage report generated: coverage.html"
# Run benchmarks
benchmark:
@echo "Running benchmarks..."
$(GOTEST) -bench=. -benchmem ./...
# Lint the code
lint:
@echo "Running linters..."
@if command -v golangci-lint >/dev/null 2>&1; then \
golangci-lint run ./...; \
else \
echo "golangci-lint not installed. Installing..."; \
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest; \
golangci-lint run ./...; \
fi
# Format code
fmt:
@echo "Formatting code..."
gofmt -w .
@if command -v goimports >/dev/null 2>&1; then \
goimports -w .; \
else \
echo "goimports not installed. Installing..."; \
go install golang.org/x/tools/cmd/goimports@latest; \
goimports -w .; \
fi
# Clean build artifacts
clean:
@echo "Cleaning build artifacts..."
$(GOCLEAN)
rm -rf $(BUILD_DIR)
rm -rf $(DIST_DIR)
rm -f coverage.out coverage.html
# Install the binary to GOPATH/bin
install: build
@echo "Installing $(BINARY_NAME)..."
cp $(BUILD_DIR)/$(BINARY_NAME) $(GOPATH)/bin/$(BINARY_NAME)
@echo "Installed to $(GOPATH)/bin/$(BINARY_NAME)"
# Development setup
dev: deps
@echo "Setting up development environment..."
@if ! command -v golangci-lint >/dev/null 2>&1; then \
echo "Installing golangci-lint..."; \
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest; \
fi
@if ! command -v goimports >/dev/null 2>&1; then \
echo "Installing goimports..."; \
go install golang.org/x/tools/cmd/goimports@latest; \
fi
@echo "Development environment ready!"
# Run the application in development mode
run: build
@echo "Running $(BINARY_NAME)..."
./$(BUILD_DIR)/$(BINARY_NAME) --version
# Generate documentation
docs:
@echo "Generating documentation..."
@if command -v godoc >/dev/null 2>&1; then \
echo "Starting godoc server at http://localhost:6060"; \
godoc -http=:6060; \
else \
echo "godoc not available, installing..."; \
go install golang.org/x/tools/cmd/godoc@latest; \
godoc -http=:6060; \
fi
# Create release archives
release: build-all
@echo "Creating release archives..."
@mkdir -p $(DIST_DIR)/releases
# Linux AMD64
tar -czf $(DIST_DIR)/releases/$(BINARY_NAME)-$(VERSION)-linux-amd64.tar.gz -C $(DIST_DIR) $(BINARY_NAME)-linux-amd64
# Linux ARM64
tar -czf $(DIST_DIR)/releases/$(BINARY_NAME)-$(VERSION)-linux-arm64.tar.gz -C $(DIST_DIR) $(BINARY_NAME)-linux-arm64
# macOS AMD64
tar -czf $(DIST_DIR)/releases/$(BINARY_NAME)-$(VERSION)-darwin-amd64.tar.gz -C $(DIST_DIR) $(BINARY_NAME)-darwin-amd64
# macOS ARM64
tar -czf $(DIST_DIR)/releases/$(BINARY_NAME)-$(VERSION)-darwin-arm64.tar.gz -C $(DIST_DIR) $(BINARY_NAME)-darwin-arm64
# Windows AMD64
zip -j $(DIST_DIR)/releases/$(BINARY_NAME)-$(VERSION)-windows-amd64.zip $(DIST_DIR)/$(BINARY_NAME)-windows-amd64.exe
@echo "Release archives created in $(DIST_DIR)/releases/"
# Check security vulnerabilities
security:
@echo "Checking for security vulnerabilities..."
@if command -v gosec >/dev/null 2>&1; then \
gosec ./...; \
else \
echo "gosec not installed. Installing..."; \
go install github.com/securecodewarrior/gosec/v2/cmd/gosec@latest; \
gosec ./...; \
fi
# Validate go.mod
mod-verify:
@echo "Verifying go.mod..."
$(GOMOD) verify
# Update dependencies
update-deps:
@echo "Updating dependencies..."
$(GOMOD) get -u ./...
$(GOMOD) tidy
# Check if code is properly formatted
check-fmt:
@echo "Checking code formatting..."
@unformatted=$$(gofmt -l .); \
if [ -n "$$unformatted" ]; then \
echo "The following files need formatting:"; \
echo "$$unformatted"; \
exit 1; \
else \
echo "All files are properly formatted"; \
fi
# Pre-commit checks
pre-commit: deps fmt lint test
# CI pipeline
ci: deps check-fmt lint test mod-verify security
# Display help
help:
@echo "Dash-Porter Makefile Commands:"
@echo ""
@echo "Build Commands:"
@echo " build Build the application"
@echo " build-all Build for multiple platforms"
@echo " install Install binary to GOPATH/bin"
@echo " release Create release archives"
@echo ""
@echo "Development Commands:"
@echo " dev Setup development environment"
@echo " run Build and run the application"
@echo " deps Install dependencies"
@echo " fmt Format code"
@echo " lint Run linters"
@echo ""
@echo "Testing Commands:"
@echo " test Run tests"
@echo " test-coverage Run tests with coverage"
@echo " benchmark Run benchmarks"
@echo ""
@echo "Quality Commands:"
@echo " security Check for security vulnerabilities"
@echo " check-fmt Check if code is formatted"
@echo " mod-verify Verify go.mod"
@echo " update-deps Update dependencies"
@echo ""
@echo "CI Commands:"
@echo " pre-commit Run pre-commit checks"
@echo " ci Run full CI pipeline"
@echo ""
@echo "Utility Commands:"
@echo " clean Clean build artifacts"
@echo " docs Generate and serve documentation"
@echo " help Show this help message"
# Default target when no argument is provided
.DEFAULT_GOAL := help