1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-24 04:16:27 +02:00
Carlos Alexandro Becker 7c6bd86b28
fix: do not do fancy 3rd party process logging (#3747)
do not write fields et al, let it just roll, otherwise its too noisy,
and we might expose things we are not supposed to.

closes #3741

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
2023-02-01 23:25:36 -03:00

45 lines
982 B
Go

package shell
import (
"bytes"
"fmt"
"io"
"os/exec"
"strings"
"github.com/caarlos0/log"
"github.com/goreleaser/goreleaser/internal/gio"
"github.com/goreleaser/goreleaser/internal/logext"
"github.com/goreleaser/goreleaser/pkg/context"
)
// Run a shell command with given arguments and envs
func Run(ctx *context.Context, dir string, command, env []string, output bool) error {
fields := log.Fields{
"cmd": command,
"env": env,
}
/* #nosec */
cmd := exec.CommandContext(ctx, command[0], command[1:]...)
cmd.Env = env
var b bytes.Buffer
w := gio.Safe(&b)
cmd.Stderr = io.MultiWriter(logext.NewConditionalWriter(output), w)
cmd.Stdout = io.MultiWriter(logext.NewConditionalWriter(output), w)
if dir != "" {
cmd.Dir = dir
}
log.WithFields(fields).Debug("running")
if err := cmd.Run(); err != nil {
log.WithFields(fields).WithError(err).Debug("failed")
return fmt.Errorf("failed to run '%s': %w", strings.Join(command, " "), err)
}
return nil
}