Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions .rhiza/make.d/bootstrap-go.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
## .rhiza/make.d/bootstrap-go.mk - Go Bootstrap and Installation
# This file provides Go-specific targets for setting up the development environment,
# installing Go dependencies, building binaries, and related tasks.

# Declare phony targets (they don't produce files)
.PHONY: install-go install build

# Read Go version from .go-version (single source of truth)
GO_VERSION ?= $(shell cat .go-version 2>/dev/null || echo "1.23")
export GO_VERSION

# Go binary location
GO_BIN ?= $(shell command -v go 2>/dev/null || echo "go")

# GOPROXY: primary proxy with direct VCS fallback for transient failures or VPN environments.
# Override with an internal proxy if needed: make install GOPROXY=https://my.proxy.internal,direct
GOPROXY ?= https://proxy.golang.org,direct
export GOPROXY

##@ Bootstrap
install-go: ## ensure Go is installed at the required version
@printf "${BLUE}[INFO] Checking Go installation...${RESET}\n"
@if command -v go >/dev/null 2>&1; then \
INSTALLED_VERSION=$$(go version | awk '{print $$3}' | sed 's/go//'); \
REQUIRED_VERSION=$$(cat .go-version); \
if [ "$$INSTALLED_VERSION" != "$$REQUIRED_VERSION" ]; then \
printf "${YELLOW}[WARN] Go version mismatch: installed=$$INSTALLED_VERSION, required=$$REQUIRED_VERSION${RESET}\n"; \
printf "${YELLOW}[INFO] Please install Go $$REQUIRED_VERSION from https://go.dev/dl/${RESET}\n"; \
else \
printf "${BLUE}[INFO] Go $$INSTALLED_VERSION is installed${RESET}\n"; \
fi; \
else \
printf "${RED}[ERROR] Go is not installed${RESET}\n"; \
printf "${YELLOW}[INFO] Please install Go from https://go.dev/dl/${RESET}\n"; \
exit 1; \
fi

install: pre-install install-go install-uv ## install Go dependencies
@printf "${BLUE}[INFO] Installing Go dependencies...${RESET}\n"

# Download dependencies
@if [ -f "go.mod" ]; then \
$(GO_BIN) mod download || { printf "${RED}[ERROR] Failed to download dependencies${RESET}\n"; exit 1; }; \
$(GO_BIN) mod tidy || { printf "${RED}[ERROR] Failed to tidy dependencies${RESET}\n"; exit 1; }; \
printf "${BLUE}[INFO] Dependencies installed successfully${RESET}\n"; \
else \
printf "${YELLOW}[WARN] No go.mod found, skipping install${RESET}\n"; \
fi

# Install development tools (run outside module dir to avoid go.mod/go.sum interaction)
@printf "${BLUE}[INFO] Installing development tools...${RESET}\n"
@cd /tmp && $(GO_BIN) install github.com/golangci/golangci-lint/cmd/golangci-lint@latest || true
@cd /tmp && $(GO_BIN) install golang.org/x/tools/cmd/goimports@latest || true
@cd /tmp && $(GO_BIN) install golang.org/x/vuln/cmd/govulncheck@latest || true
@cd /tmp && $(GO_BIN) install github.com/securego/gosec/v2/cmd/gosec@latest || true
@cd /tmp && $(GO_BIN) install gotest.tools/gotestsum@latest || true
@cd /tmp && $(GO_BIN) install github.com/princjef/gomarkdoc/cmd/gomarkdoc@latest || true
@cd /tmp && $(GO_BIN) install github.com/goreleaser/goreleaser/v2@latest || true
@curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh | sh -s -- -b "$$($(GO_BIN) env GOPATH)/bin" || true

# Install pre-commit hooks if config exists (uses uvx, installed above)
@if [ -f .pre-commit-config.yaml ]; then \
printf "${BLUE}[INFO] Installing pre-commit hooks...${RESET}\n"; \
$(UVX_BIN) pre-commit install; \
fi

@$(MAKE) post-install

build: install ## build Go binaries
@printf "${BLUE}[INFO] Building Go binaries...${RESET}\n"
@$(GO_BIN) build -v ./...
@mkdir -p bin
@$(GO_BIN) build -o bin/ ./cmd/...
@printf "${GREEN}[PASS] Binaries built to bin/${RESET}\n"
74 changes: 3 additions & 71 deletions .rhiza/make.d/bootstrap.mk
Original file line number Diff line number Diff line change
@@ -1,26 +1,15 @@
## .rhiza/make.d/bootstrap.mk - Bootstrap and Installation
# This file provides targets for setting up the development environment,
# This file provides non-Go targets for setting up the development environment,
# installing dependencies, and cleaning project artifacts.
# Go-specific targets (install-go, install, build) are in bootstrap-go.mk.

# Declare phony targets (they don't produce files)
.PHONY: install-go install-uv install build clean pre-install post-install
.PHONY: install-uv clean pre-install post-install

# Hook targets (double-colon rules allow multiple definitions)
pre-install:: ; @:
post-install:: ; @:

# Read Go version from .go-version (single source of truth)
GO_VERSION ?= $(shell cat .go-version 2>/dev/null || echo "1.23")
export GO_VERSION

# Go binary location
GO_BIN ?= $(shell command -v go 2>/dev/null || echo "go")

# GOPROXY: primary proxy with direct VCS fallback for transient failures or VPN environments.
# Override with an internal proxy if needed: make install GOPROXY=https://my.proxy.internal,direct
GOPROXY ?= https://proxy.golang.org,direct
export GOPROXY

