1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-10 03:47:03 +02:00
goreleaser/pipeline/before/before.go

35 lines
721 B
Go
Raw Normal View History

2018-03-28 15:31:09 +02:00
package before
import (
"fmt"
"os/exec"
"strings"
2018-04-04 02:35:48 +02:00
"github.com/apex/log"
"github.com/fatih/color"
2018-03-28 15:31:09 +02:00
"github.com/goreleaser/goreleaser/context"
)
// Pipe is a global hook pipe
type Pipe struct{}
// String is the name of this pipe
func (Pipe) String() string {
2018-04-04 02:35:48 +02:00
return "Running before hooks"
2018-03-28 15:31:09 +02:00
}
// Run executes the hooks
func (Pipe) Run(ctx *context.Context) error {
/* #nosec */
for _, step := range ctx.Config.Before.Hooks {
args := strings.Fields(step)
2018-04-04 02:35:48 +02:00
log.Infof("running %s", color.CyanString(step))
2018-03-28 15:31:09 +02:00
cmd := exec.Command(args[0], args[1:]...)
if out, err := cmd.CombinedOutput(); err != nil {
2018-04-04 02:35:48 +02:00
log.Debug(string(out))
2018-03-28 15:31:09 +02:00
return fmt.Errorf("hook failed: %s\n%v", step, string(out))
}
}
return nil
}