From ef126eaf61f6ce50325529820e96a1c21c414bfc Mon Sep 17 00:00:00 2001 From: jb Date: Fri, 19 Jun 2026 14:57:05 -0300 Subject: [PATCH] feat: add build-stamped version with --version flag and TUI header Introduce tui.Version (defaults to "dev"), stamped at build time via a VERSION_LDFLAG in the Makefile (-X .../internal/tui.Version=$(VERSION)) across all build targets. main.go handles "--version"/"-v" before launching the TUI, and the version is shown next to the title in the header. Docs updated (README + CLAUDE). Co-Authored-By: Claude Opus 4.8 --- CLAUDE.md | 8 ++++++++ Makefile | 15 +++++++++------ README.md | 9 +++++++++ cmd/main.go | 8 ++++++++ internal/tui/version.go | 6 ++++++ internal/tui/view.go | 4 +++- 6 files changed, 43 insertions(+), 7 deletions(-) create mode 100644 internal/tui/version.go diff --git a/CLAUDE.md b/CLAUDE.md index e8aa0c7..b2be3d8 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -145,6 +145,14 @@ make push S3_BUCKET= VERSION= # sync dist/ to S3 (version + late make release S3_BUCKET= VERSION= # per-binary copy with OS/arch naming ``` +**Versioning:** `tui.Version` ([internal/tui/version.go](internal/tui/version.go)) +defaults to `"dev"` and is stamped at build time via `VERSION_LDFLAG` +(`-X .../internal/tui.Version=$(VERSION)`) in the Makefile. `installer --version` +(or `-v`) prints it and exits before the TUI starts; it is also shown in the TUI +header. A plain `go build` leaves it as `"dev"`. The Makefile build rules have no +source deps, so `make build` will not rebuild existing `dist/` artifacts — run +`make clean` first when re-stamping a new VERSION. + Tests (`go test ./...`) cover the pure logic in [config_test.go](internal/tui/config_test.go) (config.toml/envs generation + numeric validation) and [form_test.go](internal/tui/form_test.go) (`FormStep.Values()`). The diff --git a/Makefile b/Makefile index 0cd2440..29168dd 100644 --- a/Makefile +++ b/Makefile @@ -1,33 +1,36 @@ .PHONY: build clean push release help VERSION ?= 1.0.0 -S3_BUCKET ?= +S3_BUCKET ?= BINARY_NAME ?= installer BUILD_DIR := ./dist +MODULE := git.davinti.com.br/davinTI/app-dono/tui +VERSION_LDFLAG := -X $(MODULE)/internal/tui.Version=$(VERSION) + ARCHS := linux/amd64 linux/arm64 darwin/amd64 darwin/arm64 windows/amd64 build: $(addprefix $(BUILD_DIR)/$(BINARY_NAME)-, $(subst /,-,$(ARCHS))) $(BUILD_DIR)/$(BINARY_NAME)-linux-amd64: @mkdir -p $(BUILD_DIR) - CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-extldflags -static" -o $@ ./cmd + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-extldflags -static $(VERSION_LDFLAG)" -o $@ ./cmd $(BUILD_DIR)/$(BINARY_NAME)-linux-arm64: @mkdir -p $(BUILD_DIR) - CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags="-extldflags -static" -o $@ ./cmd + CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags="-extldflags -static $(VERSION_LDFLAG)" -o $@ ./cmd $(BUILD_DIR)/$(BINARY_NAME)-darwin-amd64: @mkdir -p $(BUILD_DIR) - CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o $@ ./cmd + CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags="$(VERSION_LDFLAG)" -o $@ ./cmd $(BUILD_DIR)/$(BINARY_NAME)-darwin-arm64: @mkdir -p $(BUILD_DIR) - CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -o $@ ./cmd + CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -ldflags="$(VERSION_LDFLAG)" -o $@ ./cmd $(BUILD_DIR)/$(BINARY_NAME)-windows-amd64: @mkdir -p $(BUILD_DIR) - CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o $@ ./cmd + CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags="$(VERSION_LDFLAG)" -o $@ ./cmd clean: rm -rf $(BUILD_DIR) diff --git a/README.md b/README.md index a02a3f1..71c8974 100644 --- a/README.md +++ b/README.md @@ -200,6 +200,15 @@ go build -o installer ./cmd ./installer ``` +A versão é gravada no binário em tempo de build (`make build VERSION=1.2.0`) e pode ser +consultada sem abrir a interface: + +```bash +./installer --version # ex.: app-dono installer 1.2.0 +``` + +Um `go build` simples (sem o `Makefile`) deixa a versão como `dev`. + ## Documentação adicional - [docs/fluxo.md](docs/fluxo.md) — detalhamento de cada etapa do assistente. diff --git a/cmd/main.go b/cmd/main.go index 0bfc5e3..f10efcf 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -9,6 +9,14 @@ import ( ) func main() { + if len(os.Args) > 1 { + switch os.Args[1] { + case "--version", "-v": + fmt.Println("app-dono installer", tui.Version) + return + } + } + p := tea.NewProgram(tui.InitialModel()) if _, err := p.Run(); err != nil { fmt.Fprintf(os.Stderr, "error: %v\n", err) diff --git a/internal/tui/version.go b/internal/tui/version.go new file mode 100644 index 0000000..2fff6d5 --- /dev/null +++ b/internal/tui/version.go @@ -0,0 +1,6 @@ +package tui + +// Version is the installer version. It is stamped at build time via +// -ldflags "-X git.davinti.com.br/davinTI/app-dono/tui/internal/tui.Version=" +// (see the Makefile) and defaults to "dev" for local builds. +var Version = "dev" diff --git a/internal/tui/view.go b/internal/tui/view.go index 8782c31..4351cf0 100644 --- a/internal/tui/view.go +++ b/internal/tui/view.go @@ -114,8 +114,10 @@ func (m Model) View() tea.View { help := HelpStyle.Render(helpMsg) + title := TitleStyle.Render(header) + HelpStyle.Render(" v"+Version) + v := tea.NewView(fmt.Sprintf("\n%s%s\n\n%s\n\n%s%s\n", - pad, TitleStyle.Render(header), + pad, title, body, pad, help, ))