##@ Bootstrap
install-uv: ## ensure uv/uvx is installed
# Ensure the ${INSTALL_DIR} folder exists
Expand All @@ -39,63 +28,6 @@ install-uv: ## ensure uv/uvx is installed
fi; \
fi


##@ Bootstrap
install-go: ## ensure Go is installed at the required version
@printf "${BLUE}[INFO] Checking Go installation...${RESET}\n"
@if command -v go >/dev/null 2>&1; then \
INSTALLED_VERSION=$$(go version | awk '{print $$3}' | sed 's/go//'); \
REQUIRED_VERSION=$$(cat .go-version); \
if [ "$$INSTALLED_VERSION" != "$$REQUIRED_VERSION" ]; then \
printf "${YELLOW}[WARN] Go version mismatch: installed=$$INSTALLED_VERSION, required=$$REQUIRED_VERSION${RESET}\n"; \
printf "${YELLOW}[INFO] Please install Go $$REQUIRED_VERSION from https://go.dev/dl/${RESET}\n"; \
else \
printf "${BLUE}[INFO] Go $$INSTALLED_VERSION is installed${RESET}\n"; \
fi; \
else \
printf "${RED}[ERROR] Go is not installed${RESET}\n"; \
printf "${YELLOW}[INFO] Please install Go from https://go.dev/dl/${RESET}\n"; \
exit 1; \
fi

install: pre-install install-go install-uv ## install Go dependencies
@printf "${BLUE}[INFO] Installing Go dependencies...${RESET}\n"

# Download dependencies
@if [ -f "go.mod" ]; then \
$(GO_BIN) mod download || { printf "${RED}[ERROR] Failed to download dependencies${RESET}\n"; exit 1; }; \
$(GO_BIN) mod tidy || { printf "${RED}[ERROR] Failed to tidy dependencies${RESET}\n"; exit 1; }; \
printf "${BLUE}[INFO] Dependencies installed successfully${RESET}\n"; \
else \
printf "${YELLOW}[WARN] No go.mod found, skipping install${RESET}\n"; \
fi

# Install development tools (run outside module dir to avoid go.mod/go.sum interaction)
@printf "${BLUE}[INFO] Installing development tools...${RESET}\n"
@cd /tmp && $(GO_BIN) install github.com/golangci/golangci-lint/cmd/golangci-lint@latest || true
@cd /tmp && $(GO_BIN) install golang.org/x/tools/cmd/goimports@latest || true
@cd /tmp && $(GO_BIN) install golang.org/x/vuln/cmd/govulncheck@latest || true
@cd /tmp && $(GO_BIN) install github.com/securego/gosec/v2/cmd/gosec@latest || true
@cd /tmp && $(GO_BIN) install gotest.tools/gotestsum@latest || true
@cd /tmp && $(GO_BIN) install github.com/princjef/gomarkdoc/cmd/gomarkdoc@latest || true
@cd /tmp && $(GO_BIN) install github.com/goreleaser/goreleaser/v2@latest || true
@curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh | sh -s -- -b "$$($(GO_BIN) env GOPATH)/bin" || true

# Install pre-commit hooks if config exists (uses uvx, installed above)
@if [ -f .pre-commit-config.yaml ]; then \
printf "${BLUE}[INFO] Installing pre-commit hooks...${RESET}\n"; \
$(UVX_BIN) pre-commit install; \
fi

@$(MAKE) post-install

build: install ## build Go binaries
@printf "${BLUE}[INFO] Building Go binaries...${RESET}\n"
@$(GO_BIN) build -v ./...
@mkdir -p bin
@$(GO_BIN) build -o bin/ ./cmd/...
@printf "${GREEN}[PASS] Binaries built to bin/${RESET}\n"

clean: ## Clean project artifacts and stale local branches
@printf "%bCleaning project...%b\n" "$(BLUE)" "$(RESET)"

Expand Down
1 change: 1 addition & 0 deletions .rhiza/rhiza.mk
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export RHIZA_LOGO

# Hook targets (double-colon rules allow multiple definitions)
# Note: pre-install/post-install are defined in bootstrap.mk
# Note: install-go/install/build are defined in bootstrap-go.mk
# Note: pre-bump/post-bump/pre-release/post-release are defined in releasing.mk
pre-sync:: ; @:
post-sync:: ; @:
Expand Down
1 change: 1 addition & 0 deletions .rhiza/template-bundles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ bundles:
- .rhiza/make.d/quality.mk
- .rhiza/make.d/security.mk
- .rhiza/make.d/bootstrap.mk
- .rhiza/make.d/bootstrap-go.mk
- .rhiza/make.d/releasing.mk
- .rhiza/make.d/README.md
- .rhiza/docs
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ rhiza-go/
├── .rhiza/ # Rhiza-specific scripts and configurations
│ ├── make.d/ # Modular Makefile components
│ │ ├── bootstrap.mk
│ │ ├── bootstrap-go.mk
│ │ ├── test.mk
│ │ ├── quality.mk
│ │ └── docs.mk
Expand Down
4 changes: 2 additions & 2 deletions docs/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ flowchart TD

| Target | Extension | What it does |
|--------|-----------|-------------|
| `make install` | `bootstrap.mk` | Verify Go version, `go mod download`, install tools |
| `make build` | `bootstrap.mk` | `go build` to `bin/` |
| `make install` | `bootstrap-go.mk` | Verify Go version, `go mod download`, install tools |
| `make build` | `bootstrap-go.mk` | `go build` to `bin/` |
| `make test` | `test.mk` | `go test -race -cover ./...` with reports |
| `make fmt` | `quality.mk` | `go fmt`, `goimports`, `golangci-lint --fix` |
| `make lint` | `quality.mk` | `golangci-lint run` (25+ linters via `.golangci.yml`) |
Expand Down