1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-03-17 20:47:50 +02:00

fix: simplified before hook code

This commit is contained in:
Carlos Alexandro Becker 2018-04-03 21:35:48 -03:00
parent cbdd90ddad
commit cac92e8734
No known key found for this signature in database
GPG Key ID: E61E2F7DC14AB940

View File

@ -5,6 +5,8 @@ import (
"os/exec"
"strings"
"github.com/apex/log"
"github.com/fatih/color"
"github.com/goreleaser/goreleaser/context"
)
@ -13,15 +15,7 @@ type Pipe struct{}
// String is the name of this pipe
func (Pipe) String() string {
return "Run global hooks before starting the relase process"
}
// Default initialized the default values
func (Pipe) Default(ctx *context.Context) error {
if ctx.Config.Before.Hooks == nil {
ctx.Config.Before.Hooks = []string{}
}
return nil
return "Running before hooks"
}
// Run executes the hooks
@ -29,8 +23,10 @@ func (Pipe) Run(ctx *context.Context) error {
/* #nosec */
for _, step := range ctx.Config.Before.Hooks {
args := strings.Fields(step)
log.Infof("running %s", color.CyanString(step))
cmd := exec.Command(args[0], args[1:]...)
if out, err := cmd.CombinedOutput(); err != nil {
log.Debug(string(out))
return fmt.Errorf("hook failed: %s\n%v", step, string(out))
}
}