fix(hooks): improve cmd execution

This commit is contained in:
Nightapes
2020-01-06 17:41:10 +01:00
parent a8b68f9182
commit 575ba5d5bd
2 changed files with 76 additions and 3 deletions

View File

@@ -3,6 +3,7 @@ package hooks
import (
"bufio"
"os/exec"
"runtime"
"strings"
"github.com/Nightapes/go-semantic-release/internal/shared"
@@ -51,9 +52,14 @@ func (h *Hooks) PostRelease() error {
func (h *Hooks) runCommand(command string) error {
splittedCmd := strings.Split(strings.ReplaceAll(command, "$RELEASE_VERSION", h.version.Next.Version.String()), " ")
cmdReplaced := strings.ReplaceAll(command, "$RELEASE_VERSION", h.version.Next.Version.String())
cmd := exec.Command(splittedCmd[0], splittedCmd[1:]...)
var cmd *exec.Cmd
if runtime.GOOS == "windows" {
cmd = exec.Command("cmd.exe", "/C", cmdReplaced)
} else {
cmd = exec.Command("sh", "-c", cmdReplaced)
}
cmdReader, err := cmd.StdoutPipe()
if err != nil {
@@ -63,7 +69,7 @@ func (h *Hooks) runCommand(command string) error {
scanner := bufio.NewScanner(cmdReader)
go func() {
for scanner.Scan() {
log.WithField("cmd", splittedCmd[0]).Infof("%s\n", scanner.Text())
log.WithField("cmd", strings.Fields(cmdReplaced)[0]).Infof("%s\n", scanner.Text())
}
}()