From cdaad0cde2170ece81273fb64523c8656749634c Mon Sep 17 00:00:00 2001 From: Lucas Bajolet Date: Tue, 16 Apr 2024 13:55:48 -0400 Subject: [PATCH] version: up version handling code for SDK update Since the SDK was updated and now accepts raw version strings in addition to also supporting metadata officially, we can start using those functions in our version package as well. --- version/version.go | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/version/version.go b/version/version.go index 418d7ea4b62..139025076e6 100644 --- a/version/version.go +++ b/version/version.go @@ -5,7 +5,6 @@ package version import ( _ "embed" - "fmt" "strings" "github.com/hashicorp/go-version" @@ -52,21 +51,14 @@ func FormattedVersion() string { var SemVer *version.Version func init() { - var err error + rawVersion = strings.TrimSpace(rawVersion) - // Note: we use strings.TrimSpace on the version read from version/VERSION - // as it could have trailing whitespaces that must not be part of the - // version string, otherwise version.NewSemver will reject it. - SemVer, err = version.NewSemver(strings.TrimSpace(rawVersion)) - if err != nil { - panic(fmt.Sprintf("Invalid semver version specified in 'version/VERSION' (%q): %s", rawVersion, err)) - } + PackerVersion = pluginVersion.NewRawVersion(rawVersion) + SemVer = PackerVersion.SemVer() - Version = SemVer.Core().String() - VersionPrerelease = SemVer.Prerelease() - VersionMetadata = SemVer.Metadata() - - PackerVersion = pluginVersion.InitializePluginVersion(SemVer.Core().String(), SemVer.Prerelease()) + Version = PackerVersion.GetVersion() + VersionPrerelease = PackerVersion.GetVersionPrerelease() + VersionMetadata = PackerVersion.GetMetadata() } // String returns the complete version string, including prerelease