Skip to content

Commit a433c69

Browse files
committed
feat: generate Makefile with build, test, generate, and release targets
Adds a Makefile template to the controller generation pipeline so that users can run codegen and release builds directly from the controller repo without switching to the code-generator directory.
1 parent b061ffd commit a433c69

3 files changed

Lines changed: 72 additions & 3 deletions

File tree

pkg/generate/ack/controller.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,11 @@ func Controller(
331331
return nil, err
332332
}
333333

334+
// Add the Makefile template
335+
if err = ts.Add("Makefile", "Makefile.tpl", metaVars); err != nil {
336+
return nil, err
337+
}
338+
334339
// Finally, add the configuration YAML file templates
335340
for _, path := range controllerConfigTemplatePaths {
336341
outPath := strings.TrimSuffix(path, ".tpl")

pkg/sdk/repo.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,12 @@ func EnsureDir(fp string) (bool, error) {
7575
// isDirWriteable returns true if the supplied directory path is writeable,
7676
// false otherwise
7777
func isDirWriteable(fp string) bool {
78-
testPath := filepath.Join(fp, "test")
79-
f, err := os.Create(testPath)
78+
f, err := os.CreateTemp(fp, ".ack-writeable-check-*")
8079
if err != nil {
8180
return false
8281
}
8382
f.Close()
84-
os.Remove(testPath)
83+
os.Remove(f.Name())
8584
return true
8685
}
8786

templates/Makefile.tpl

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Code generated by ack-generate. DO NOT EDIT.
2+
#
3+
# Makefile for the ACK {{ .ServicePackageName }} controller.
4+
# Run 'make help' to see available targets.
5+
6+
SHELL := /bin/bash
7+
8+
SERVICE := {{ .ServicePackageName }}
9+
10+
# Build configuration
11+
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "v0.0.0")
12+
GITCOMMIT = $(shell git rev-parse HEAD)
13+
BUILDDATE = $(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
14+
GO_LDFLAGS = -ldflags "-X main.version=$(VERSION) -X main.buildHash=$(GITCOMMIT) -X main.buildDate=$(BUILDDATE)"
15+
16+
# Code generator — assumes the standard ACK workspace layout (../code-generator)
17+
CODE_GENERATOR_DIR ?= ../code-generator
18+
19+
# Controller runtime configuration
20+
AWS_REGION ?= us-west-2
21+
22+
.PHONY: all build test local-test ensure-codegen generate release run version help
23+
24+
all: test
25+
26+
build: ## Build the controller binary
27+
@go build $(GO_LDFLAGS) -o bin/controller cmd/controller/main.go
28+
29+
test: ## Run unit tests
30+
@go test ./...
31+
32+
local-test: ## Run unit tests using go.local.mod
33+
@go test -modfile=go.local.mod ./...
34+
35+
ensure-codegen:
36+
@if [ ! -d "$(CODE_GENERATOR_DIR)" ]; then \
37+
echo "Error: code-generator not found at $(CODE_GENERATOR_DIR)"; \
38+
echo "Clone it with: git clone https://github.com/aws-controllers-k8s/code-generator $(CODE_GENERATOR_DIR)"; \
39+
exit 1; \
40+
fi
41+
42+
generate: ensure-codegen ## Regenerate controller code from the AWS SDK model
43+
@$(MAKE) --no-print-directory -C $(CODE_GENERATOR_DIR) build-controller SERVICE=$(SERVICE)
44+
45+
release: ensure-codegen ## Generate release artifacts (make release V=v1.2.4)
46+
@[ -n "$(V)" ] || { echo "Error: version is required"; echo "Usage: make release V=v1.2.4"; exit 1; }
47+
@$(MAKE) --no-print-directory -C $(CODE_GENERATOR_DIR) build-ack-generate
48+
@RELEASE_VERSION=$(V) $(CODE_GENERATOR_DIR)/scripts/build-controller-release.sh $(SERVICE)
49+
50+
run: ## Run the controller locally (AWS_REGION=us-west-2)
51+
@go run ./cmd/controller/main.go \
52+
--aws-region=$(AWS_REGION) \
53+
--enable-development-logging \
54+
--log-level=debug
55+
56+
version: ## Print the current version
57+
@echo $(VERSION)
58+
59+
help: ## Show this help
60+
@echo "Usage: make [target]"
61+
@echo ""
62+
@echo "Targets:"
63+
@grep -E '^[a-zA-Z_-]+:.*##' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*##"}; {printf " \033[36m%-15s\033[0m %s\n", $$1, $$2}'
64+
65+
-include Makefile.custom

0 commit comments

Comments
 (0)