Skip to content

Commit

Permalink
fix(download): make extended version download work (#35)
Browse files Browse the repository at this point in the history
* fix(download): make extended version download work

* allow leading v
  • Loading branch information
wass3r authored Aug 31, 2022
1 parent 7342052 commit 136523c
Showing 1 changed file with 41 additions and 8 deletions.
49 changes: 41 additions & 8 deletions cmd/vela-hugo/hugo.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"runtime"
"strings"

"github.com/Masterminds/semver/v3"
"github.com/hashicorp/go-getter"
"github.com/sirupsen/logrus"
"github.com/spf13/afero"
Expand Down Expand Up @@ -58,28 +59,60 @@ func install(extendedBinary bool, customVer, defaultVer string) error {
archType = "unsupported"
}

versionMatch := strings.EqualFold(customVer, defaultVer)
// change the binary file name
// if the extended version for Sass/SCSS support
// has been requested
if extendedBinary {
logrus.Infof("using extended hugo binary")

binary = "hugo_extended"
}

// check if the custom version requested
// is the default version
isDefaultVersion := strings.EqualFold(customVer, defaultVer)

// check if the custom version matches the default version and/or the extneded binary is requested
if versionMatch && !extendedBinary {
if isDefaultVersion && !extendedBinary {
// the hugo versions match and using the base hugo binary so no action is required
return nil
}

if !versionMatch {
logrus.Infof("custom version does not match default: %s", defaultVer)
// use default version if no custom version
// was requested
if len(customVer) == 0 {
customVer = defaultVer
}

if extendedBinary {
logrus.Infof("using extended hugo binary")
// try to parse the version
// into semantic version struct
ver, err := semver.NewVersion(customVer)
if err != nil {
return fmt.Errorf("not a valid version: %s", customVer)
}

binary = "hugo_extended"
// allow version usage with and without leading 'v'
customVer = strings.TrimPrefix(customVer, "v")

// let user know that a custom version
// was requested
if !isDefaultVersion && len(customVer) > 0 {
logrus.Infof("custom version requested (default is: %s): %s", defaultVer, customVer)
}

// special handling for macOS.
// starting with 0.102, hugo supplies
// a fat universal binary
//
// see notes here: https://github.com/gohugoio/hugo/releases/tag/v0.102.0
if osName == "macOS" && ver.Minor() > uint64(101) {
archType = "universal"
}

// rename the old hugo binary since we can't overwrite it for now
//
// https://github.com/hashicorp/go-getter/issues/219
err := a.Rename(_hugo, fmt.Sprintf("%s.default", _hugo))
err = a.Rename(_hugo, fmt.Sprintf("%s.default", _hugo))
if err != nil {
return err
}
Expand Down

0 comments on commit 136523c

Please sign in to comment.