Skip to content

Commit

Permalink
version: up version handling code for SDK update
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lbajolet-hashicorp committed Apr 16, 2024
1 parent 33d9550 commit cdaad0c
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package version

import (
_ "embed"
"fmt"
"strings"

"github.com/hashicorp/go-version"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit cdaad0c

Please sign in to comment.