Track upstream versions more precisely
Kubernetes tests and client code uses semantic version tests against
alpha tags (is > v1.3.0-alpha.3). If we use v1.3.0-51-gxxxxxx, we'll
fail that test.  Instead, make our versions compatible with upstream and
use +commit at the end.
@@ -22,6 +22,8 @@ var (
majorFromGit string
// minor version
minorFromGit string
+ // build date in ISO8601 format, output of $(date -u +'%Y-%m-%dT%H:%M:%SZ')
+ buildDate string
)
// Info contains versioning information.
@@ -32,6 +34,7 @@ type Info struct {
Minor string `json:"minor"`
GitCommit string `json:"gitCommit"`
GitVersion string `json:"gitVersion"`
+ BuildDate string `json:"buildDate"`
}
// Get returns the overall codebase version. It's for detecting
@@ -42,6 +45,7 @@ func Get() Info {
Minor: minorFromGit,
GitCommit: commitFromGit,
GitVersion: versionFromGit,
+ BuildDate: buildDate,
}
}
@@ -55,12 +59,12 @@ func (info Info) String() string {
}
var (
- reCommitSegment = regexp.MustCompile(`^g[0-9a-f]{6,10}$`)
+ reCommitSegment = regexp.MustCompile(`\+[0-9a-f]{6,14}$`)
reCommitIncrement = regexp.MustCompile(`^[0-9a-f]+$`)
)
// LastSemanticVersion attempts to return a semantic version from the GitVersion - which
-// is either <semver>-<increment>-g<commit> or <semver> on release boundaries.
+// is either <semver>+<commit> or <semver> on release boundaries.
func (info Info) LastSemanticVersion() string {
version := info.GitVersion
parts := strings.Split(version, "-")
@@ -70,7 +74,10 @@ func (info Info) LastSemanticVersion() string {
}
// strip the Git commit
if len(parts) > 1 && reCommitSegment.MatchString(parts[len(parts)-1]) {
+ parts[len(parts)-1] = reCommitSegment.ReplaceAllString(parts[len(parts)-1], "")
+ if len(parts[len(parts)-1]) == 0 {
parts = parts[:len(parts)-1]
+ }
// strip a version increment, but only if we found the commit
if len(parts) > 1 && reCommitIncrement.MatchString(parts[len(parts)-1]) {
parts = parts[:len(parts)-1]
