Uploaded image for project: 'Red Hat OpenShift Control Planes'
  1. Red Hat OpenShift Control Planes
  2. CNTRLPLANE-2807

Fix hypershift CLI version showing <unknown> in git worktree builds

XMLWordPrintable

    • Icon: Task Task
    • Resolution: Unresolved
    • Icon: Undefined Undefined
    • None
    • None
    • None
    • None
    • None
    • False
    • Hide

      None

      Show
      None
    • False
    • None

      When building the hypershift CLI from a git worktree, hypershift --version shows [unknown] instead of the git commit hash.

      Root cause: Go's VCS stamping does not embed vcs.revision into binaries when building with -mod=vendor or from git worktrees. The GetRevision() function in support/supportedversion/version.go relies solely on runtime/debug.ReadBuildInfo() to retrieve the commit hash, which returns nothing in these scenarios.

      Fix: Add a commitHash package variable to supportedversion that is injected via -ldflags -X at build time, and use it as a fallback in GetRevision() when debug.ReadBuildInfo() does not provide vcs.revision. The Makefile build recipes are updated to pass git rev-parse HEAD through ldflags.

      Files changed:

      • Makefile — added COMMIT_HASH, VERSION_PKG, GO_LDFLAGS variables; updated GO_BUILD_RECIPE and GO_CLI_RECIPE
      • support/supportedversion/version.go — added commitHash variable and fallback logic in GetRevision()

              Unassigned Unassigned
              cewong@redhat.com Cesar Wong
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated: