Add extra build info (#1115)
cc @xuu ``` [07:44:27] <prologic> xuu how's this? [07:44:28] <prologic> 0.15.1-86-geac11004-1673646222 [07:44:41] <prologic> https://files.mills.io/download/Screenshot%202023-01-14%20at%2007.44.19.png [07:45:00] <prologic> Format is: <version>-<commits>-<sha>-<timestamp> [07:45:13] <prologic> where commits are no. of commits ahead of last release [07:45:22] <prologic> timestamp is a unix epic (UTC) ``` Co-authored-by: James Mills <1290234+prologic@users.noreply.github.com> Reviewed-on: #1115pull/1116/head^2
parent
eac1100425
commit
84e7db965b
@ -1,21 +1,50 @@ |
||||
// Copyright 2020-present Yarn.social
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
package yarn |
||||
|
||||
import ( |
||||
"fmt" |
||||
"runtime/debug" |
||||
"strings" |
||||
) |
||||
|
||||
const ( |
||||
defaultVersion = "0.0.0" |
||||
defaultCommit = "HEAD" |
||||
defaultBuild = "0000-01-01:00:00+00:00" |
||||
) |
||||
|
||||
var ( |
||||
// Version release version
|
||||
Version = "0.0.2" |
||||
// Version is the tagged release version in the form <major>.<minor>.<patch>
|
||||
// following semantic versioning and is overwritten by the build system.
|
||||
Version = defaultVersion |
||||
|
||||
// Commit is the commit sha of the build (normally from Git) and is overwritten
|
||||
// by the build system.
|
||||
Commit = defaultCommit |
||||
|
||||
// Commit will be overwritten automatically by the build system
|
||||
Commit = "HEAD" |
||||
// Build is the date and time of the build as an RFC3339 formatted string
|
||||
// and is overwritten by the build system.
|
||||
Build = defaultBuild |
||||
) |
||||
|
||||
// FullVersion display the full version and build
|
||||
func FullVersion() string { |
||||
return fmt.Sprintf("%s@%s", Version, Commit) |
||||
var sb strings.Builder |
||||
|
||||
isDefault := Version == defaultVersion && Commit == defaultCommit && Build == defaultBuild |
||||
|
||||
if !isDefault { |
||||
sb.WriteString(fmt.Sprintf("%s@%s %s", Version, Commit, Build)) |
||||
} |
||||
|
||||
if info, ok := debug.ReadBuildInfo(); ok { |
||||
if isDefault { |
||||
sb.WriteString(fmt.Sprintf(" %s", info.Main.Version)) |
||||
} |
||||
sb.WriteString(fmt.Sprintf(" %s", info.GoVersion)) |
||||
if info.Main.Sum != "" { |
||||
sb.WriteString(fmt.Sprintf(" %s", info.Main.Sum)) |
||||
} |
||||
} |
||||
|
||||
return sb.String() |
||||
} |
||||
|
Loading…
Reference in new issue