-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
77 lines (62 loc) · 2.69 KB
/
Makefile
File metadata and controls
77 lines (62 loc) · 2.69 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
.PHONY: build test test-coverage clean lint fmt vet check install build-all help deps
# Version info
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
DATE ?= $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
# Build variables
BINARY_NAME := infranow
BUILD_DIR := bin
GO := go
GOFLAGS := -trimpath
LDFLAGS := -ldflags "-s -w -X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.date=$(DATE)"
# Default target
.DEFAULT_GOAL := help
help: ## Show this help message
@echo "Usage: make [target]"
@echo ""
@echo "Targets:"
@awk 'BEGIN {FS = ":.*##"} /^[a-zA-Z_-]+:.*?##/ { printf " %-15s %s\n", $$1, $$2 }' $(MAKEFILE_LIST)
build: ## Build the binary
@echo "Building $(BINARY_NAME) $(VERSION)..."
@mkdir -p $(BUILD_DIR)
$(GO) build $(GOFLAGS) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME) ./cmd/infranow
@echo "Binary built: $(BUILD_DIR)/$(BINARY_NAME)"
install: ## Install the binary to GOPATH/bin
@echo "Installing $(BINARY_NAME)..."
$(GO) install $(GOFLAGS) $(LDFLAGS) ./cmd/infranow
test: ## Run tests
@echo "Running tests..."
$(GO) test -v -race -timeout 30s ./...
test-coverage: ## Run tests with coverage
@echo "Running tests with coverage..."
$(GO) test -v -race -coverprofile=coverage.out -covermode=atomic ./...
$(GO) tool cover -func=coverage.out
clean: ## Clean build artifacts
@echo "Cleaning..."
rm -rf $(BUILD_DIR)
rm -f coverage.out
$(GO) clean
fmt: ## Format code
@echo "Formatting code..."
$(GO) fmt ./...
vet: ## Run go vet
@echo "Running go vet..."
$(GO) vet ./...
lint: ## Run linters (requires golangci-lint)
@echo "Running linters..."
@which golangci-lint > /dev/null || (echo "golangci-lint not found, install from https://golangci-lint.run/usage/install/" && exit 1)
golangci-lint run ./...
check: fmt vet test ## Run all checks (fmt, vet, test)
build-all: ## Build for all platforms
@echo "Building for all platforms..."
@mkdir -p $(BUILD_DIR)
GOOS=linux GOARCH=amd64 $(GO) build $(GOFLAGS) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-linux-amd64 ./cmd/infranow
GOOS=linux GOARCH=arm64 $(GO) build $(GOFLAGS) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-linux-arm64 ./cmd/infranow
GOOS=darwin GOARCH=amd64 $(GO) build $(GOFLAGS) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-darwin-amd64 ./cmd/infranow
GOOS=darwin GOARCH=arm64 $(GO) build $(GOFLAGS) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-darwin-arm64 ./cmd/infranow
GOOS=windows GOARCH=amd64 $(GO) build $(GOFLAGS) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-windows-amd64.exe ./cmd/infranow
@echo "All binaries built in $(BUILD_DIR)/"
deps: ## Download dependencies
@echo "Downloading dependencies..."
$(GO) mod download
$(GO) mod tidy