1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-08 03:31:59 +02:00

Merge pull request #148 from goreleaser/log

pre/post-build hooks should only run once
This commit is contained in:
Carlos Alexandro Becker 2017-03-24 09:51:47 -03:00 committed by GitHub
commit 475e4aae4f

View File

@ -5,6 +5,7 @@ import (
"log"
"os"
"os/exec"
"runtime"
"strings"
"github.com/goreleaser/goreleaser/context"
@ -21,6 +22,13 @@ 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
}
}
var g errgroup.Group
for _, goos := range ctx.Config.Build.Goos {
for _, goarch := range ctx.Config.Build.Goarch {
@ -39,19 +47,23 @@ func (Pipe) Run(ctx *context.Context) error {
})
}
}
return g.Wait()
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 nil
}
func build(name, goos, goarch string, ctx *context.Context) error {
ldflags := ctx.Config.Build.Ldflags + " -X main.version=" + ctx.Version
output := "dist/" + name + "/" + ctx.Config.Build.Binary + extFor(goos)
log.Println("Building", output)
if ctx.Config.Build.Hooks.Pre != "" {
cmd := strings.Fields(ctx.Config.Build.Hooks.Pre)
if err := run(goos, goarch, cmd); err != nil {
return err
}
}
cmd := []string{"go", "build"}
if ctx.Config.Build.Flags != "" {
cmd = append(cmd, strings.Fields(ctx.Config.Build.Flags)...)
@ -60,12 +72,6 @@ func build(name, goos, goarch string, ctx *context.Context) error {
if err := run(goos, goarch, cmd); err != nil {
return err
}
if ctx.Config.Build.Hooks.Post != "" {
cmd := strings.Fields(ctx.Config.Build.Hooks.Post)
if err := run(goos, goarch, cmd); err != nil {
return err
}
}
return nil
}