1
0
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:
Carlos Alexandro Becker 2019-06-09 12:14:30 -03:00 committed by GitHub
parent b0630160b0
commit 7ee486fc9b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 16 deletions

View File

@ -3,6 +3,7 @@
package build
import (
"fmt"
"os"
"os/exec"
"path/filepath"
@ -112,7 +113,11 @@ func doBuild(ctx *context.Context, build config.Build, target string) error {
build.Binary = binary
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")
return builders.For(build.Lang).Build(ctx, build, builders.Options{
Target: target,

View File

@ -35,6 +35,12 @@ func (f *fakeBuilder) Build(ctx *context.Context, build config.Build, options ap
if f.fail {
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)
return nil
}
@ -51,7 +57,10 @@ func TestPipeDescription(t *testing.T) {
}
func TestBuild(t *testing.T) {
folder, back := testlib.Mktmp(t)
defer back()
var config = config.Project{
Dist: folder,
Builds: []config.Build{
{
Lang: "fake",
@ -75,7 +84,10 @@ func TestBuild(t *testing.T) {
}
func TestRunPipe(t *testing.T) {
folder, back := testlib.Mktmp(t)
defer back()
var config = config.Project{
Dist: folder,
Builds: []config.Build{
{
Lang: "fake",
@ -100,6 +112,7 @@ func TestRunFullPipe(t *testing.T) {
var config = config.Project{
Builds: []config.Build{
{
ID: "build1",
Lang: "fake",
Binary: "testing",
Flags: []string{"-v"},
@ -111,13 +124,15 @@ func TestRunFullPipe(t *testing.T) {
Targets: []string{"whatever"},
},
},
Dist: folder,
}
var ctx = context.New(config)
ctx.Git.CurrentTag = "2.4.5"
assert.NoError(t, Pipe{}.Run(ctx))
assert.Equal(t, ctx.Artifacts.List(), []artifact.Artifact{fakeArtifact})
assert.True(t, exists(pre), pre)
assert.True(t, exists(post), post)
assert.FileExists(t, post)
assert.FileExists(t, pre)
assert.FileExists(t, filepath.Join(folder, "build1_whatever", "testing"))
}
func TestRunFullPipeFail(t *testing.T) {
@ -126,6 +141,7 @@ func TestRunFullPipeFail(t *testing.T) {
var pre = filepath.Join(folder, "pre")
var post = filepath.Join(folder, "post")
var config = config.Project{
Dist: folder,
Builds: []config.Build{
{
Lang: "fakeFail",
@ -144,12 +160,14 @@ func TestRunFullPipeFail(t *testing.T) {
ctx.Git.CurrentTag = "2.4.5"
assert.EqualError(t, Pipe{}.Run(ctx), errFailedBuild.Error())
assert.Empty(t, ctx.Artifacts.List())
assert.True(t, exists(pre), pre)
assert.False(t, exists(post), post)
assert.FileExists(t, pre)
}
func TestRunPipeFailingHooks(t *testing.T) {
folder, back := testlib.Mktmp(t)
defer back()
var config = config.Project{
Dist: folder,
Builds: []config.Build{
{
Lang: "fake",
@ -345,7 +363,7 @@ func TestHookEnvs(t *testing.T) {
},
}), build.Env, "touch {{ .Env.FOO }}")
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) {
@ -368,15 +386,6 @@ touch "$BAR"`
},
}), build.Env, "sh test.sh")
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)
}