Skip to content

fix: infer module version for source builds#545

Closed
joshavant wants to merge 1 commit intoopenclaw:mainfrom
joshavant:fix/module-version-fallback
Closed

fix: infer module version for source builds#545
joshavant wants to merge 1 commit intoopenclaw:mainfrom
joshavant:fix/module-version-fallback

Conversation

@joshavant
Copy link
Copy Markdown
Contributor

Summary

This makes version reporting use Go build metadata as a fallback when release metadata has not been injected by linker flags.

Release builds still work the same way: GoReleaser injects version, commit, and date with -ldflags, and those injected values remain authoritative. For source/module builds without those linker flags, gog now falls back to debug.ReadBuildInfo() and reports the main module version when Go provides one.

Why

go install github.com/steipete/gogcli/cmd/gog@v0.14.0 does not run through GoReleaser, so it does not receive the release workflow's -ldflags. Before this change, those builds fell back to the hardcoded source value (0.13.0-dev), which made a binary built from a newer tag look like an older development build.

That is misleading for diagnostics, support reports, and packaging verification.

Why This Change

This keeps the release workflow and GoReleaser config unchanged while improving source-build behavior:

  • GoReleaser artifacts keep their rich injected output, e.g. v0.14.0 (commit date).
  • go install module@version can report the module version from Go's build info.
  • Plain local development builds still fall back to dev when no useful module version is available.
  • Stale hardcoded release-like fallback values are removed.

Verification

  • go test ./internal/cmd
  • go test ./cmd/gog
  • go build -o /tmp/gog-dev ./cmd/gog && /tmp/gog-dev --version prints the local module/VCS-derived build version
  • go build -ldflags \"-X github.com/steipete/gogcli/internal/cmd.version=v9.9.9 -X github.com/steipete/gogcli/internal/cmd.commit=abc123 -X github.com/steipete/gogcli/internal/cmd.date=2026-05-01T00:00:00Z\" -o /tmp/gog-release ./cmd/gog && /tmp/gog-release --version prints v9.9.9 (abc123 2026-05-01T00:00:00Z)

Related issue: #544

@steipete
Copy link
Copy Markdown
Collaborator

steipete commented May 4, 2026

Thanks for the PR. This fix is already on main as 6af52a4 (fix(version): infer module version for source installs), including the module build-info fallback and regression coverage.

Verified current origin/main has the behavior with go test ./internal/cmd -run TestVersionStringUsesModuleVersionFallback; I also closed #544 with the same proof. Closing this PR as superseded by main, with attribution preserved in the changelog.

@steipete steipete closed this May 4, 2026
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.

2 participants