mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-01-10 03:47:03 +02:00
27aa6871cb
* chore(deps): bump github.com/golangci/golangci-lint Bumps [github.com/golangci/golangci-lint](https://github.com/golangci/golangci-lint) from 1.31.0 to 1.32.2. - [Release notes](https://github.com/golangci/golangci-lint/releases) - [Changelog](https://github.com/golangci/golangci-lint/blob/master/CHANGELOG.md) - [Commits](https://github.com/golangci/golangci-lint/compare/v1.31.0...v1.32.2) Signed-off-by: dependabot[bot] <support@github.com> * fix: lint issues Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * refactor: lint issues Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Carlos Alexandro Becker <caarlos0@gmail.com>
47 lines
1.1 KiB
Go
47 lines
1.1 KiB
Go
// Package before provides the pipe implementation that runs before all other pipes.
|
|
package before
|
|
|
|
import (
|
|
"fmt"
|
|
"os/exec"
|
|
|
|
"github.com/apex/log"
|
|
"github.com/fatih/color"
|
|
"github.com/goreleaser/goreleaser/internal/tmpl"
|
|
"github.com/goreleaser/goreleaser/pkg/context"
|
|
"github.com/mattn/go-shellwords"
|
|
)
|
|
|
|
// 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, err := shellwords.Parse(s)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
log.Infof("running %s", color.CyanString(step))
|
|
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))
|
|
}
|
|
}
|
|
return nil
|
|
}
|