From effbcd64f67120787b12743ebb32ec27e93a05ce Mon Sep 17 00:00:00 2001 From: Brandon Cook Date: Tue, 16 Jun 2026 21:16:03 +1000 Subject: [PATCH] fix(cli): embed version via ldflags so release binaries report it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .changeset/embed-cli-version.md | 11 +++++++++++ .goreleaser.yaml | 2 +- cmd/shellcade-kit/main.go | 16 ++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 .changeset/embed-cli-version.md diff --git a/.changeset/embed-cli-version.md b/.changeset/embed-cli-version.md new file mode 100644 index 0000000..136c6dc --- /dev/null +++ b/.changeset/embed-cli-version.md @@ -0,0 +1,11 @@ +--- +"kit": patch +--- + +`shellcade-kit version` now reports the real release version instead of +`(devel)`/`(unknown)`. GoReleaser builds the binary with plain `go build`, so +`debug.ReadBuildInfo().Main.Version` was empty for the released artifact; +GoReleaser now stamps the tag into `main.version` via `-ldflags`, making the +"binary embeds the same kit version it ships under" claim true. In-tree +`go build`/`go run` is unchanged (still falls back to build info). No behavior +change for game authors. diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 4c7e639..342cec7 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -18,7 +18,7 @@ builds: env: [CGO_ENABLED=0] goos: [darwin, linux, windows] goarch: [amd64, arm64] - ldflags: ["-s -w"] + ldflags: ["-s -w -X main.version={{.Version}}"] archives: - formats: [tar.gz] diff --git a/cmd/shellcade-kit/main.go b/cmd/shellcade-kit/main.go index ebf4c8d..e5c2ad7 100644 --- a/cmd/shellcade-kit/main.go +++ b/cmd/shellcade-kit/main.go @@ -35,6 +35,12 @@ import ( "github.com/shellcade/kit/v2/host/sdk" ) +// version is the binary's own version. GoReleaser overrides it via +// -ldflags "-X main.version={{.Version}}" so release binaries report the kit +// tag they ship under; in-tree `go build`/`go run` leaves it "dev" and +// printVersion falls back to the module version from build info. +var version = "dev" + func main() { if len(os.Args) >= 2 && os.Args[1] == "version" { printVersion() @@ -117,6 +123,16 @@ func printVersion() { } } } + // A real -ldflags value (the GoReleaser release path) wins over the empty + // bi.Main.Version that in-tree `go build` produces. Under lockstep the tag + // IS the kit module release, so the binary ships under that kit version too + // — adopt it for the kit line when build info couldn't supply one. + if version != "" && version != "dev" { + own = version + if kitv == "(unknown)" { + kitv = version + } + } fmt.Printf("shellcade-kit %s\nkit %s (github.com/shellcade/kit/v2)\nabi v%d\n", own, kitv, gameabi.Version) }