tailscale/version/print.go
Brad Fitzpatrick 9dfe7875fd version: show tailscale/go toolchain git hash in version output
When built with the Tailscale Go toolchain, include the toolchain's
git revision in the version output. The non-JSON output shows the
first 10 hex digits:

  go version: go1.26.2 (tailscale/go dfe2a5fd8e)

The JSON output includes the full hash as "tailscaleGoGitHash", or
omits the field when not using tsgo.

The toolchain rev is read via a separate sync.OnceValue rather than
piggybacking on getEmbeddedInfo, because that function discards all
data when VCS fields are absent (e.g. in test binaries), while the
tailscale.toolchain.rev setting is still present.

Also add a CI-only test verifying tailscaleToolchainRev is non-empty
when built with the tailscale_go build tag.

Fixes #19374

Change-Id: Ied0b16d7aead5471d8c614c30cba8b0dcf80c691
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2026-04-13 15:20:56 -07:00

41 lines
1007 B
Go

// Copyright (c) Tailscale Inc & contributors
// SPDX-License-Identifier: BSD-3-Clause
package version
import (
"fmt"
"runtime"
"strings"
"sync"
)
var stringLazy = sync.OnceValue(func() string {
var ret strings.Builder
ret.WriteString(Short())
ret.WriteByte('\n')
if IsUnstableBuild() {
fmt.Fprintf(&ret, " track: unstable (dev); frequent updates and bugs are likely\n")
}
if gitCommit() != "" {
fmt.Fprintf(&ret, " tailscale commit: %s%s\n", gitCommit(), dirtyString())
}
fmt.Fprintf(&ret, " long version: %s\n", Long())
if extraGitCommitStamp != "" {
fmt.Fprintf(&ret, " other commit: %s\n", extraGitCommitStamp)
}
if tsGoRev := tailscaleToolchainRev(); tsGoRev != "" {
if len(tsGoRev) > 10 {
tsGoRev = tsGoRev[:10]
}
fmt.Fprintf(&ret, " go version: %s (tailscale/go %s)\n", runtime.Version(), tsGoRev)
} else {
fmt.Fprintf(&ret, " go version: %s\n", runtime.Version())
}
return strings.TrimSpace(ret.String())
})
func String() string {
return stringLazy()
}