-
Notifications
You must be signed in to change notification settings - Fork 683
Expand file tree
/
Copy pathmakefile
More file actions
164 lines (134 loc) · 5.28 KB
/
makefile
File metadata and controls
164 lines (134 loc) · 5.28 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
# Makefile for kubectl-ai
#
# This Makefile provides a set of commands to build, test, run,
# and manage the kubectl-ai project.
# Default target to run when no target is specified.
.DEFAULT_GOAL := help
# --- Variables ---
# Define common variables to avoid repetition and ease maintenance.
BIN_DIR := ./bin
CMD_DIR := ./cmd
BINARY_NAME := kubectl-ai
BINARY_PATH := $(BIN_DIR)/$(BINARY_NAME)
# Attempt to determine GOPATH/bin for installation.
# Fallback to a common default if `go env GOPATH` fails or is empty.
GOPATH_BIN := $(shell go env GOPATH)/bin
ifeq ($(GOPATH_BIN),/bin)
GOPATH_BIN := $(HOME)/go/bin
endif
# --- Environment Variables from .env ---
# If a .env file exists, include it. This makes variables defined in .env
# (e.g., API_KEY=123) available as Make variables.
# Then, export these variables so they are available in the environment
# for shell commands executed by Make recipes.
ifneq ($(wildcard .env),)
include .env
# Extract variable names from .env and export them.
# This assumes .env contains lines like VAR=value.
ENV_VARS_TO_EXPORT := $(shell awk -F= '{print $$1}' .env | xargs)
export $(ENV_VARS_TO_EXPORT)
endif
# --- Help Target ---
# Displays a list of available targets and their descriptions.
# Descriptions are extracted from comments following '##'.
help:
@echo "kubectl-ai Makefile"
@echo "-------------------"
@echo "Available targets:"
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z0-9_-]+:.*?## / {printf " %-20s %s\n", $$1, $$2}' $(MAKEFILE_LIST)
# --- Build Tasks ---
build-recursive: ## Build the binary using dev script (recursive for all modules)
@echo "λ Building all modules (recursive using dev script)..."
mkdir -p $(BIN_DIR)
./dev/ci/presubmits/go-build.sh
build: ## Build single binary for the current platform
@echo "λ Building $(BINARY_NAME) for current platform..."
mkdir -p $(BIN_DIR)
go build -o $(BINARY_PATH) $(CMD_DIR)
# --- Run Tasks ---
run: ## Run the application
@echo "λ Running $(BINARY_NAME) from source..."
go run $(CMD_DIR)
run-html: ## Run with HTML UI
@echo "λ Running $(BINARY_NAME) with HTML UI from source..."
go run $(CMD_DIR) --ui-type web
# --- Code Quality Tasks (using dev scripts) ---
fmt: ## Format code using dev script
@echo "λ Formatting code (using dev script)..."
./dev/tasks/format.sh
vet: ## Run go vet using dev script
@echo "λ Running go vet (using dev script)..."
./dev/ci/presubmits/go-vet.sh
tidy: ## Tidy go modules using dev script
@echo "λ Tidying go modules (using dev script)..."
./dev/tasks/gomod.sh
# --- Verification Tasks (CI-style checks using dev scripts) ---
verify-format: ## Verify code formatting
@echo "λ Verifying code formatting..."
./dev/ci/presubmits/verify-format.sh
verify-gomod: ## Verify go.mod files are tidy
@echo "λ Verifying go.mod files..."
./dev/ci/presubmits/verify-gomod.sh
verify-autogen: ## Verify auto-generated files are up to date
@echo "λ Verifying auto-generated files..."
./dev/ci/presubmits/verify-autogen.sh
generate:
go generate ./internal/mocks
verify-mocks:
@echo "λ Verifying mocks..."
./dev/ci/presubmits/verify-mocks.sh
# --- Generation Tasks ---
generate-actions: ## Generate GitHub Actions workflows
@echo "λ Generating GitHub Actions workflows..."
./dev/tasks/generate-github-actions.sh
# --- Evaluation Tasks ---
run-evals: ## Run evaluations (periodic task)
@echo "λ Running evaluations..."
./dev/ci/periodics/run-evals.sh
analyze-evals: ## Analyze evaluations (periodic task)
@echo "λ Analyzing evaluations..."
./dev/ci/periodics/analyze-evals.sh $(ARGS)
# --- Combined Tasks ---
# 'check' depends on other verification tasks. They will run as prerequisites.
check: verify-format verify-gomod verify-autogen build-recursive vet ## Run all verification checks (presubmit-style)
@echo "λ All checks completed."
# --- Development Workflow ---
# 'dev' and 'dev-html' depend on the 'build' target.
dev: build ## Development mode - build and run
@echo "λ Starting $(BINARY_NAME) in dev mode..."
$(BINARY_PATH)
dev-html: build ## Development mode - build and run with HTML UI
@echo "λ Starting $(BINARY_NAME) with HTML UI in dev mode..."
$(BINARY_PATH) --ui-type web
# --- Maintenance Tasks ---
clean: ## Clean build artifacts and coverage files
@echo "λ Cleaning build artifacts..."
rm -rf $(BIN_DIR)
rm -f coverage.out coverage.html
deps: ## Download Go module dependencies
@echo "λ Downloading Go module dependencies..."
go mod download
update-deps: ## Update Go module dependencies and then tidy
@echo "λ Updating Go module dependencies..."
go get -u ./...
@echo "λ Tidying modules after update..."
$(MAKE) tidy
# --- Installation ---
# 'install' depends on the 'build' target.
install: build ## Install the binary to $(GOPATH_BIN)
@echo "λ Installing $(BINARY_NAME) to $(GOPATH_BIN)..."
cp $(BINARY_PATH) $(GOPATH_BIN)/
@echo "$(BINARY_NAME) installed."
# --- Testing ---
test: ## Run tests
@echo "λ Running tests..."
go test ./...
test-verbose: ## Run tests with verbose output
@echo "λ Running tests (verbose)..."
go test -v ./...
test-coverage: ## Run tests with coverage and generate HTML report
@echo "λ Running tests with coverage..."
go test -coverprofile=coverage.out ./...
@echo "λ Generating coverage HTML report..."
go tool cover -html=coverage.out -o coverage.html
@echo "Coverage report generated: coverage.html"