You've already forked goreleaser
mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-09-16 09:26:52 +02:00
fixed pre/post build hooks
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/goreleaser/goreleaser/context"
|
"github.com/goreleaser/goreleaser/context"
|
||||||
@@ -21,6 +22,13 @@ func (Pipe) Description() string {
|
|||||||
|
|
||||||
// Run the pipe
|
// Run the pipe
|
||||||
func (Pipe) Run(ctx *context.Context) error {
|
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
|
var g errgroup.Group
|
||||||
for _, goos := range ctx.Config.Build.Goos {
|
for _, goos := range ctx.Config.Build.Goos {
|
||||||
for _, goarch := range ctx.Config.Build.Goarch {
|
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 {
|
func build(name, goos, goarch string, ctx *context.Context) error {
|
||||||
ldflags := ctx.Config.Build.Ldflags + " -X main.version=" + ctx.Version
|
ldflags := ctx.Config.Build.Ldflags + " -X main.version=" + ctx.Version
|
||||||
output := "dist/" + name + "/" + ctx.Config.Build.Binary + extFor(goos)
|
output := "dist/" + name + "/" + ctx.Config.Build.Binary + extFor(goos)
|
||||||
log.Println("Building", output)
|
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"}
|
cmd := []string{"go", "build"}
|
||||||
if ctx.Config.Build.Flags != "" {
|
if ctx.Config.Build.Flags != "" {
|
||||||
cmd = append(cmd, strings.Fields(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 {
|
if err := run(goos, goarch, cmd); err != nil {
|
||||||
return err
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user