github.phpd.cn/goreleaser/goreleaser@v0.92.0/internal/pipe/before/before.go (about)

     1  package before
     2  
     3  import (
     4  	"fmt"
     5  	"os/exec"
     6  	"strings"
     7  
     8  	"github.com/apex/log"
     9  	"github.com/fatih/color"
    10  	"github.com/goreleaser/goreleaser/pkg/context"
    11  )
    12  
    13  // Pipe is a global hook pipe
    14  type Pipe struct{}
    15  
    16  // String is the name of this pipe
    17  func (Pipe) String() string {
    18  	return "Running before hooks"
    19  }
    20  
    21  // Run executes the hooks
    22  func (Pipe) Run(ctx *context.Context) error {
    23  	/* #nosec */
    24  	for _, step := range ctx.Config.Before.Hooks {
    25  		args := strings.Fields(step)
    26  		log.Infof("running %s", color.CyanString(step))
    27  		cmd := exec.Command(args[0], args[1:]...)
    28  		out, err := cmd.CombinedOutput()
    29  		log.Debug(string(out))
    30  		if err != nil {
    31  			return fmt.Errorf("hook failed: %s\n%v", step, string(out))
    32  		}
    33  	}
    34  	return nil
    35  }