-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMakefile
More file actions
149 lines (122 loc) · 5.85 KB
/
Makefile
File metadata and controls
149 lines (122 loc) · 5.85 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
# ==============================================================================
# Makefile for hyperfleet-hooks
# ==============================================================================
include .bingo/Variables.mk
.PHONY: help build build-all test test-coverage lint clean install validate-commits \
check-container-tool image image-push
# ==============================================================================
# Configuration
# ==============================================================================
# Binary configuration
BINARY_NAME := hyperfleet-hooks
BIN_DIR := bin
# Version information (auto-detected from git)
APP_VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "0.0.0-dev")
GIT_SHA ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
GIT_DIRTY ?= $(shell [ -z "$$(git status --porcelain 2>/dev/null)" ] || echo "-modified")
BUILD_DATE ?= $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
# Container configuration
CONTAINER_TOOL ?= $(shell command -v podman 2>/dev/null || command -v docker 2>/dev/null)
PLATFORM ?= linux/amd64
IMAGE_REGISTRY ?= quay.io/openshift-hyperfleet
IMAGE_NAME ?= hyperfleet-git-hooks
IMAGE_TAG ?= $(APP_VERSION)
# Build flags
GOFLAGS ?= -trimpath
LDFLAGS := -ldflags "\
-s -w \
-X github.com/openshift-hyperfleet/hyperfleet-hooks/pkg/version.Version=$(APP_VERSION) \
-X github.com/openshift-hyperfleet/hyperfleet-hooks/pkg/version.GitCommit=$(GIT_SHA)$(GIT_DIRTY) \
-X github.com/openshift-hyperfleet/hyperfleet-hooks/pkg/version.BuildDate=$(BUILD_DATE)"
# ==============================================================================
# Targets
# ==============================================================================
.DEFAULT_GOAL := help
help: ## Show this help message
@echo 'Usage: make [target]'
@echo ''
@echo 'Available targets:'
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf " %-20s %s\n", $$1, $$2}' $(MAKEFILE_LIST)
# ------------------------------------------------------------------------------
# Build
# ------------------------------------------------------------------------------
build: ## Build the binary
@echo "Building $(BINARY_NAME) $(APP_VERSION)..."
@mkdir -p $(BIN_DIR)
go build $(GOFLAGS) $(LDFLAGS) -o $(BIN_DIR)/$(BINARY_NAME) ./cmd/hyperfleet-hooks
@echo "✓ Built $(BIN_DIR)/$(BINARY_NAME)"
build-all: ## Build binaries for all platforms
@echo "Building for all platforms..."
@mkdir -p $(BIN_DIR)
GOOS=linux GOARCH=amd64 go build $(GOFLAGS) $(LDFLAGS) -o $(BIN_DIR)/$(BINARY_NAME)-linux-amd64 ./cmd/hyperfleet-hooks
GOOS=linux GOARCH=arm64 go build $(GOFLAGS) $(LDFLAGS) -o $(BIN_DIR)/$(BINARY_NAME)-linux-arm64 ./cmd/hyperfleet-hooks
GOOS=darwin GOARCH=amd64 go build $(GOFLAGS) $(LDFLAGS) -o $(BIN_DIR)/$(BINARY_NAME)-darwin-amd64 ./cmd/hyperfleet-hooks
GOOS=darwin GOARCH=arm64 go build $(GOFLAGS) $(LDFLAGS) -o $(BIN_DIR)/$(BINARY_NAME)-darwin-arm64 ./cmd/hyperfleet-hooks
@echo "✓ Built all platform binaries"
# ------------------------------------------------------------------------------
# Test
# ------------------------------------------------------------------------------
test: ## Run tests
@echo "Running tests..."
go test -v -race -coverprofile=coverage.out ./...
@echo "✓ Tests passed"
test-coverage: test ## Run tests with coverage report
@echo "Generating coverage report..."
go tool cover -html=coverage.out -o coverage.html
@echo "✓ Coverage report generated: coverage.html"
# ------------------------------------------------------------------------------
# Quality
# ------------------------------------------------------------------------------
lint: $(GOLANGCI_LINT) ## Run linters
@echo "Running linters..."
$(GOLANGCI_LINT) run --timeout=5m
@echo "✓ Linting passed"
# ------------------------------------------------------------------------------
# Utility
# ------------------------------------------------------------------------------
clean: ## Clean build artifacts
@echo "Cleaning..."
rm -rf $(BIN_DIR)
rm -f coverage.out coverage.html
@echo "✓ Cleaned"
install: build ## Install binary to /usr/local/bin
@echo "Installing $(BINARY_NAME) to /usr/local/bin..."
@cp $(BIN_DIR)/$(BINARY_NAME) /usr/local/bin/$(BINARY_NAME)
@echo "✓ Installed $(BINARY_NAME)"
# ------------------------------------------------------------------------------
# Container
# ------------------------------------------------------------------------------
check-container-tool:
ifndef CONTAINER_TOOL
@echo "Error: No container tool found (podman or docker)"
@echo ""
@echo "Please install one of:"
@echo " brew install podman # macOS"
@echo " brew install docker # macOS"
@echo " dnf install podman # Fedora/RHEL"
@exit 1
endif
image: check-container-tool ## Build container image
@echo "Building container image..."
$(CONTAINER_TOOL) build \
--platform $(PLATFORM) \
--build-arg GIT_SHA=$(GIT_SHA) \
--build-arg GIT_DIRTY=$(GIT_DIRTY) \
--build-arg BUILD_DATE=$(BUILD_DATE) \
--build-arg APP_VERSION=$(APP_VERSION) \
-t $(IMAGE_REGISTRY)/$(IMAGE_NAME):$(IMAGE_TAG) \
-t $(IMAGE_REGISTRY)/$(IMAGE_NAME):latest .
@echo "✓ Built $(IMAGE_REGISTRY)/$(IMAGE_NAME):$(IMAGE_TAG)"
@echo "✓ Built $(IMAGE_REGISTRY)/$(IMAGE_NAME):latest"
image-push: check-container-tool image ## Build and push container image
@echo "Pushing container image..."
$(CONTAINER_TOOL) push $(IMAGE_REGISTRY)/$(IMAGE_NAME):$(IMAGE_TAG)
$(CONTAINER_TOOL) push $(IMAGE_REGISTRY)/$(IMAGE_NAME):latest
@echo "✓ Pushed $(IMAGE_REGISTRY)/$(IMAGE_NAME):$(IMAGE_TAG)"
@echo "✓ Pushed $(IMAGE_REGISTRY)/$(IMAGE_NAME):latest"
# ------------------------------------------------------------------------------
# CI
# ------------------------------------------------------------------------------
validate-commits: build ## Validate commits in current branch (CI mode)
@echo "Validating commits..."
@./bin/hyperfleet-hooks commitlint --pr