-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
148 lines (128 loc) · 7.93 KB
/
Makefile
File metadata and controls
148 lines (128 loc) · 7.93 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
.PHONY: build build-dev build-release clean test
# Default build (development version)
build:
go build -o kgrep
# Development build with "dev" version
build-dev:
go build -ldflags "-X github.com/hbelmiro/kgrep/cmd.Version=dev -X github.com/hbelmiro/kgrep/cmd.BuildTime=$(shell date -u '+%Y-%m-%d_%H:%M:%S') -X github.com/hbelmiro/kgrep/cmd.CommitHash=$(shell git rev-parse --short HEAD 2>/dev/null || echo 'unknown')" -o kgrep
# Release build with git tag version
build-release:
@if [ -z "$(VERSION)" ]; then \
echo "Error: VERSION is required. Usage: make build-release VERSION=1.0.0"; \
exit 1; \
fi
go build -ldflags "-X github.com/hbelmiro/kgrep/cmd.Version=$(VERSION) -X github.com/hbelmiro/kgrep/cmd.BuildTime=$(shell date -u '+%Y-%m-%d_%H:%M:%S') -X github.com/hbelmiro/kgrep/cmd.CommitHash=$(shell git rev-parse --short HEAD 2>/dev/null || echo 'unknown')" -o kgrep
# Build with git describe (includes dirty state)
build-git:
go build -ldflags "-X github.com/hbelmiro/kgrep/cmd.Version=$(shell git describe --tags --always --dirty 2>/dev/null || echo 'dev') -X github.com/hbelmiro/kgrep/cmd.BuildTime=$(shell date -u '+%Y-%m-%d_%H:%M:%S') -X github.com/hbelmiro/kgrep/cmd.CommitHash=$(shell git rev-parse --short HEAD 2>/dev/null || echo 'unknown')" -o kgrep
# Release build based on latest Git tag
build-tag:
@LATEST_TAG=$$(git describe --tags --abbrev=0 2>/dev/null || echo "no-tags"); \
if [ "$$LATEST_TAG" = "no-tags" ]; then \
echo "Error: No Git tags found. Create a tag first: git tag v1.0.0"; \
exit 1; \
fi; \
echo "Building release version: $$LATEST_TAG"; \
go build -ldflags "-X github.com/hbelmiro/kgrep/cmd.Version=$$LATEST_TAG -X github.com/hbelmiro/kgrep/cmd.BuildTime=$(shell date -u '+%Y-%m-%d_%H:%M:%S') -X github.com/hbelmiro/kgrep/cmd.CommitHash=$(shell git rev-parse --short HEAD 2>/dev/null || echo 'unknown')" -o kgrep
# Build for specific tag
build-tag-version:
@if [ -z "$(TAG)" ]; then \
echo "Error: TAG is required. Usage: make build-tag-version TAG=v1.0.0"; \
exit 1; \
fi; \
echo "Building version: $(TAG)"; \
go build -ldflags "-X github.com/hbelmiro/kgrep/cmd.Version=$(TAG) -X github.com/hbelmiro/kgrep/cmd.BuildTime=$(shell date -u '+%Y-%m-%d_%H:%M:%S') -X github.com/hbelmiro/kgrep/cmd.CommitHash=$(shell git rev-parse --short HEAD 2>/dev/null || echo 'unknown')" -o kgrep
# Cross-compilation targets for specific tag
build-tag-version-linux-amd64:
@if [ -z "$(TAG)" ]; then \
echo "Error: TAG is required. Usage: make build-tag-version-linux-amd64 TAG=v1.0.0"; \
exit 1; \
fi; \
echo "Building Linux amd64 version: $(TAG)"; \
GOOS=linux GOARCH=amd64 go build -ldflags "-X github.com/hbelmiro/kgrep/cmd.Version=$(TAG) -X github.com/hbelmiro/kgrep/cmd.BuildTime=$(shell date -u '+%Y-%m-%d_%H:%M:%S') -X github.com/hbelmiro/kgrep/cmd.CommitHash=$(shell git rev-parse --short HEAD 2>/dev/null || echo 'unknown')" -o kgrep-amd64
build-tag-version-linux-arm64:
@if [ -z "$(TAG)" ]; then \
echo "Error: TAG is required. Usage: make build-tag-version-linux-arm64 TAG=v1.0.0"; \
exit 1; \
fi; \
echo "Building Linux arm64 version: $(TAG)"; \
GOOS=linux GOARCH=arm64 go build -ldflags "-X github.com/hbelmiro/kgrep/cmd.Version=$(TAG) -X github.com/hbelmiro/kgrep/cmd.BuildTime=$(shell date -u '+%Y-%m-%d_%H:%M:%S') -X github.com/hbelmiro/kgrep/cmd.CommitHash=$(shell git rev-parse --short HEAD 2>/dev/null || echo 'unknown')" -o kgrep-arm64
build-tag-version-windows-amd64:
@if [ -z "$(TAG)" ]; then \
echo "Error: TAG is required. Usage: make build-tag-version-windows-amd64 TAG=v1.0.0"; \
exit 1; \
fi; \
echo "Building Windows amd64 version: $(TAG)"; \
GOOS=windows GOARCH=amd64 go build -ldflags "-X github.com/hbelmiro/kgrep/cmd.Version=$(TAG) -X github.com/hbelmiro/kgrep/cmd.BuildTime=$(shell date -u '+%Y-%m-%d_%H:%M:%S') -X github.com/hbelmiro/kgrep/cmd.CommitHash=$(shell git rev-parse --short HEAD 2>/dev/null || echo 'unknown')" -o kgrep-amd64.exe
build-tag-version-windows-arm64:
@if [ -z "$(TAG)" ]; then \
echo "Error: TAG is required. Usage: make build-tag-version-windows-arm64 TAG=v1.0.0"; \
exit 1; \
fi; \
echo "Building Windows arm64 version: $(TAG)"; \
GOOS=windows GOARCH=arm64 go build -ldflags "-X github.com/hbelmiro/kgrep/cmd.Version=$(TAG) -X github.com/hbelmiro/kgrep/cmd.BuildTime=$(shell date -u '+%Y-%m-%d_%H:%M:%S') -X github.com/hbelmiro/kgrep/cmd.CommitHash=$(shell git rev-parse --short HEAD 2>/dev/null || echo 'unknown')" -o kgrep-arm64.exe
build-tag-version-darwin-amd64:
@if [ -z "$(TAG)" ]; then \
echo "Error: TAG is required. Usage: make build-tag-version-darwin-amd64 TAG=v1.0.0"; \
exit 1; \
fi; \
echo "Building macOS amd64 version: $(TAG)"; \
GOOS=darwin GOARCH=amd64 go build -ldflags "-X github.com/hbelmiro/kgrep/cmd.Version=$(TAG) -X github.com/hbelmiro/kgrep/cmd.BuildTime=$(shell date -u '+%Y-%m-%d_%H:%M:%S') -X github.com/hbelmiro/kgrep/cmd.CommitHash=$(shell git rev-parse --short HEAD 2>/dev/null || echo 'unknown')" -o kgrep-amd64
build-tag-version-darwin-arm64:
@if [ -z "$(TAG)" ]; then \
echo "Error: TAG is required. Usage: make build-tag-version-darwin-arm64 TAG=v1.0.0"; \
exit 1; \
fi; \
echo "Building macOS arm64 version: $(TAG)"; \
GOOS=darwin GOARCH=arm64 go build -ldflags "-X github.com/hbelmiro/kgrep/cmd.Version=$(TAG) -X github.com/hbelmiro/kgrep/cmd.BuildTime=$(shell date -u '+%Y-%m-%d_%H:%M:%S') -X github.com/hbelmiro/kgrep/cmd.CommitHash=$(shell git rev-parse --short HEAD 2>/dev/null || echo 'unknown')" -o kgrep-arm64
# Create a new tag and build release
tag-and-build:
@if [ -z "$(VERSION)" ]; then \
echo "Error: VERSION is required. Usage: make tag-and-build VERSION=1.0.0"; \
exit 1; \
fi; \
echo "Creating tag v$(VERSION)..."; \
git tag v$(VERSION); \
echo "Building release version v$(VERSION)..."; \
go build -ldflags "-X github.com/hbelmiro/kgrep/cmd.Version=v$(VERSION) -X github.com/hbelmiro/kgrep/cmd.BuildTime=$(shell date -u '+%Y-%m-%d_%H:%M:%S') -X github.com/hbelmiro/kgrep/cmd.CommitHash=$(shell git rev-parse --short HEAD 2>/dev/null || echo 'unknown')" -o kgrep; \
echo "Release built successfully! Don't forget to push the tag: git push origin v$(VERSION)"
# List all available tags
list-tags:
@echo "Available tags:"; \
git tag --sort=-version:refname | head -10
# Clean build artifacts
clean:
rm -f kgrep kgrep-amd64 kgrep-arm64 kgrep.exe kgrep-amd64.exe kgrep-arm64.exe
# Run tests
test:
go test ./...
# Run integration tests (requires a running Kubernetes cluster)
test-integration:
@echo "Running integration tests..."
@echo "Make sure you have a running Kubernetes cluster accessible via kubectl"
cd test/integration && KGREP_INTEGRATION_TESTS=true go test -v -timeout=10m ./...
# Run integration tests with kind (creates a local cluster)
test-integration-kind:
@echo "Setting up kind cluster for integration tests..."
@if ! command -v kind > /dev/null 2>&1; then \
echo "Error: kind is not installed. Please install it first: https://kind.sigs.k8s.io/docs/user/quick-start/#installation"; \
exit 1; \
fi
@if ! command -v kubectl > /dev/null 2>&1; then \
echo "Error: kubectl is not installed. Please install it first: https://kubernetes.io/docs/tasks/tools/install-kubectl/"; \
exit 1; \
fi
@echo "Creating kind cluster..."
kind create cluster --name kgrep-integration-test --image kindest/node:v1.31.0 || true
@echo "Waiting for cluster to be ready..."
kubectl wait --for=condition=Ready nodes --all --timeout=300s
@echo "Running integration tests..."
cd test/integration && KGREP_INTEGRATION_TESTS=true go test -v -timeout=10m ./...
@echo "Cleaning up kind cluster..."
kind delete cluster --name kgrep-integration-test || true
# Install development version
install-dev:
go install -ldflags "-X github.com/hbelmiro/kgrep/cmd.Version=dev -X github.com/hbelmiro/kgrep/cmd.BuildTime=$(shell date -u '+%Y-%m-%d_%H:%M:%S') -X github.com/hbelmiro/kgrep/cmd.CommitHash=$(shell git rev-parse --short HEAD 2>/dev/null || echo 'unknown')"
# Show current version
version:
@echo "Current version: $(shell ./kgrep version 2>/dev/null || echo 'not built')"