You've already forked goreleaser
mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-06-23 00:40:06 +02:00
feat: add hooks to universal binaries (#2684)
* add hooks for universal binaries * task fmt
This commit is contained in:
committed by
GitHub
parent
611313571e
commit
f9b693edf0
@ -104,7 +104,9 @@ func TestRun(t *testing.T) {
|
||||
"arm64": filepath.Join(dist, "fake_darwin_arm64/fake"),
|
||||
}
|
||||
|
||||
ctx1 := context.New(config.Project{
|
||||
pre := filepath.Join(dist, "pre")
|
||||
post := filepath.Join(dist, "post")
|
||||
cfg := config.Project{
|
||||
Dist: dist,
|
||||
UniversalBinaries: []config.UniversalBinary{
|
||||
{
|
||||
@ -113,7 +115,8 @@ func TestRun(t *testing.T) {
|
||||
Replace: true,
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
ctx1 := context.New(cfg)
|
||||
|
||||
ctx2 := context.New(config.Project{
|
||||
Dist: dist,
|
||||
@ -145,6 +148,24 @@ func TestRun(t *testing.T) {
|
||||
},
|
||||
})
|
||||
|
||||
ctx5 := context.New(config.Project{
|
||||
Dist: dist,
|
||||
UniversalBinaries: []config.UniversalBinary{
|
||||
{
|
||||
ID: "foo",
|
||||
NameTemplate: "foo",
|
||||
Hooks: config.BuildHookConfig{
|
||||
Pre: []config.Hook{
|
||||
{Cmd: "touch " + pre},
|
||||
},
|
||||
Post: []config.Hook{
|
||||
{Cmd: "touch " + post},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
for arch, path := range paths {
|
||||
cmd := exec.Command("go", "build", "-o", path, src)
|
||||
cmd.Env = append(os.Environ(), "GOOS=darwin", "GOARCH="+arch)
|
||||
@ -168,6 +189,7 @@ func TestRun(t *testing.T) {
|
||||
}
|
||||
ctx1.Artifacts.Add(&art)
|
||||
ctx2.Artifacts.Add(&art)
|
||||
ctx5.Artifacts.Add(&art)
|
||||
ctx4.Artifacts.Add(&artifact.Artifact{
|
||||
Name: "fake",
|
||||
Path: path + "wrong",
|
||||
@ -212,6 +234,25 @@ func TestRun(t *testing.T) {
|
||||
t.Run("fail to open", func(t *testing.T) {
|
||||
require.ErrorIs(t, Pipe{}.Run(ctx4), os.ErrNotExist)
|
||||
})
|
||||
|
||||
t.Run("hooks", func(t *testing.T) {
|
||||
require.NoError(t, Pipe{}.Run(ctx5))
|
||||
require.FileExists(t, pre)
|
||||
require.FileExists(t, post)
|
||||
})
|
||||
|
||||
t.Run("failing pre-hook", func(t *testing.T) {
|
||||
ctx := ctx5
|
||||
ctx.Config.UniversalBinaries[0].Hooks.Pre = []config.Hook{{Cmd: "exit 1"}}
|
||||
ctx.Config.UniversalBinaries[0].Hooks.Post = []config.Hook{{Cmd: "echo post"}}
|
||||
require.EqualError(t, Pipe{}.Run(ctx), `pre hook failed: "": exec: "exit": executable file not found in $PATH`)
|
||||
})
|
||||
t.Run("failing post-hook", func(t *testing.T) {
|
||||
ctx := ctx5
|
||||
ctx.Config.UniversalBinaries[0].Hooks.Pre = []config.Hook{{Cmd: "echo pre"}}
|
||||
ctx.Config.UniversalBinaries[0].Hooks.Post = []config.Hook{{Cmd: "exit 1"}}
|
||||
require.EqualError(t, Pipe{}.Run(ctx), `post hook failed: "": exec: "exit": executable file not found in $PATH`)
|
||||
})
|
||||
}
|
||||
|
||||
func checkUniversalBinary(tb testing.TB, unibin *artifact.Artifact) {
|
||||
|
Reference in New Issue
Block a user