Skip to content

Commit ab3c2b9

Browse files
authored
Add Makefile and helper commands (#3)
* Add makefile build helpers, including version bump * Fix fmt issue in version bump make target
1 parent 1e2d782 commit ab3c2b9

1 file changed

Lines changed: 104 additions & 0 deletions

File tree

Makefile

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# rightsizer Makefile
2+
3+
# Variables
4+
BINARY_NAME := rightsizer
5+
DOCKER_IMAGE := nextroll/rightsizer
6+
GO_FILES := $(shell find . -name '*.go' -type f)
7+
8+
# Default target
9+
.PHONY: all
10+
all: build
11+
12+
# Build the binary
13+
.PHONY: build
14+
build:
15+
go build -o $(BINARY_NAME) .
16+
17+
# Generate mocks
18+
.PHONY: generate
19+
generate:
20+
go generate ./...
21+
22+
# Run tests
23+
.PHONY: test
24+
test: generate
25+
go test ./...
26+
27+
# Clean build artifacts
28+
.PHONY: clean
29+
clean:
30+
rm -f $(BINARY_NAME)
31+
32+
# Build Docker image
33+
.PHONY: docker-build
34+
docker-build:
35+
docker build -t $(DOCKER_IMAGE) .
36+
37+
# Run with Docker
38+
.PHONY: docker-run
39+
docker-run:
40+
docker run --rm $(DOCKER_IMAGE) $(BINARY_NAME) $(ARGS)
41+
42+
# Install dependencies
43+
.PHONY: deps
44+
deps:
45+
go mod download
46+
go mod tidy
47+
48+
# Format code
49+
.PHONY: fmt
50+
fmt:
51+
go fmt ./...
52+
53+
# Vet code
54+
.PHONY: vet
55+
vet:
56+
go vet ./...
57+
58+
# Run linter (requires golangci-lint)
59+
.PHONY: lint
60+
lint:
61+
golangci-lint run
62+
63+
# Full check: format, vet, generate, test
64+
.PHONY: check
65+
check: fmt vet generate test
66+
67+
# Bump version
68+
.PHONY: version-bump
69+
version-bump:
70+
@if [ -z "$(VERSION)" ]; then \
71+
echo "Usage: make version-bump VERSION=x.y.z"; \
72+
exit 1; \
73+
fi
74+
@echo "Bumping version to $(VERSION)..."
75+
@sed -i '' 's/Version:.*"[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*"/Version: "$(VERSION)"/' main.go
76+
@echo "Version updated to $(VERSION) in main.go"
77+
@# Extract major and minor versions for workflow tags
78+
@MAJOR=$$(echo $(VERSION) | cut -d. -f1); \
79+
MINOR=$$(echo $(VERSION) | cut -d. -f2); \
80+
sed -i '' "s/nextroll\/rightsizer:v[0-9][0-9]*/nextroll\/rightsizer:v$$MAJOR/" .github/workflows/ship-version.yml; \
81+
sed -i '' "s/nextroll\/rightsizer:v[0-9][0-9]*\.[0-9][0-9]*/nextroll\/rightsizer:v$$MAJOR.$$MINOR/" .github/workflows/ship-version.yml; \
82+
sed -i '' "s/nextroll\/rightsizer:v[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*/nextroll\/rightsizer:v$(VERSION)/" .github/workflows/ship-version.yml
83+
@echo "Running go fmt..."
84+
go fmt ./...
85+
@echo "Version updated to $(VERSION) in .github/workflows/ship-version.yml"
86+
87+
88+
# Help
89+
.PHONY: help
90+
help:
91+
@echo "Available targets:"
92+
@echo " build - Build the rightsizer binary"
93+
@echo " generate - Generate mocks using go generate"
94+
@echo " test - Run tests (generates mocks first)"
95+
@echo " clean - Remove build artifacts"
96+
@echo " docker-build - Build Docker image"
97+
@echo " docker-run - Run with Docker (use ARGS='cluster service')"
98+
@echo " deps - Download and tidy Go modules"
99+
@echo " fmt - Format Go code"
100+
@echo " vet - Run go vet"
101+
@echo " lint - Run golangci-lint"
102+
@echo " check - Run fmt, vet, generate, and test"
103+
@echo " version-bump - Bump version (use VERSION=x.y.z)"
104+
@echo " help - Show this help message"

0 commit comments

Comments
 (0)