-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
116 lines (92 loc) · 4.15 KB
/
Copy pathMakefile
File metadata and controls
116 lines (92 loc) · 4.15 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
.PHONY: help build test test-coverage lint fmt vet clean install deps run check ci build-all docker-build
# Variables
BINARY_NAME=trustwatch
BUILD_DIR=bin
VERSION=$(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
GIT_COMMIT=$(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
BUILD_DATE=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
LDFLAGS=-ldflags "-X main.version=$(VERSION) -X main.commit=$(GIT_COMMIT) -X main.date=$(BUILD_DATE) -s -w"
IMAGE?=trustwatch
# Go parameters
GOCMD=go
GOBUILD=$(GOCMD) build
GOTEST=$(GOCMD) test
GOCLEAN=$(GOCMD) clean
GOMOD=$(GOCMD) mod
GOFMT=gofmt
GOVET=$(GOCMD) vet
help: ## Show this help message
@echo "Available targets:"
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-20s\033[0m %s\n", $$1, $$2}'
build: ## Build the binary
@echo "Building $(BINARY_NAME) version $(VERSION)..."
@mkdir -p $(BUILD_DIR)
$(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME) ./cmd/$(BINARY_NAME)
@echo "Build complete: $(BUILD_DIR)/$(BINARY_NAME)"
test: ## Run tests with race detection
@echo "Running tests..."
$(GOTEST) -v -race -timeout 30s ./...
test-coverage: ## Run tests with coverage report
@echo "Running tests with coverage..."
$(GOTEST) -v -coverprofile=coverage.out ./... || true
@echo "Generating HTML coverage report..."
@if [ -f coverage.out ]; then \
$(GOCMD) tool cover -html=coverage.out -o coverage.html; \
echo "Coverage report generated: coverage.html"; \
else \
echo "No coverage data generated"; \
fi
test-short: ## Run tests without race detector (faster)
@echo "Running tests (short)..."
$(GOTEST) -v -short ./...
lint: ## Run golangci-lint
@echo "Running golangci-lint..."
@which golangci-lint > /dev/null || (echo "golangci-lint not installed. Install with: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$(go env GOPATH)/bin"; exit 1)
golangci-lint run
fmt: ## Format code with gofmt
@echo "Formatting code..."
$(GOFMT) -s -w .
vet: ## Run go vet
@echo "Running go vet..."
$(GOVET) ./...
clean: ## Remove build artifacts
@echo "Cleaning..."
$(GOCLEAN)
rm -rf $(BUILD_DIR)
rm -f coverage.out coverage.html
@echo "Clean complete"
kubectl-plugin: build ## Build kubectl-trustwatch plugin
@ln -sf $(BINARY_NAME) $(BUILD_DIR)/kubectl-trustwatch
@echo "kubectl plugin: $(BUILD_DIR)/kubectl-trustwatch"
install: build ## Install binary to GOPATH/bin
@echo "Installing to $(GOPATH)/bin..."
cp $(BUILD_DIR)/$(BINARY_NAME) $(GOPATH)/bin/
ln -sf $(BINARY_NAME) $(GOPATH)/bin/kubectl-trustwatch
@echo "Installed: $(GOPATH)/bin/$(BINARY_NAME) + kubectl-trustwatch"
deps: ## Download and tidy dependencies
@echo "Downloading dependencies..."
$(GOMOD) download
$(GOMOD) tidy
@echo "Dependencies updated"
run: build ## Build and run the binary
@echo "Running $(BINARY_NAME)..."
./$(BUILD_DIR)/$(BINARY_NAME) --help
# Multi-platform builds
build-linux: ## Build for Linux (amd64)
GOOS=linux GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-linux-amd64 ./cmd/$(BINARY_NAME)
build-linux-arm: ## Build for Linux (arm64)
GOOS=linux GOARCH=arm64 $(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-linux-arm64 ./cmd/$(BINARY_NAME)
build-darwin: ## Build for macOS (amd64)
GOOS=darwin GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-darwin-amd64 ./cmd/$(BINARY_NAME)
build-darwin-arm: ## Build for macOS (arm64)
GOOS=darwin GOARCH=arm64 $(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-darwin-arm64 ./cmd/$(BINARY_NAME)
build-windows: ## Build for Windows (amd64)
GOOS=windows GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-windows-amd64.exe ./cmd/$(BINARY_NAME)
build-all: build-linux build-linux-arm build-darwin build-darwin-arm build-windows ## Build for all platforms
@echo "All platform builds complete"
docker-build: ## Build container image (IMAGE=my-registry.io/trustwatch)
docker build --build-arg VERSION=$(VERSION) -t $(IMAGE):$(VERSION) -t $(IMAGE):latest .
check: fmt vet lint test ## Run all checks (fmt, vet, lint, test)
@echo "All checks passed!"
ci: deps check ## Run CI checks (for GitHub Actions)
@echo "CI checks complete"