fix(cli): ensure version is correctly embedded in all release binaries - #364
Merged
Conversation
#363) The musl-binary build in release.yaml was missing the version injection LDFLAGS (-X kcl-lang.io/cli/pkg/version.version=...), so the resulting binary would fall back to the hardcoded VersionTypeLatest constant and display a stale version. Additionally, VersionTypeLatest had not been updated since 0.12.3 and the constants list was missing 0.12.4-0.12.7, which would all silently display the wrong version if LDFLAGS were ever forgotten again. Changes: - release.yaml: read VERSION and inject it via LDFLAGS into the musl build - version.go: bump VersionTypeLatest to 0.12.8 and add the missing 0.12.4-0.12.8 constants so the fallback is at least current Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Adds a secondary fallback so binaries built without the
`-ldflags "-X .../pkg/version.version=..."` injection still report a
useful version instead of silently displaying the hardcoded
VersionTypeLatest constant.
The lookup order is now:
1. LDFLAGS-injected `version` variable (used by goreleaser and the
musl release build).
2. `debug.ReadBuildInfo().Main.Version` from the Go runtime (works
for `go install kcl-lang.io/cli@vX.Y.Z` and similar module-aware
builds). The leading "v" is stripped and "(devel)" / pseudo-versions
are treated as "no version available" so the fallback can still
kick in.
3. Hardcoded `VersionTypeLatest` constant.
A new test asserts that the build info path returns the empty string
under `go test` (where the main module is reported as "(devel)").
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Coverage Report for CI Build 31017517112Coverage increased (+0.3%) to 27.691%Details
Uncovered Changes
Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
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
Issue #363: Users downloading release binaries (notably the linux-musl-amd64 build, but possibly others in past releases) see
0.12.3-darwin-arm64or similar stale output when runningkcl version, instead of the version they downloaded.Root Cause
Primary: The
musl-binaryjob in.github/workflows/release.yamlbuilds the static musl binary without the-X kcl-lang.io/cli/pkg/version.version=...LDFLAGS that the goreleaser-drivenbinaryjob uses. The globalversionvariable inpkg/version/version.gotherefore stays empty, andGetVersionString()falls back toVersionTypeLatest.Secondary:
VersionTypeLatestwas hardcoded toVersion_0_12_3and the constants list was missing0.12.4–0.12.7. So even when the fallback kicked in (e.g., for local builds without LDFLAGS), it would silently display a stale version.Tertiary: The fallback chain had only one step (the hardcoded constant), so any build that did not pass LDFLAGS — including
go install-style module-aware builds — silently reported a stale version instead of the version embedded in the Go build info.Fix
.github/workflows/release.yaml: readVERSIONin the musl build step and pass it via-X 'kcl-lang.io/cli/pkg/version.version=${VERSION}', mirroring how the regular goreleaser build injects the version.pkg/version/version.go:VersionTypeLatesttoVersion_0_12_8.Version_0_12_4…Version_0_12_8constants so the fallback can never silently regress to a much older version.runtime/debug.ReadBuildInfo().Main.Versionso module-aware installs (go install kcl-lang.io/cli@vX.Y.Z) report the correct version even without LDFLAGS."(devel)"and pseudo-versions are treated as "no version available" so the constant fallback still kicks in for local dirty builds.pkg/version/version_test.go: add aTestBuildInfoVersioncovering the(devel)case undergo test.Lookup order
versionpackage variable (LDFLAGS-injected; used by goreleaser and the fixed musl build)debug.ReadBuildInfo().Main.Version(works forgo installfrom a tagged module)VersionTypeLatestconstant (last resort)Verification
Built locally and confirmed all three paths:
go test ./pkg/version/...passes.Fixes #363
🤖 Generated with Claude Code