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) }