mirror of
https://github.com/hashicorp/vault.git
synced 2025-08-10 00:27:02 +02:00
* add BuildDate to version base
* populate BuildDate with ldflags
* include BuildDate in FullVersionNumber
* add BuildDate to seal-status and associated status cmd
* extend core/versions entries to include BuildDate
* include BuildDate in version-history API and CLI
* fix version history tests
* fix sys status tests
* fix TestStatusFormat
* remove extraneous LD_FLAGS from build.sh
* add BuildDate to build.bat
* fix TestSysUnseal_Reset
* attempt to add build-date to release builds
* add branch to github build workflow
* add get-build-date to build-* job needs
* fix release build command vars
* add missing quote in release build command
* Revert "add branch to github build workflow"
This reverts commit b835699ecb
.
* add changelog entry
81 lines
1.7 KiB
Go
81 lines
1.7 KiB
Go
package version
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
)
|
|
|
|
// VersionInfo
|
|
type VersionInfo struct {
|
|
Revision string `json:"revision,omitempty"`
|
|
Version string `json:"version,omitempty"`
|
|
VersionPrerelease string `json:"version_prerelease,omitempty"`
|
|
VersionMetadata string `json:"version_metadata,omitempty"`
|
|
BuildDate string `json:"build_date,omitempty"`
|
|
}
|
|
|
|
func GetVersion() *VersionInfo {
|
|
ver := Version
|
|
rel := VersionPrerelease
|
|
md := VersionMetadata
|
|
if GitDescribe != "" {
|
|
ver = GitDescribe
|
|
}
|
|
if GitDescribe == "" && rel == "" && VersionPrerelease != "" {
|
|
rel = "dev"
|
|
}
|
|
|
|
return &VersionInfo{
|
|
Revision: GitCommit,
|
|
Version: ver,
|
|
VersionPrerelease: rel,
|
|
VersionMetadata: md,
|
|
BuildDate: BuildDate,
|
|
}
|
|
}
|
|
|
|
func (c *VersionInfo) VersionNumber() string {
|
|
if Version == "unknown" && VersionPrerelease == "unknown" {
|
|
return "(version unknown)"
|
|
}
|
|
|
|
version := c.Version
|
|
|
|
if c.VersionPrerelease != "" {
|
|
version = fmt.Sprintf("%s-%s", version, c.VersionPrerelease)
|
|
}
|
|
|
|
if c.VersionMetadata != "" {
|
|
version = fmt.Sprintf("%s+%s", version, c.VersionMetadata)
|
|
}
|
|
|
|
return version
|
|
}
|
|
|
|
func (c *VersionInfo) FullVersionNumber(rev bool) string {
|
|
var versionString bytes.Buffer
|
|
|
|
if Version == "unknown" && VersionPrerelease == "unknown" {
|
|
return "Vault (version unknown)"
|
|
}
|
|
|
|
fmt.Fprintf(&versionString, "Vault v%s", c.Version)
|
|
if c.VersionPrerelease != "" {
|
|
fmt.Fprintf(&versionString, "-%s", c.VersionPrerelease)
|
|
}
|
|
|
|
if c.VersionMetadata != "" {
|
|
fmt.Fprintf(&versionString, "+%s", c.VersionMetadata)
|
|
}
|
|
|
|
if rev && c.Revision != "" {
|
|
fmt.Fprintf(&versionString, " (%s)", c.Revision)
|
|
}
|
|
|
|
if c.BuildDate != "" {
|
|
fmt.Fprintf(&versionString, ", built %s", c.BuildDate)
|
|
}
|
|
|
|
return versionString.String()
|
|
}
|