Added the hugoExtended

This commit is contained in:
Jens True 2019-04-25 10:48:42 +02:00
parent e635243b54
commit 1f5cdffd0b
6 changed files with 41 additions and 12 deletions

3
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,3 @@
{
"go.formatTool": "goimports"
}

View File

@ -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, "")
}

View File

@ -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")

View File

@ -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_HUGO_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"),

View File

@ -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 {

View File

@ -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)
}
}