-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathMakefile
More file actions
169 lines (136 loc) · 5.21 KB
/
Makefile
File metadata and controls
169 lines (136 loc) · 5.21 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
include .bingo/Variables.mk
.DEFAULT_GOAL := help
GO ?= go
GOFMT ?= gofmt
# Binary output directory and name
BIN_DIR := bin
OUTPUT_DIR := output
BINARY_NAME := $(BIN_DIR)/hyperfleet-e2e
# Version information
BUILD_DATE ?= $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
GIT_SHA ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
GIT_COMMIT ?= $(shell git rev-parse HEAD 2>/dev/null || echo "unknown")
GIT_DIRTY ?= $(shell git diff --quiet 2>/dev/null || echo "-modified")
VERSION:=$(GIT_SHA)$(GIT_DIRTY)
# Go build flags
LDFLAGS := -X main.version=$(VERSION) \
-X main.commit=$(GIT_COMMIT) \
-X main.date=$(BUILD_DATE)
# Container tool (docker or podman)
CONTAINER_TOOL ?= $(shell command -v podman 2>/dev/null || command -v docker 2>/dev/null)
# =============================================================================
# Image Configuration
# =============================================================================
IMAGE_REGISTRY ?= quay.io/openshift-hyperfleet
IMAGE_NAME ?= hyperfleet-e2e
IMAGE_TAG ?= $(VERSION)
# Dev image configuration - set QUAY_USER to push to personal registry
# Usage: QUAY_USER=myuser make image-dev
QUAY_USER ?=
DEV_TAG ?= dev-$(GIT_SHA)
.PHONY: help
help: ## Display this help
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z0-9_-]+:.*##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
##@ Code Generation
# OpenAPI configuration - download schema from hyperfleet-api
OPENAPI_SPEC_REF ?= main
OPENAPI_SPEC_URL ?= https://raw.githubusercontent.com/openshift-hyperfleet/hyperfleet-api/$(OPENAPI_SPEC_REF)/openapi/openapi.yaml
.PHONY: generate
generate: $(OAPI_CODEGEN) ## Generate API client code from OpenAPI schema
@echo "Downloading OpenAPI schema from $(OPENAPI_SPEC_REF)..."
@mkdir -p openapi
@curl -fsSL $(OPENAPI_SPEC_URL) -o openapi/openapi.yaml || { \
echo "Error: Failed to download OpenAPI schema from $(OPENAPI_SPEC_URL)"; \
exit 1; \
}
@echo "Generating API client from OpenAPI schema..."
@mkdir -p pkg/api/openapi
$(OAPI_CODEGEN) --config openapi/oapi-codegen.yaml openapi/openapi.yaml
@echo "✓ API client code generated in pkg/api/openapi/"
##@ Development
.PHONY: build
build: generate ## Build the hyperfleet-e2e binary
@mkdir -p $(BIN_DIR)
CGO_ENABLED=0 $(GO) build -ldflags "$(LDFLAGS)" -o $(BINARY_NAME) ./cmd/hyperfleet-e2e
.PHONY: install
install: ## Build and install binary to GOPATH/bin
$(GO) install -ldflags "$(LDFLAGS)" ./cmd/hyperfleet-e2e
.PHONY: run
run: build ## Build and run with help
./$(BINARY_NAME) --help
.PHONY: clean
clean: ## Remove build artifacts
rm -rf $(BIN_DIR)
rm -rf $(OUTPUT_DIR)
rm -f openapi/openapi.yaml
rm -rf pkg/api/openapi
rm -f coverage.out coverage.html
##@ Testing
.PHONY: test
test: generate ## Run unit tests
$(GO) test -v -race -cover -coverprofile=coverage.out ./pkg/...
.PHONY: test-coverage
test-coverage: test ## Run tests and generate HTML coverage report
$(GO) tool cover -html=coverage.out -o coverage.html
.PHONY: e2e
e2e: build ## Run all E2E tests
./$(BINARY_NAME) test
.PHONY: e2e-ci
e2e-ci: build ## Run E2E tests with CI configuration
mkdir -p $(OUTPUT_DIR)
./$(BINARY_NAME) test --configs ci --junit-report $(OUTPUT_DIR)/junit.xml
##@ Code Quality
.PHONY: fmt
fmt: ## Format Go code
$(GOFMT) -s -w .
.PHONY: fmt-check
fmt-check: ## Check if code is formatted
@diff=$$($(GOFMT) -s -d .); \
if [ -n "$$diff" ]; then \
echo "Code is not formatted. Run 'make fmt' to fix:"; \
echo "$$diff"; \
exit 1; \
fi
.PHONY: vet
vet: generate ## Run go vet
$(GO) vet ./...
.PHONY: lint
lint: generate $(GOLANGCI_LINT) ## Run golangci-lint
$(GOLANGCI_LINT) run
.PHONY: verify
verify: generate fmt-check vet ## Run all verification checks
.PHONY: check
check: verify lint test ## Run all checks (fmt, vet, lint, test)
##@ Container Images
.PHONY: image
image: ## Build container image with configurable registry/tag
@echo "Building image $(IMAGE_REGISTRY)/$(IMAGE_NAME):$(IMAGE_TAG) ..."
$(CONTAINER_TOOL) build \
--platform linux/amd64 \
--build-arg GIT_COMMIT=$(GIT_COMMIT) \
-t $(IMAGE_REGISTRY)/$(IMAGE_NAME):$(IMAGE_TAG) .
@echo "Image built: $(IMAGE_REGISTRY)/$(IMAGE_NAME):$(IMAGE_TAG)"
.PHONY: image-push
image-push: image ## Build and push container image
@echo "Pushing image $(IMAGE_REGISTRY)/$(IMAGE_NAME):$(IMAGE_TAG) ..."
$(CONTAINER_TOOL) push $(IMAGE_REGISTRY)/$(IMAGE_NAME):$(IMAGE_TAG)
@echo "Image pushed: $(IMAGE_REGISTRY)/$(IMAGE_NAME):$(IMAGE_TAG)"
.PHONY: image-dev
image-dev: ## Build and push to personal Quay registry (requires QUAY_USER)
ifndef QUAY_USER
@echo "Error: QUAY_USER is not set"
@echo ""
@echo "Usage: QUAY_USER=myuser make image-dev"
@echo ""
@echo "This will build and push to: quay.io/\$$QUAY_USER/$(IMAGE_NAME):$(DEV_TAG)"
@exit 1
endif
@echo "Building dev image quay.io/$(QUAY_USER)/$(IMAGE_NAME):$(DEV_TAG) ..."
$(CONTAINER_TOOL) build \
--platform linux/amd64 \
--build-arg GIT_COMMIT=$(GIT_COMMIT) \
-t quay.io/$(QUAY_USER)/$(IMAGE_NAME):$(DEV_TAG) .
@echo "Pushing dev image..."
$(CONTAINER_TOOL) push quay.io/$(QUAY_USER)/$(IMAGE_NAME):$(DEV_TAG)
@echo ""
@echo "Dev image pushed: quay.io/$(QUAY_USER)/$(IMAGE_NAME):$(DEV_TAG)"