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"
|
2019-03-03 19:12:22 +02:00
|
|
|
"github.com/goreleaser/goreleaser/internal/tmpl"
|
2018-08-15 04:50:20 +02:00
|
|
|
"github.com/goreleaser/goreleaser/pkg/context"
|
2018-03-28 15:31:09 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// Pipe is a global hook pipe
|
|
|
|
type Pipe struct{}
|
|
|
|
|
|
|
|
// String is the name of this pipe
|
|
|
|
func (Pipe) String() string {
|
2020-03-06 06:25:09 +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 {
|
2019-03-03 19:12:22 +02:00
|
|
|
var tmpl = tmpl.New(ctx)
|
2018-03-28 15:31:09 +02:00
|
|
|
/* #nosec */
|
|
|
|
for _, step := range ctx.Config.Before.Hooks {
|
2019-03-03 19:12:22 +02:00
|
|
|
s, err := tmpl.Apply(step)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
args := strings.Fields(s)
|
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:]...)
|
2019-04-09 14:15:05 +02:00
|
|
|
cmd.Env = ctx.Env.Strings()
|
2018-04-10 19:35:45 +02:00
|
|
|
out, err := cmd.CombinedOutput()
|
|
|
|
log.Debug(string(out))
|
|
|
|
if err != nil {
|
2018-03-28 15:31:09 +02:00
|
|
|
return fmt.Errorf("hook failed: %s\n%v", step, string(out))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|