diff --git a/util/version/version.go b/util/version/version.go index cfd4392abd62..46c26fab0272 100644 --- a/util/version/version.go +++ b/util/version/version.go @@ -174,7 +174,8 @@ func (v buildIdentifier) compare(o buildIdentifier) int { } type comparer struct { - buildTags bool + buildTags bool + withoutPreReleases bool } // CompareOption is a configuration option for Compare. @@ -201,6 +202,12 @@ func WithBuildTags() CompareOption { } } +func WithoutPreReleases() CompareOption { + return func(c *comparer) { + c.withoutPreReleases = true + } +} + // Compare 2 semver versions. // Defaults to doing the standard semver comparison when no options are specified. // The comparison logic can be modified by passing additional compare options. @@ -212,6 +219,11 @@ func Compare(a, b semver.Version, options ...CompareOption) int { o(c) } + if c.withoutPreReleases { + a.Pre = nil + b.Pre = nil + } + if c.buildTags { if comp := a.Compare(b); comp != 0 { return comp