mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-01-06 03:13:48 +02:00
fix: build with same binary name (#1041)
This commit is contained in:
parent
b0630160b0
commit
7ee486fc9b
@ -3,6 +3,7 @@
|
|||||||
package build
|
package build
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -112,7 +113,11 @@ func doBuild(ctx *context.Context, build config.Build, target string) error {
|
|||||||
|
|
||||||
build.Binary = binary
|
build.Binary = binary
|
||||||
var name = build.Binary + ext
|
var name = build.Binary + ext
|
||||||
var path = filepath.Join(ctx.Config.Dist, target, name)
|
var path = filepath.Join(
|
||||||
|
ctx.Config.Dist,
|
||||||
|
fmt.Sprintf("%s_%s", build.ID, target),
|
||||||
|
name,
|
||||||
|
)
|
||||||
log.WithField("binary", path).Info("building")
|
log.WithField("binary", path).Info("building")
|
||||||
return builders.For(build.Lang).Build(ctx, build, builders.Options{
|
return builders.For(build.Lang).Build(ctx, build, builders.Options{
|
||||||
Target: target,
|
Target: target,
|
||||||
|
@ -35,6 +35,12 @@ func (f *fakeBuilder) Build(ctx *context.Context, build config.Build, options ap
|
|||||||
if f.fail {
|
if f.fail {
|
||||||
return errFailedBuild
|
return errFailedBuild
|
||||||
}
|
}
|
||||||
|
if err := os.MkdirAll(filepath.Dir(options.Path), 0755); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := ioutil.WriteFile(options.Path, []byte("foo"), 0755); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
ctx.Artifacts.Add(fakeArtifact)
|
ctx.Artifacts.Add(fakeArtifact)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -51,7 +57,10 @@ func TestPipeDescription(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestBuild(t *testing.T) {
|
func TestBuild(t *testing.T) {
|
||||||
|
folder, back := testlib.Mktmp(t)
|
||||||
|
defer back()
|
||||||
var config = config.Project{
|
var config = config.Project{
|
||||||
|
Dist: folder,
|
||||||
Builds: []config.Build{
|
Builds: []config.Build{
|
||||||
{
|
{
|
||||||
Lang: "fake",
|
Lang: "fake",
|
||||||
@ -75,7 +84,10 @@ func TestBuild(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestRunPipe(t *testing.T) {
|
func TestRunPipe(t *testing.T) {
|
||||||
|
folder, back := testlib.Mktmp(t)
|
||||||
|
defer back()
|
||||||
var config = config.Project{
|
var config = config.Project{
|
||||||
|
Dist: folder,
|
||||||
Builds: []config.Build{
|
Builds: []config.Build{
|
||||||
{
|
{
|
||||||
Lang: "fake",
|
Lang: "fake",
|
||||||
@ -100,6 +112,7 @@ func TestRunFullPipe(t *testing.T) {
|
|||||||
var config = config.Project{
|
var config = config.Project{
|
||||||
Builds: []config.Build{
|
Builds: []config.Build{
|
||||||
{
|
{
|
||||||
|
ID: "build1",
|
||||||
Lang: "fake",
|
Lang: "fake",
|
||||||
Binary: "testing",
|
Binary: "testing",
|
||||||
Flags: []string{"-v"},
|
Flags: []string{"-v"},
|
||||||
@ -111,13 +124,15 @@ func TestRunFullPipe(t *testing.T) {
|
|||||||
Targets: []string{"whatever"},
|
Targets: []string{"whatever"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Dist: folder,
|
||||||
}
|
}
|
||||||
var ctx = context.New(config)
|
var ctx = context.New(config)
|
||||||
ctx.Git.CurrentTag = "2.4.5"
|
ctx.Git.CurrentTag = "2.4.5"
|
||||||
assert.NoError(t, Pipe{}.Run(ctx))
|
assert.NoError(t, Pipe{}.Run(ctx))
|
||||||
assert.Equal(t, ctx.Artifacts.List(), []artifact.Artifact{fakeArtifact})
|
assert.Equal(t, ctx.Artifacts.List(), []artifact.Artifact{fakeArtifact})
|
||||||
assert.True(t, exists(pre), pre)
|
assert.FileExists(t, post)
|
||||||
assert.True(t, exists(post), post)
|
assert.FileExists(t, pre)
|
||||||
|
assert.FileExists(t, filepath.Join(folder, "build1_whatever", "testing"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRunFullPipeFail(t *testing.T) {
|
func TestRunFullPipeFail(t *testing.T) {
|
||||||
@ -126,6 +141,7 @@ func TestRunFullPipeFail(t *testing.T) {
|
|||||||
var pre = filepath.Join(folder, "pre")
|
var pre = filepath.Join(folder, "pre")
|
||||||
var post = filepath.Join(folder, "post")
|
var post = filepath.Join(folder, "post")
|
||||||
var config = config.Project{
|
var config = config.Project{
|
||||||
|
Dist: folder,
|
||||||
Builds: []config.Build{
|
Builds: []config.Build{
|
||||||
{
|
{
|
||||||
Lang: "fakeFail",
|
Lang: "fakeFail",
|
||||||
@ -144,12 +160,14 @@ func TestRunFullPipeFail(t *testing.T) {
|
|||||||
ctx.Git.CurrentTag = "2.4.5"
|
ctx.Git.CurrentTag = "2.4.5"
|
||||||
assert.EqualError(t, Pipe{}.Run(ctx), errFailedBuild.Error())
|
assert.EqualError(t, Pipe{}.Run(ctx), errFailedBuild.Error())
|
||||||
assert.Empty(t, ctx.Artifacts.List())
|
assert.Empty(t, ctx.Artifacts.List())
|
||||||
assert.True(t, exists(pre), pre)
|
assert.FileExists(t, pre)
|
||||||
assert.False(t, exists(post), post)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRunPipeFailingHooks(t *testing.T) {
|
func TestRunPipeFailingHooks(t *testing.T) {
|
||||||
|
folder, back := testlib.Mktmp(t)
|
||||||
|
defer back()
|
||||||
var config = config.Project{
|
var config = config.Project{
|
||||||
|
Dist: folder,
|
||||||
Builds: []config.Build{
|
Builds: []config.Build{
|
||||||
{
|
{
|
||||||
Lang: "fake",
|
Lang: "fake",
|
||||||
@ -345,7 +363,7 @@ func TestHookEnvs(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}), build.Env, "touch {{ .Env.FOO }}")
|
}), build.Env, "touch {{ .Env.FOO }}")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.True(t, exists(filepath.Join(tmp, "foo")))
|
assert.FileExists(t, filepath.Join(tmp, "foo"))
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("invalid template", func(t *testing.T) {
|
t.Run("invalid template", func(t *testing.T) {
|
||||||
@ -368,15 +386,6 @@ touch "$BAR"`
|
|||||||
},
|
},
|
||||||
}), build.Env, "sh test.sh")
|
}), build.Env, "sh test.sh")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.True(t, exists(filepath.Join(tmp, "bar")))
|
assert.FileExists(t, filepath.Join(tmp, "bar"))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
// Helpers
|
|
||||||
//
|
|
||||||
|
|
||||||
func exists(file string) bool {
|
|
||||||
_, err := os.Stat(file)
|
|
||||||
return !os.IsNotExist(err)
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user