From da75e49223910080d2aaa0a0b0716d4b79a5045a Mon Sep 17 00:00:00 2001 From: David Anderson Date: Mon, 6 Feb 2023 23:23:00 -0800 Subject: [PATCH] version: return correct Meta.MajorMinorPatch in non-dev builds Signed-off-by: David Anderson --- version-embed.go | 7 ++++++- version/prop.go | 3 +-- version/version.go | 13 +++++++++++-- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/version-embed.go b/version-embed.go index b65759310..40c2e7cef 100644 --- a/version-embed.go +++ b/version-embed.go @@ -6,8 +6,13 @@ package tailscaleroot import _ "embed" +// VersionDotTxt is the contents of VERSION.txt. Despite the tempting filename, +// this does not necessarily contain the accurate version number of the build, which +// depends on the branch type and how it was built. To get version information, use +// the version package instead. +// //go:embed VERSION.txt -var Version string +var VersionDotTxt string //go:embed ALPINE.txt var AlpineDockerTag string diff --git a/version/prop.go b/version/prop.go index 4bb77717a..0077c4e76 100644 --- a/version/prop.go +++ b/version/prop.go @@ -6,7 +6,6 @@ package version import ( "strings" - tailscaleroot "tailscale.com" "tailscale.com/tailcfg" ) @@ -95,7 +94,7 @@ type Meta struct { // GetMeta returns version metadata about the current build. func GetMeta() Meta { return Meta{ - MajorMinorPatch: strings.TrimSpace(tailscaleroot.Version), + MajorMinorPatch: majorMinorPatch, Short: Short, Long: Long, GitCommit: GitCommit, diff --git a/version/version.go b/version/version.go index ac0a274c5..9c32e7d87 100644 --- a/version/version.go +++ b/version/version.go @@ -80,6 +80,9 @@ var ( // isWindowsGUI is whether the current binary is the Windows GUI binary. isWindowsGUI bool + + // majorMinorPatch is the major.minor.patch portion of Short. + majorMinorPatch string ) func init() { @@ -89,6 +92,12 @@ func init() { } func initVersion() { + defer func() { + // Must be run after Short has been initialized, easiest way to do that + // is a defer. + majorMinorPatch, _, _ = strings.Cut(Short, "-") + }() + if Long != "" && Short != "" { // Built in the recommended way, using build_dist.sh. return @@ -98,7 +107,7 @@ func initVersion() { // stamping. bi, ok := debug.ReadBuildInfo() if !ok { - Long = strings.TrimSpace(tailscaleroot.Version) + "-ERR-BuildInfo" + Long = strings.TrimSpace(tailscaleroot.VersionDotTxt) + "-ERR-BuildInfo" Short = Long return } @@ -126,7 +135,7 @@ func initVersion() { } // Backup path, using Go 1.18's built-in git stamping. - Short = strings.TrimSpace(tailscaleroot.Version) + "-dev" + commitDate + Short = strings.TrimSpace(tailscaleroot.VersionDotTxt) + "-dev" + commitDate Long = Short + "-t" + commitHashAbbrev + dirty }