Skip to content

Conversation

@umputun
Copy link
Owner

@umputun umputun commented Feb 10, 2026

go install doesn't inject ldflags, so revision stays "unknown". Added resolveVersion() fallback using debug.ReadBuildInfo():

  • go install @latest → module version from tag (e.g. v0.10.0)
  • go install @v0.10.0v0.10.0
  • local go build without ldflags → short VCS commit hash (e.g. abc1234)
  • make build → unchanged, ldflags take priority

Related to #83

use debug.ReadBuildInfo() fallback when ldflags revision is not set.
priority: ldflags → module version (go install tag) → VCS commit hash → unknown.

Related to #83
Copilot AI review requested due to automatic review settings February 10, 2026 19:31
@cloudflare-workers-and-pages
Copy link

Deploying ralphex with  Cloudflare Pages  Cloudflare Pages

Latest commit: baa3250
Status: ✅  Deploy successful!
Preview URL: https://71294a54.ralphex.pages.dev
Branch Preview URL: https://fix-version-unknown.ralphex.pages.dev

View logs

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a runtime fallback for the ralphex version string so binaries installed via go install display a meaningful version/commit even when ldflags aren’t injected (addressing issue #83).

Changes:

  • Introduce resolveVersion() that prefers ldflags revision, then Go module version from debug.ReadBuildInfo(), then a short VCS commit hash.
  • Switch startup version printing to use resolveVersion().
  • Add unit tests covering ldflags and fallback behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
cmd/ralphex/main.go Adds resolveVersion() using runtime/debug.ReadBuildInfo() and prints resolved version.
cmd/ralphex/main_test.go Adds tests for resolveVersion() behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +897 to +905
t.Run("fallback_to_build_info", func(t *testing.T) {
orig := revision
t.Cleanup(func() { revision = orig })
revision = "unknown"
// in test context, debug.ReadBuildInfo returns (devel) module version
// but VCS info should be available from the git repo
v := resolveVersion()
assert.NotEmpty(t, v)
})
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fallback_to_build_info currently only asserts the resolved version is non-empty, but resolveVersion() can legitimately return the literal string "unknown" here, making this test pass even if the build-info fallback logic is broken. Consider asserting that the result is not equal to "unknown" when build info contains either a non-"(devel)" module version or a vcs.revision setting, and otherwise explicitly asserting it equals "unknown" (branching based on debug.ReadBuildInfo() in the test to avoid flakiness).

Copilot uses AI. Check for mistakes.
@umputun umputun merged commit face1f4 into master Feb 10, 2026
11 checks passed
@umputun umputun deleted the fix-version-unknown branch February 10, 2026 19:34
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