-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
116 lines (96 loc) · 3.32 KB
/
Copy pathMakefile
File metadata and controls
116 lines (96 loc) · 3.32 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
# Variables
BINARY_NAME=urlx
VERSION?=1.0.0
BUILD_DIR=build
MAIN_PATH=main.go
# Go parameters
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get
GOMOD=$(GOCMD) mod
# Build flags
LDFLAGS=-ldflags "-s -w -X main.version=$(VERSION)"
.PHONY: all build clean test coverage help install docker
# Default target
all: clean build
## help: Display this help message
help:
@echo "Available targets:"
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf " %-15s %s\n", $$1, $$2}' $(MAKEFILE_LIST)
## build: Build the binary
build:
@echo "Building $(BINARY_NAME)..."
$(GOBUILD) $(LDFLAGS) -o $(BINARY_NAME) $(MAIN_PATH)
@echo "Build complete: ./$(BINARY_NAME)"
## build-all: Build for all platforms
build-all: clean
@echo "Building for multiple platforms..."
@mkdir -p $(BUILD_DIR)
GOOS=linux GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-linux-amd64 $(MAIN_PATH)
GOOS=linux GOARCH=arm64 $(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-linux-arm64 $(MAIN_PATH)
GOOS=darwin GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-darwin-amd64 $(MAIN_PATH)
GOOS=darwin GOARCH=arm64 $(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-darwin-arm64 $(MAIN_PATH)
GOOS=windows GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-windows-amd64.exe $(MAIN_PATH)
@echo "Build complete for all platforms in $(BUILD_DIR)/"
## clean: Remove build artifacts
clean:
@echo "Cleaning..."
$(GOCLEAN)
@rm -f $(BINARY_NAME)
@rm -rf $(BUILD_DIR)
@echo "Clean complete"
## test: Run tests
test:
@echo "Running tests..."
$(GOTEST) -v ./...
## coverage: Run tests with coverage
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"
## install: Install the binary to $GOPATH/bin
install: build
@echo "Installing $(BINARY_NAME)..."
@cp $(BINARY_NAME) $(GOPATH)/bin/
@echo "Installed to $(GOPATH)/bin/$(BINARY_NAME)"
## run: Build and run with example domain
run: build
@echo "Running $(BINARY_NAME)..."
./$(BINARY_NAME) -domain example.com -v
## deps: Download dependencies
deps:
@echo "Downloading dependencies..."
$(GOMOD) download
$(GOMOD) tidy
## fmt: Format code
fmt:
@echo "Formatting code..."
$(GOCMD) fmt ./...
## vet: Run go vet
vet:
@echo "Running go vet..."
$(GOCMD) vet ./...
## lint: Run golangci-lint (requires golangci-lint installed)
lint:
@echo "Running linter..."
@which golangci-lint > /dev/null || (echo "golangci-lint not installed. Run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOPATH)/bin" && exit 1)
golangci-lint run
## docker-build: Build Docker image
docker-build:
@echo "Building Docker image..."
docker build -t $(BINARY_NAME):$(VERSION) .
docker tag $(BINARY_NAME):$(VERSION) $(BINARY_NAME):latest
@echo "Docker image built: $(BINARY_NAME):$(VERSION)"
## docker-run: Run in Docker container
docker-run:
@echo "Running in Docker..."
docker run --rm $(BINARY_NAME):latest -domain example.com -v
## release: Create a new release (run tests, build all platforms)
release: test build-all
@echo "Release $(VERSION) ready in $(BUILD_DIR)/"
## check: Run all checks (fmt, vet, lint, test)
check: fmt vet lint test
@echo "All checks passed!"