-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
141 lines (121 loc) · 4.15 KB
/
Makefile
File metadata and controls
141 lines (121 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
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
# pctl Makefile
# Variables
BINARY_NAME=pctl
BUILD_DIR=build
VERSION?=dev
COMMIT=$(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
BUILD_TIME=$(shell date -u '+%Y-%m-%d_%H:%M:%S')
LDFLAGS=-ldflags "-X github.com/deviantony/pctl/cmd/version.Version=$(VERSION) -X github.com/deviantony/pctl/cmd/version.Commit=$(COMMIT) -X github.com/deviantony/pctl/cmd/version.BuildTime=$(BUILD_TIME)"
# Default target
.PHONY: all
all: clean build
# Build the binary
.PHONY: build
build:
@echo "Building $(BINARY_NAME)..."
@mkdir -p $(BUILD_DIR)
go build $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME) .
@echo "Binary built: $(BUILD_DIR)/$(BINARY_NAME)"
# Build for multiple platforms
.PHONY: build-all
build-all: clean
@echo "Building for multiple platforms..."
@mkdir -p $(BUILD_DIR)
# Linux AMD64
GOOS=linux GOARCH=amd64 go build $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-linux-amd64 .
# Linux ARM64
GOOS=linux GOARCH=arm64 go build $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-linux-arm64 .
# macOS AMD64
GOOS=darwin GOARCH=amd64 go build $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-darwin-amd64 .
# macOS ARM64 (Apple Silicon)
GOOS=darwin GOARCH=arm64 go build $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-darwin-arm64 .
# Windows AMD64
GOOS=windows GOARCH=amd64 go build $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-windows-amd64.exe .
@echo "Cross-platform binaries built in $(BUILD_DIR)/"
# Install dependencies
.PHONY: deps
deps:
@echo "Installing dependencies..."
go mod download
go mod tidy
# Run tests
.PHONY: test
test:
@echo "Running tests..."
go test -v ./...
# Run tests with coverage
.PHONY: test-coverage
test-coverage:
@echo "Running tests with coverage..."
go test -v -coverprofile=coverage.out ./...
go tool cover -html=coverage.out -o coverage.html
@echo "Coverage report generated: coverage.html"
# Run integration tests
.PHONY: test-integration
test-integration:
@echo "Running integration tests..."
@if [ ! -f integration_test_config.json ]; then \
echo "Error: integration_test_config.json not found"; \
echo "Copy integration_test_config.json.example to integration_test_config.json and configure it"; \
echo "Example:"; \
echo " cp integration_test_config.json.example integration_test_config.json"; \
echo " # Edit integration_test_config.json with your Portainer details"; \
exit 1; \
fi
go test -v -tags=integration ./tests/integration/...
# Lint the code
.PHONY: lint
lint:
@echo "Running linter..."
@if command -v golangci-lint >/dev/null 2>&1; then \
golangci-lint run; \
else \
echo "golangci-lint not found. Install it with: go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest"; \
fi
# Format the code
.PHONY: fmt
fmt:
@echo "Formatting code..."
go fmt ./...
# Clean build artifacts
.PHONY: clean
clean:
@echo "Cleaning build artifacts..."
rm -rf $(BUILD_DIR)
rm -f coverage.out coverage.html
# Install the binary to GOPATH/bin
.PHONY: install
install: build
@echo "Installing $(BINARY_NAME) to GOPATH/bin..."
cp $(BUILD_DIR)/$(BINARY_NAME) $(GOPATH)/bin/$(BINARY_NAME)
@echo "Installed: $(GOPATH)/bin/$(BINARY_NAME)"
# Run the binary locally
.PHONY: run
run: build
@echo "Running $(BINARY_NAME)..."
./$(BUILD_DIR)/$(BINARY_NAME)
# Show help
.PHONY: help
help:
@echo "Available targets:"
@echo " build - Build the binary for current platform"
@echo " build-all - Build binaries for multiple platforms"
@echo " deps - Install and tidy dependencies"
@echo " test - Run tests"
@echo " test-coverage - Run tests with coverage report"
@echo " test-integration - Run integration tests (requires integration_test_config.json)"
@echo " lint - Run linter (requires golangci-lint)"
@echo " fmt - Format code"
@echo " clean - Clean build artifacts"
@echo " install - Install binary to GOPATH/bin"
@echo " run - Build and run the binary"
@echo " help - Show this help message"
@echo ""
@echo "Variables:"
@echo " VERSION - Version to embed in binary (default: dev)"
@echo ""
@echo "Examples:"
@echo " make build VERSION=1.1.1"
@echo " make build-all"
@echo " make test-coverage"
@echo " ./build/pctl version"