-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
65 lines (56 loc) · 2.33 KB
/
Makefile
File metadata and controls
65 lines (56 loc) · 2.33 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
.PHONY: build build-all test lint clean help
BUILD_DIR := build
BINARY_NAME := okms-k8s-encryption-provider
DIST_DIR := $(BUILD_DIR)/dist
MAIN_PKG := ./cmd/okms-k8s-encryption-provider
# Supported architectures for cross-compilation
ARCHITECTURES := linux/amd64 linux/arm64 darwin/amd64 darwin/arm64 windows/amd64
all: lint build test
# Build the application for current architecture
build:
@echo "Building okms-k8s-encryption-provider for current architecture..."
@mkdir -p $(BUILD_DIR)
go build -o $(BUILD_DIR)/$(BINARY_NAME) $(MAIN_PKG)
# Build for multiple architectures
build-all: clean
@echo "Building okms-k8s-encryption-provider for multiple architectures..."
@mkdir -p $(DIST_DIR)
@for arch in $(ARCHITECTURES); do \
os=$${arch%/*}; \
cpu=$${arch#*/}; \
output=$(DIST_DIR)/$(BINARY_NAME)-$${os}-$${cpu}; \
if [ "$$os" = "windows" ]; then \
output=$${output}.exe; \
fi; \
echo "Building for $$arch -> $$output"; \
GOOS=$$os GOARCH=$$cpu go build -o $$output -ldflags "-X main.version=$(GIT_VERSION)" $(MAIN_PKG); \
done
@echo "Build complete. Artifacts in $(DIST_DIR)/"
# Lint code with golangci-lint
lint:
@echo "Running golangci-lint..."
@mkdir -p $(BUILD_DIR)
golangci-lint run --output.json.path=$(BUILD_DIR)/lint-report.json --output.text.path=stdout
# Run tests with coverage and junit report
test:
@echo "Running tests with coverage..."
@mkdir -p $(BUILD_DIR)
go test -v -json -coverprofile=$(BUILD_DIR)/coverage.out ./... > $(BUILD_DIR)/test-results.json
gotestsum --junitfile=$(BUILD_DIR)/junit.xml --raw-command -- cat $(BUILD_DIR)/test-results.json
go tool cover -html=$(BUILD_DIR)/coverage.out -o $(BUILD_DIR)/coverage.html
clean:
@echo "Cleaning up..."
rm -rf $(BUILD_DIR)
# Display help message
help:
@echo "Available targets:"
@echo " all - Run lint, build, and test"
@echo " lint - Run golangci-lint code linter"
@echo " build - Build the application for current architecture"
@echo " build-all - Build for multiple architectures (linux/darwin/windows, amd64/arm64)"
@echo " test - Run unit tests with coverage and junit report"
@echo " clean - Remove build artifacts"
@echo " help - Display this help message"
@echo ""
@echo "Environment variables:"
@echo " GIT_VERSION - Version/tag to embed in binary (default: git describe or dev)"