mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-03-17 20:47:50 +02:00
fixed pre/post build hooks
This commit is contained in:
parent
0aa98cef67
commit
cc46a0b347
@ -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,20 +47,21 @@ func (Pipe) Run(ctx *context.Context) error {
|
||||
})
|
||||
}
|
||||
}
|
||||
return g.Wait()
|
||||
err := g.Wait()
|
||||
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 err
|
||||
}
|
||||
|
||||
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 != "" {
|
||||
log.Println("Running pre-build hook", 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)...)
|
||||
@ -61,13 +70,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 != "" {
|
||||
log.Println("Running post-build hook", 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
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user