fix(cli): embed version via ldflags so release binaries report it#49
Merged
Conversation
GoReleaser builds ./cmd/shellcade-kit with plain `go build`, so
debug.ReadBuildInfo().Main.Version is empty for the released artifact and
`shellcade-kit version` printed `shellcade-kit (devel)` / `kit (unknown)` —
contradicting the docs that say the binary embeds the kit version it ships
under.
Stamp the tag into a package-level `main.version` via
-ldflags "-X main.version={{.Version}}" and prefer it in printVersion (with
bi.Main.Version as the fallback for in-tree `go build`/`go run`, where version
stays "dev"). Under lockstep the tag is the kit module release, so the kit
line adopts the same version when build info can't supply one.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The published
shellcade-kitbinary printedshellcade-kit (devel)/kit (unknown)forshellcade-kit version. GoReleaser builds./cmd/shellcade-kitwith plaingo build, sodebug.ReadBuildInfo().Main.Versionis empty for the released artifact — contradicting the docs (CLAUDE.md / changeset #46) that claim "the binary embeds the same kit version it ships under".Fix
.goreleaser.yaml:ldflags: ["-s -w"]→ldflags: ["-s -w -X main.version={{.Version}}"], stamping the release tag into the binary.cmd/shellcade-kit/main.go: add a package-levelvar version = "dev"; inprintVersion(), prefer it over the emptybi.Main.Versionwhen set to a real value. The in-treego build/go runpath is unchanged (versionstays"dev"→ falls back to build info). Under lockstep the tag is the kit module release, so thekitline adopts the same version when build info can't supply one..changeset/embed-cli-version.md:kitpatch (a CLI-only fix rides a kit patch bump).The "binary embeds the same kit version it ships under" claim is now true; no doc change needed.
Verification
In-tree fallback still degrades gracefully:
goreleaser checkpasses;go vet ./cmd/shellcade-kitandgo test ./cmd/shellcade-kitpass.🤖 Generated with Claude Code