1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-02-09 13:36:56 +02:00

fix: better handle before hooks errors (#1698)

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>
This commit is contained in:
Carlos Alexandro Becker 2020-07-22 09:14:56 -03:00 committed by GitHub
parent 713e53d560
commit 47e88b9bcf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 16 deletions

View File

@ -37,9 +37,9 @@ func (Pipe) Run(ctx *context.Context) error {
cmd := exec.Command(args[0], args[1:]...)
cmd.Env = ctx.Env.Strings()
out, err := cmd.CombinedOutput()
log.Debug(string(out))
log.WithField("cmd", step).Debug(string(out))
if err != nil {
return fmt.Errorf("hook failed: %s\n%v", step, string(out))
return fmt.Errorf("hook failed: %s: %s; output: %s", step, err.Error(), string(out))
}
}
return nil

View File

@ -34,23 +34,20 @@ func TestRunPipe(t *testing.T) {
}
func TestRunPipeInvalidCommand(t *testing.T) {
for _, tc := range [][]string{
{`bash -c "echo \"unterminated command\"`},
} {
ctx := context.New(
config.Project{
Before: config.Before{
Hooks: tc,
},
ctx := context.New(
config.Project{
Before: config.Before{
Hooks: []string{`bash -c "echo \"unterminated command\"`},
},
)
require.Error(t, Pipe{}.Run(ctx))
}
},
)
require.EqualError(t, Pipe{}.Run(ctx), "invalid command line string")
}
func TestRunPipeFail(t *testing.T) {
for _, tc := range [][]string{
{"go tool foobar"},
for err, tc := range map[string][]string{
"hook failed: go tool foobar: exit status 2; output: go tool: no such tool \"foobar\"\n": {"go tool foobar"},
"hook failed: sh ./testdata/foo.sh: exit status 1; output: lalala\n": {"sh ./testdata/foo.sh"},
} {
ctx := context.New(
config.Project{
@ -59,7 +56,7 @@ func TestRunPipeFail(t *testing.T) {
},
},
)
require.Error(t, Pipe{}.Run(ctx))
require.EqualError(t, Pipe{}.Run(ctx), err)
}
}

3
internal/pipe/before/testdata/foo.sh vendored Normal file
View File

@ -0,0 +1,3 @@
#!/bin/sh
echo lalala
exit 1