Skip to content

fix(cli): embed version via ldflags so release binaries report it#49

Merged
BCook98 merged 1 commit into
mainfrom
fix-cli-version
Jun 16, 2026
Merged

fix(cli): embed version via ldflags so release binaries report it#49
BCook98 merged 1 commit into
mainfrom
fix-cli-version

Conversation

@BCook98

@BCook98 BCook98 commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Problem

The published shellcade-kit binary printed shellcade-kit (devel) / kit (unknown) for shellcade-kit version. GoReleaser builds ./cmd/shellcade-kit with plain go build, so debug.ReadBuildInfo().Main.Version is 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-level var version = "dev"; in printVersion(), prefer it over the empty bi.Main.Version when set to a real value. The in-tree go build/go run path is unchanged (version stays "dev" → falls back to build info). Under lockstep the tag is the kit module release, so the kit line adopts the same version when build info can't supply one.
  • .changeset/embed-cli-version.md: kit patch (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

$ go build ./cmd/shellcade-kit                  # plain build OK
$ go build -ldflags "-s -w -X main.version=v2.12.1" -o /tmp/sk ./cmd/shellcade-kit
$ /tmp/sk version
shellcade-kit v2.12.1
kit           v2.12.1 (github.com/shellcade/kit/v2)
abi           v2

In-tree fallback still degrades gracefully:

$ go run ./cmd/shellcade-kit version
shellcade-kit (devel)
kit           (unknown) (github.com/shellcade/kit/v2)
abi           v2

goreleaser check passes; go vet ./cmd/shellcade-kit and go test ./cmd/shellcade-kit pass.

🤖 Generated with Claude Code

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>
@BCook98
BCook98 merged commit 8e78569 into main Jun 16, 2026
6 checks passed
@BCook98
BCook98 deleted the fix-cli-version branch June 16, 2026 11:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant