diff --git a/pipeline/build/build.go b/pipeline/build/build.go index 692924094..ee3f7ed93 100644 --- a/pipeline/build/build.go +++ b/pipeline/build/build.go @@ -23,12 +23,8 @@ func (Pipe) Description() string { // Run the pipe func (Pipe) Run(ctx *context.Context) error { - if ctx.Config.Build.Hooks.Pre != "" { - log.Println("Running pre-build hook", ctx.Config.Build.Hooks.Pre) - cmd := strings.Fields(ctx.Config.Build.Hooks.Pre) - if err := run(runtime.GOOS, runtime.GOARCH, cmd); err != nil { - return err - } + if err := runHook(ctx.Config.Build.Hooks.Pre); err != nil { + return err } var g errgroup.Group for _, goos := range ctx.Config.Build.Goos { @@ -51,14 +47,16 @@ func (Pipe) Run(ctx *context.Context) error { if err := g.Wait(); err != nil { return err } - if ctx.Config.Build.Hooks.Post != "" { - log.Println("Running post-build hook", ctx.Config.Build.Hooks.Post) - cmd := strings.Fields(ctx.Config.Build.Hooks.Post) - if err := run(runtime.GOOS, runtime.GOARCH, cmd); err != nil { - return err - } + return runHook(ctx.Config.Build.Hooks.Post) +} + +func runHook(hook string) error { + if hook == "" { + return nil } - return nil + log.Println("Running hook", hook) + cmd := strings.Fields(hook) + return run(runtime.GOOS, runtime.GOARCH, cmd) } func build(name, goos, goarch string, ctx *context.Context) error { @@ -77,10 +75,7 @@ func build(name, goos, goarch string, ctx *context.Context) error { return err } cmd = append(cmd, "-ldflags="+flags, "-o", output, ctx.Config.Build.Main) - if err := run(goos, goarch, cmd); err != nil { - return err - } - return nil + return run(goos, goarch, cmd) } func run(goos, goarch string, command []string) error { diff --git a/pipeline/env/env_test.go b/pipeline/env/env_test.go index 287fb3f13..01bb766ed 100644 --- a/pipeline/env/env_test.go +++ b/pipeline/env/env_test.go @@ -24,7 +24,7 @@ func TestValidEnv(t *testing.T) { func TestInvalidEnv(t *testing.T) { assert := assert.New(t) - os.Unsetenv("GITHUB_TOKEN") + assert.NoError(os.Unsetenv("GITHUB_TOKEN")) var ctx = &context.Context{ Config: config.Project{}, } diff --git a/pipeline/git/git.go b/pipeline/git/git.go index f1a7db438..34b2434c5 100644 --- a/pipeline/git/git.go +++ b/pipeline/git/git.go @@ -46,7 +46,8 @@ func (Pipe) Run(ctx *context.Context) (err error) { } // removes usual `v` prefix ctx.Version = strings.TrimPrefix(tag, "v") - if matches, err := regexp.MatchString("^[0-9.]+", ctx.Version); !matches || err != nil { + matches, err := regexp.MatchString("^[0-9.]+", ctx.Version) + if err != nil || !matches { return ErrInvalidVersionFormat{ctx.Version} } commit, err := commitHash()