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

fix: skip post-hook on universal binaries as well

closes #4278
This commit is contained in:
Carlos Alexandro Becker 2023-09-17 16:56:26 +00:00
parent 0337a0b3a8
commit d90c2ca2f2
No known key found for this signature in database
GPG Key ID: E61E2F7DC14AB940
3 changed files with 25 additions and 2 deletions

View File

@ -9,6 +9,7 @@ import (
"github.com/goreleaser/goreleaser/internal/artifact"
"github.com/goreleaser/goreleaser/internal/semerrgroup"
"github.com/goreleaser/goreleaser/internal/skips"
"github.com/goreleaser/goreleaser/internal/testctx"
"github.com/goreleaser/goreleaser/internal/testlib"
"github.com/goreleaser/goreleaser/internal/tmpl"
@ -223,6 +224,17 @@ func TestRunPipeFailingHooks(t *testing.T) {
require.ErrorIs(t, err, exec.ErrNotFound)
require.Contains(t, err.Error(), "post hook failed")
})
t.Run("post-hook-skip", func(t *testing.T) {
ctx := testctx.NewWithCfg(
cfg,
testctx.WithCurrentTag("2.4.5"),
testctx.Skip(skips.PostBuildHooks),
)
ctx.Config.Builds[0].Hooks.Pre = []config.Hook{{Cmd: "echo pre"}}
ctx.Config.Builds[0].Hooks.Post = []config.Hook{{Cmd: "exit 1"}}
require.NoError(t, Pipe{}.Run(ctx))
})
}
func TestDefaultNoBuilds(t *testing.T) {

View File

@ -16,6 +16,7 @@ import (
"github.com/goreleaser/goreleaser/internal/pipe"
"github.com/goreleaser/goreleaser/internal/semerrgroup"
"github.com/goreleaser/goreleaser/internal/shell"
"github.com/goreleaser/goreleaser/internal/skips"
"github.com/goreleaser/goreleaser/internal/tmpl"
"github.com/goreleaser/goreleaser/pkg/build"
"github.com/goreleaser/goreleaser/pkg/config"
@ -64,8 +65,10 @@ func (Pipe) Run(ctx *context.Context) error {
if err := makeUniversalBinary(ctx, &opts, unibin); err != nil {
return err
}
if err := runHook(ctx, &opts, unibin.Hooks.Post); err != nil {
return fmt.Errorf("post hook failed: %w", err)
if !skips.Any(ctx, skips.PostBuildHooks) {
if err := runHook(ctx, &opts, unibin.Hooks.Post); err != nil {
return fmt.Errorf("post hook failed: %w", err)
}
}
if !unibin.Replace {
return nil

View File

@ -12,6 +12,7 @@ import (
"time"
"github.com/goreleaser/goreleaser/internal/artifact"
"github.com/goreleaser/goreleaser/internal/skips"
"github.com/goreleaser/goreleaser/internal/testctx"
"github.com/goreleaser/goreleaser/internal/testlib"
"github.com/goreleaser/goreleaser/pkg/config"
@ -329,6 +330,13 @@ func TestRun(t *testing.T) {
require.Contains(t, err.Error(), "post hook failed")
})
t.Run("skipping post-hook", func(t *testing.T) {
ctx := ctx5
skips.Set(ctx, skips.PostBuildHooks)
ctx.Config.UniversalBinaries[0].Hooks.Post = []config.Hook{{Cmd: "exit 1"}}
require.NoError(t, Pipe{}.Run(ctx))
})
t.Run("hook with env tmpl", func(t *testing.T) {
ctx := ctx5
ctx.Config.UniversalBinaries[0].Hooks.Pre = []config.Hook{{