Related to #83

This commit is contained in:
Henrique Dias 2016-08-09 22:49:03 +01:00
parent 432438c573
commit 629d78ecee
3 changed files with 66 additions and 262 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
hugo
hugo.gz

262
binary.go

File diff suppressed because one or more lines are too long

64
build/main.go Normal file
View File

@ -0,0 +1,64 @@
package main
import (
"log"
"os"
"os/exec"
"path/filepath"
"strings"
)
func main() {
goPath := os.Getenv("GOPATH")
hugoPath := filepath.Join(goPath, "src/github.com/spf13/hugo")
if found, err := exists(hugoPath); !found || err != nil {
log.Fatalf("Aborting. Can't find Hugo source on %s.", hugoPath)
}
// NOTE: I assume that 'go get -u' was run before of this and that
// every package and dependency is up to date.
// Get new tags from remote
run("git", []string{"fetch", "--tags"}, hugoPath)
// Get the revision for the latest tag
commit := run("git", []string{"rev-list", "--tags", "--max-count=1"}, hugoPath)
// Get the latest tag
tag := run("git", []string{"describe", "--tags", commit}, hugoPath)
// Checkout the latest tag
run("git", []string{"checkout", tag}, hugoPath)
// Build hugo binary
pluginPath := filepath.Join(goPath, "src/github.com/hacdias/caddy-hugo")
run("go", []string{"build", "-o", "assets/hugo", "github.com/spf13/hugo"}, pluginPath)
}
func run(command string, args []string, path string) string {
cmd := exec.Command(command, args...)
cmd.Dir = path
out, err := cmd.Output()
if err != nil {
log.Fatal(err)
}
return strings.TrimSpace(string(out))
}
// exists returns whether the given file or directory exists or not
func exists(path string) (bool, error) {
_, err := os.Stat(path)
if err == nil {
return true, nil
}
if os.IsNotExist(err) {
return false, nil
}
return true, err
}