1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-10 03:47:03 +02:00
goreleaser/internal/pipe/before/before.go
Carlos Alexandro Becker cf4aba68d3
feat: global env and template-able before hooks (#974)
* feat: global env

* docs: hooks templateable, global env

* docs: hooks templateable, global env

* feat: templas on before hooks

* docs: revert unwanted change

* fix: use os.environ too

* chore: travis

* fix: goreleaser.yml
2019-03-03 14:12:22 -03:00

44 lines
921 B
Go

package before
import (
"fmt"
"os"
"os/exec"
"strings"
"github.com/apex/log"
"github.com/fatih/color"
"github.com/goreleaser/goreleaser/internal/tmpl"
"github.com/goreleaser/goreleaser/pkg/context"
)
// Pipe is a global hook pipe
type Pipe struct{}
// String is the name of this pipe
func (Pipe) String() string {
return "Running before hooks"
}
// Run executes the hooks
func (Pipe) Run(ctx *context.Context) error {
var tmpl = tmpl.New(ctx)
/* #nosec */
for _, step := range ctx.Config.Before.Hooks {
s, err := tmpl.Apply(step)
if err != nil {
return err
}
args := strings.Fields(s)
log.Infof("running %s", color.CyanString(step))
cmd := exec.Command(args[0], args[1:]...)
cmd.Env = append(os.Environ(), ctx.Config.Env...)
out, err := cmd.CombinedOutput()
log.Debug(string(out))
if err != nil {
return fmt.Errorf("hook failed: %s\n%v", step, string(out))
}
}
return nil
}