-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMakefile
More file actions
183 lines (166 loc) · 5.53 KB
/
Makefile
File metadata and controls
183 lines (166 loc) · 5.53 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
# Makefile for boundary
# Variables
BINARY_NAME := boundary
BUILD_DIR := build
INSTALL_PATH ?= /usr/local/bin
VERSION := $(shell git describe --tags --exact-match 2>/dev/null || echo "dev-$(shell git rev-parse --short HEAD)")
LDFLAGS := -s -w -X main.version=$(VERSION)
# Default target
.PHONY: all
all: build
# Build for current platform
.PHONY: build
build:
@echo "Building $(BINARY_NAME) for current platform..."
@echo "Version: $(VERSION)"
go build -ldflags="$(LDFLAGS)" -o $(BINARY_NAME) ./cmd/boundary
@echo "✓ Built $(BINARY_NAME)"
# Install binary to $(INSTALL_PATH) (default: /usr/local/bin).
.PHONY: install
install: build
@echo "Installing $(BINARY_NAME) to $(INSTALL_PATH)..."
sudo install -m 755 $(BINARY_NAME) $(INSTALL_PATH)/$(BINARY_NAME)
@echo "✓ Installed $(INSTALL_PATH)/$(BINARY_NAME)"
# Build for all supported platforms
.PHONY: build-all
build-all:
@echo "Building $(BINARY_NAME) for all platforms..."
@echo "Version: $(VERSION)"
@mkdir -p $(BUILD_DIR)
@echo "Building Linux amd64..."
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags="$(LDFLAGS)" -o $(BUILD_DIR)/$(BINARY_NAME)-linux-amd64 ./cmd/boundary
@echo "Building Linux arm64..."
GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build -ldflags="$(LDFLAGS)" -o $(BUILD_DIR)/$(BINARY_NAME)-linux-arm64 ./cmd/boundary
@# macOS builds removed; Linux only
@echo "✓ All binaries built successfully!"
@echo "Binaries are in the '$(BUILD_DIR)' directory:"
@ls -la $(BUILD_DIR)/
# Download and verify dependencies
.PHONY: deps
deps:
@echo "Downloading dependencies..."
go mod download
@echo "Verifying dependencies..."
go mod verify
@echo "✓ Dependencies ready!"
# Run unit tests only (no sudo required)
.PHONY: unit-test
unit-test:
@echo "Running unit tests..."
@which go > /dev/null || (echo "Go not found in PATH" && exit 1)
go test -v -race $$(go list ./... | grep -v e2e_tests)
@echo "✓ Unit tests passed!"
# Run E2E tests (Linux only, needs sudo)
.PHONY: e2e-test
e2e-test:
@echo "Running E2E tests..."
@which go > /dev/null || (echo "Go not found in PATH" && exit 1)
@if [ "$$(uname)" != "Linux" ]; then \
echo "E2E tests require Linux platform. Current platform: $$(uname)"; \
exit 1; \
fi
sudo $(shell which go) test -v -race ./e2e_tests -count=1
@echo "✓ E2E tests passed!"
# Run tests with coverage (needs sudo for E2E tests)
.PHONY: test-coverage
test-coverage:
@echo "Running tests with coverage..."
go test -v -race -coverprofile=coverage.out ./...
go tool cover -html=coverage.out -o coverage.html
@echo "✓ Coverage report generated: coverage.html"
# CI checks (deps, test, build)
.PHONY: ci
ci: deps test build
@echo "✓ All CI checks passed!"
# CI checks with coverage
.PHONY: ci-coverage
ci-coverage: deps test-coverage build
@echo "✓ All CI checks with coverage passed!"
# Prepare release archives
.PHONY: release-archives
release-archives:
@echo "Creating release archives..."
@# Check if we should use build directory or artifacts directory
@if [ -d "binaries" ]; then \
echo "Using artifacts from binaries/ directory"; \
mkdir -p archives; \
for dir in binaries/*/; do \
if [ -d "$$dir" ]; then \
binary_name=$$(basename "$$dir"); \
if [ -f "$$dir/$$binary_name" ]; then \
echo "Creating archive for $$binary_name..."; \
cd "$$dir" && tar -czf "../../archives/$${binary_name}.tar.gz" "$$binary_name" && cd ../..; \
fi; \
fi; \
done; \
else \
echo "Using binaries from build/ directory"; \
if [ ! -d "$(BUILD_DIR)" ]; then \
echo "No binaries found. Run 'make build-all' first."; \
exit 1; \
fi; \
mkdir -p $(BUILD_DIR)/archives; \
for binary in $(BUILD_DIR)/$(BINARY_NAME)-*; do \
if [ -f "$$binary" ]; then \
binary_name=$$(basename "$$binary"); \
echo "Creating archive for $$binary_name..."; \
cd $(BUILD_DIR) && tar -czf "archives/$${binary_name}.tar.gz" "$$binary_name" && cd ..; \
fi; \
done; \
fi
@echo "✓ Release archives created!"
@if [ -d "archives" ]; then \
echo "Archives in archives/:"; \
ls -la archives/; \
else \
echo "Archives in $(BUILD_DIR)/archives/:"; \
ls -la $(BUILD_DIR)/archives/; \
fi
# Clean build artifacts
.PHONY: clean
clean:
@echo "Cleaning build artifacts..."
rm -f $(BINARY_NAME)
rm -rf $(BUILD_DIR)
rm -f coverage.out coverage.html
@echo "✓ Clean complete!"
# Format code
.PHONY: fmt
fmt:
@echo "Formatting code..."
go fmt ./...
@echo "✓ Code formatted!"
# Check formatting (for CI)
.PHONY: fmt-check
fmt-check:
@echo "Checking code formatting..."
@if [ -n "$$(gofmt -l .)" ]; then \
echo "The following files are not formatted:"; \
gofmt -l .; \
echo "Run 'make fmt' to fix formatting."; \
exit 1; \
fi
@echo "✓ All code is properly formatted!"
# Lint code
.PHONY: lint
lint:
@echo "Linting code..."
golangci-lint run
@echo "✓ Linting complete!"
# Show help
.PHONY: help
help:
@echo "Available targets:"
@echo " build Build for current platform"
@echo " build-all Build for all supported platforms"
@echo " install Install binary to $(INSTALL_PATH) (may need sudo)"
@echo " deps Download and verify dependencies"
@echo " test Run tests"
@echo " test-coverage Run tests with coverage report"
@echo " ci Run CI checks (deps + test + build)"
@echo " ci-coverage Run CI checks with coverage"
@echo " release-archives Create release archives"
@echo " clean Clean build artifacts"
@echo " fmt Format code"
@echo " lint Lint code"
@echo " help Show this help message"