1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-24 04:16:27 +02:00

47 lines
1.1 KiB
Go
Raw Normal View History

// Package before provides the pipe implementation that runs before all other pipes.
2018-03-28 15:31:09 +02:00
package before
import (
"fmt"
"os/exec"
2018-04-03 21:35:48 -03:00
"github.com/apex/log"
"github.com/caarlos0/go-shellwords"
2018-04-03 21:35:48 -03:00
"github.com/fatih/color"
"github.com/goreleaser/goreleaser/internal/tmpl"
"github.com/goreleaser/goreleaser/pkg/context"
2018-03-28 15:31:09 +02:00
)
// Pipe is a global hook pipe.
2018-03-28 15:31:09 +02:00
type Pipe struct{}
// String is the name of this pipe.
2018-03-28 15:31:09 +02:00
func (Pipe) String() string {
return "running before hooks"
2018-03-28 15:31:09 +02:00
}
// Run executes the hooks.
2018-03-28 15:31:09 +02:00
func (Pipe) Run(ctx *context.Context) error {
tmpl := tmpl.New(ctx)
2018-03-28 15:31:09 +02:00
/* #nosec */
for _, step := range ctx.Config.Before.Hooks {
s, err := tmpl.Apply(step)
if err != nil {
return err
}
args, err := shellwords.Parse(s)
if err != nil {
return err
}
2018-04-03 21:35:48 -03:00
log.Infof("running %s", color.CyanString(step))
2018-03-28 15:31:09 +02:00
cmd := exec.Command(args[0], args[1:]...)
cmd.Env = ctx.Env.Strings()
out, err := cmd.CombinedOutput()
log.WithField("cmd", step).Debug(string(out))
if err != nil {
return fmt.Errorf("hook failed: %s: %w; output: %s", step, err, string(out))
2018-03-28 15:31:09 +02:00
}
}
return nil
}