Merge pull request #19 from drone-plugins/pr_18
Follow up: Added the hugoExtended (#18)
This commit is contained in:
commit
a85b540749
@ -16,11 +16,19 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
_downloadURL = "https://github.com/gohugoio/hugo/releases/download/v%s/hugo_%s_Linux-%s.tar.gz"
|
||||
_downloadURL = "https://github.com/gohugoio/hugo/releases/download/v%s/%s_%s_Linux-%s.tar.gz"
|
||||
)
|
||||
|
||||
func downloadURL(version string) string {
|
||||
func downloadURL(version string, extended bool) string {
|
||||
var archType string
|
||||
var binary string
|
||||
|
||||
if extended {
|
||||
binary = "hugo_extended"
|
||||
} else {
|
||||
binary = "hugo"
|
||||
}
|
||||
|
||||
switch runtime.GOARCH {
|
||||
case "amd64":
|
||||
archType = "64bit"
|
||||
@ -33,7 +41,7 @@ func downloadURL(version string) string {
|
||||
default:
|
||||
archType = "unsupported"
|
||||
}
|
||||
return fmt.Sprintf(_downloadURL, version, version, archType)
|
||||
return fmt.Sprintf(_downloadURL, version, binary, version, archType)
|
||||
}
|
||||
|
||||
func getTempFile() (string, io.WriteCloser, error) {
|
||||
@ -46,8 +54,8 @@ func getTempFile() (string, io.WriteCloser, error) {
|
||||
}
|
||||
|
||||
// Get will download the specified hugo verion
|
||||
func Get(version string) (string, error) {
|
||||
resp, err := http.Get(downloadURL(version))
|
||||
func Get(version string, extended bool) (string, error) {
|
||||
resp, err := http.Get(downloadURL(version, extended))
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "")
|
||||
}
|
||||
|
@ -6,13 +6,20 @@ import (
|
||||
|
||||
func TestDownloadURL(t *testing.T) {
|
||||
want := "https://github.com/gohugoio/hugo/releases/download/v1.0/hugo_1.0_Linux-64bit.tar.gz"
|
||||
if got := downloadURL("1.0"); got != want {
|
||||
if got := downloadURL("1.0", false); got != want {
|
||||
t.Errorf("Download url is not correct, got: %s, want: %s", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDownloadURLExtended(t *testing.T) {
|
||||
want := "https://github.com/gohugoio/hugo/releases/download/v0.55.4/hugo_extended_0.55.4_Linux-64bit.tar.gz"
|
||||
if got := downloadURL("0.55.4", true); got != want {
|
||||
t.Errorf("Download url is not correct, got: %s, want: %s", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGet(t *testing.T) {
|
||||
if binPath , err := Get("0.42"); err != nil {
|
||||
if binPath , err := Get("0.42", false); err != nil {
|
||||
t.Errorf("Failed to download archive: %s", err)
|
||||
if binPath == "" {
|
||||
t.Errorf("binPath was nil")
|
||||
|
6
main.go
6
main.go
@ -92,6 +92,11 @@ func main() {
|
||||
EnvVar: "PLUGIN_HUGO_VERSION",
|
||||
Value: "",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "hugoExtended",
|
||||
Usage: "If the hugo extended package should be used",
|
||||
EnvVar: "PLUGIN_EXTENDED",
|
||||
},
|
||||
}
|
||||
if err := app.Run(os.Args); err != nil {
|
||||
log.Fatal(err)
|
||||
@ -102,6 +107,7 @@ func run(c *cli.Context) error {
|
||||
plugin := Plugin{
|
||||
Config: Config{
|
||||
HugoVersion: c.String("hugoVersion"),
|
||||
HugoExtended: c.Bool("hugoExtended"),
|
||||
BuildDrafts: c.Bool("buildDrafts"),
|
||||
BuildExpired: c.Bool("buildExpired"),
|
||||
BuildFuture: c.Bool("buildFuture"),
|
||||
|
11
plugin.go
11
plugin.go
@ -27,6 +27,7 @@ type (
|
||||
Theme string
|
||||
Url string
|
||||
HugoVersion string
|
||||
HugoExtended bool
|
||||
Validate bool
|
||||
}
|
||||
)
|
||||
@ -39,8 +40,8 @@ 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)
|
||||
if !versionsEqual(p.BuildInVersion, p.Config.HugoVersion, p.Config.HugoExtended) {
|
||||
hugoPath, err := download.Get(p.Config.HugoVersion, p.Config.HugoExtended)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -110,7 +111,11 @@ func trace(cmd *exec.Cmd) {
|
||||
fmt.Fprintf(os.Stdout, "+ %s\n", strings.Join(cmd.Args, " "))
|
||||
}
|
||||
|
||||
func versionsEqual(version string, toCompare string) bool {
|
||||
func versionsEqual(version string, toCompare string, extended bool) bool {
|
||||
if extended {
|
||||
return false
|
||||
}
|
||||
|
||||
if toCompare == version || toCompare == "" {
|
||||
return true
|
||||
} else {
|
||||
|
@ -25,12 +25,12 @@ func TestCommandValidate(t *testing.T) {
|
||||
|
||||
func TestVersionEqual(t *testing.T) {
|
||||
want := true
|
||||
if got := versionsEqual("1.0", "1.0"); want != got {
|
||||
if got := versionsEqual("1.0", "1.0", false); want != got {
|
||||
t.Errorf("want: %t, got: %t", want, got)
|
||||
}
|
||||
|
||||
want = false
|
||||
if got := versionsEqual("1.5", "1.0"); want != got {
|
||||
if got := versionsEqual("1.5", "1.0", false); want != got {
|
||||
t.Errorf("want: %t, got: %t", want, got)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user