From 838f73506e687d825ae617f79558aa2b00274773 Mon Sep 17 00:00:00 2001 From: Danny Fowler Date: Fri, 13 Jun 2025 12:23:05 -0700 Subject: [PATCH 1/2] Add makefile build helpers, including version bump --- Makefile | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..c864c94 --- /dev/null +++ b/Makefile @@ -0,0 +1,101 @@ +# rightsizer Makefile + +# Variables +BINARY_NAME := rightsizer +DOCKER_IMAGE := nextroll/rightsizer +GO_FILES := $(shell find . -name '*.go' -type f) + +# Default target +.PHONY: all +all: build + +# Build the binary +.PHONY: build +build: + go build -o $(BINARY_NAME) . + +# Generate mocks +.PHONY: generate +generate: + go generate ./... + +# Run tests +.PHONY: test +test: generate + go test ./... + +# Clean build artifacts +.PHONY: clean +clean: + rm -f $(BINARY_NAME) + +# Build Docker image +.PHONY: docker-build +docker-build: + docker build -t $(DOCKER_IMAGE) . + +# Run with Docker +.PHONY: docker-run +docker-run: + docker run --rm $(DOCKER_IMAGE) $(BINARY_NAME) $(ARGS) + +# Install dependencies +.PHONY: deps +deps: + go mod download + go mod tidy + +# Format code +.PHONY: fmt +fmt: + go fmt ./... + +# Vet code +.PHONY: vet +vet: + go vet ./... + +# Run linter (requires golangci-lint) +.PHONY: lint +lint: + golangci-lint run + +# Full check: format, vet, generate, test +.PHONY: check +check: fmt vet generate test + +# Bump version +.PHONY: version-bump +version-bump: + @if [ -z "$(VERSION)" ]; then \ + echo "Usage: make version-bump VERSION=x.y.z"; \ + exit 1; \ + fi + @echo "Bumping version to $(VERSION)..." + @sed -i '' 's/Version:.*"[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*"/Version: "$(VERSION)"/' main.go + @echo "Version updated to $(VERSION) in main.go" + @# Extract major and minor versions for workflow tags + @MAJOR=$$(echo $(VERSION) | cut -d. -f1); \ + MINOR=$$(echo $(VERSION) | cut -d. -f2); \ + sed -i '' "s/nextroll\/rightsizer:v[0-9][0-9]*/nextroll\/rightsizer:v$$MAJOR/" .github/workflows/ship-version.yml; \ + sed -i '' "s/nextroll\/rightsizer:v[0-9][0-9]*\.[0-9][0-9]*/nextroll\/rightsizer:v$$MAJOR.$$MINOR/" .github/workflows/ship-version.yml; \ + 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 + @echo "Version updated to $(VERSION) in .github/workflows/ship-version.yml" + +# Help +.PHONY: help +help: + @echo "Available targets:" + @echo " build - Build the rightsizer binary" + @echo " generate - Generate mocks using go generate" + @echo " test - Run tests (generates mocks first)" + @echo " clean - Remove build artifacts" + @echo " docker-build - Build Docker image" + @echo " docker-run - Run with Docker (use ARGS='cluster service')" + @echo " deps - Download and tidy Go modules" + @echo " fmt - Format Go code" + @echo " vet - Run go vet" + @echo " lint - Run golangci-lint" + @echo " check - Run fmt, vet, generate, and test" + @echo " version-bump - Bump version (use VERSION=x.y.z)" + @echo " help - Show this help message" From c45c6ec07859f0b2db471eb4de66fcb6cbe82fe3 Mon Sep 17 00:00:00 2001 From: Danny Fowler Date: Fri, 13 Jun 2025 12:29:59 -0700 Subject: [PATCH 2/2] Fix fmt issue in version bump make target --- Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Makefile b/Makefile index c864c94..4d6d2e8 100644 --- a/Makefile +++ b/Makefile @@ -80,7 +80,10 @@ version-bump: sed -i '' "s/nextroll\/rightsizer:v[0-9][0-9]*/nextroll\/rightsizer:v$$MAJOR/" .github/workflows/ship-version.yml; \ sed -i '' "s/nextroll\/rightsizer:v[0-9][0-9]*\.[0-9][0-9]*/nextroll\/rightsizer:v$$MAJOR.$$MINOR/" .github/workflows/ship-version.yml; \ 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 + @echo "Running go fmt..." + go fmt ./... @echo "Version updated to $(VERSION) in .github/workflows/ship-version.yml" + # Help .PHONY: help