Removing architecture attribute from plugin struct, adding switch statement for GOARCH mapping
This commit is contained in:
parent
b686d1f154
commit
b7ceb78f28
@ -111,7 +111,6 @@ func run(c *cli.Context) error {
|
||||
Theme: c.String("theme"),
|
||||
Url: c.String("url"),
|
||||
},
|
||||
Architecture: os.Getenv("PLUGIN_HUGO_ARCH"),
|
||||
BuildInVersion: os.Getenv("PLUGIN_HUGO_SHIPPED_VERSION"),
|
||||
}
|
||||
return plugin.Exec()
|
||||
|
@ -12,13 +12,27 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
"log"
|
||||
"net/http"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
var (
|
||||
_downloadURL = "https://github.com/gohugoio/hugo/releases/download/v%s/hugo_%s_Linux-%s.tar.gz"
|
||||
)
|
||||
|
||||
func downloadURL(version string, archType string) string {
|
||||
func downloadURL(version string) string {
|
||||
var archType string
|
||||
switch runtime.GOARCH {
|
||||
case "amd64":
|
||||
archType = "64bit"
|
||||
case "arm64":
|
||||
archType = "arm64"
|
||||
case "arm":
|
||||
archType = "arm"
|
||||
case "386":
|
||||
archType = "32bit"
|
||||
default:
|
||||
archType = "unsupported"
|
||||
}
|
||||
return fmt.Sprintf(_downloadURL, version, version, archType)
|
||||
}
|
||||
|
||||
@ -32,8 +46,8 @@ func getTempFile() (string, io.WriteCloser, error) {
|
||||
}
|
||||
|
||||
// Get will download the specified hugo verion
|
||||
func Get(ver string, archType string) (string, error) {
|
||||
resp, err := http.Get(downloadURL(ver, archType))
|
||||
func Get(version string) (string, error) {
|
||||
resp, err := http.Get(downloadURL(version))
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "")
|
||||
}
|
||||
|
@ -11,7 +11,6 @@ import (
|
||||
type (
|
||||
Plugin struct {
|
||||
Config Config
|
||||
Architecture string
|
||||
BuildInVersion string
|
||||
}
|
||||
|
||||
@ -40,7 +39,7 @@ func (p Plugin) Exec() error {
|
||||
// Check if buildIn plugin version equals
|
||||
// plugin version declared in drone.yml
|
||||
if !versionsEqual(p.BuildInVersion, p.Config.HugoVersion) {
|
||||
hugoPath, err := download.Get(p.Config.HugoVersion, p.Architecture)
|
||||
hugoPath, err := download.Get(p.Config.HugoVersion)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user