Skip to content

Commit

Permalink
fix: builds.binary template (#1476)
Browse files Browse the repository at this point in the history
* fix: builds.binary template

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: revert

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: tests

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>
  • Loading branch information
caarlos0 committed Apr 29, 2020
1 parent 7756891 commit 705ab90
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 32 deletions.
2 changes: 1 addition & 1 deletion internal/builders/golang/build.go
Expand Up @@ -81,7 +81,7 @@ func (*Builder) Build(ctx *context.Context, build config.Build, options api.Opti
Goarm: target.arm,
Gomips: target.mips,
Extra: map[string]interface{}{
"Binary": filepath.Base(build.Binary),
"Binary": filepath.Base(options.Path),
"Ext": options.Ext,
"ID": build.ID,
},
Expand Down
52 changes: 28 additions & 24 deletions internal/builders/golang/build_test.go
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/goreleaser/goreleaser/pkg/config"
"github.com/goreleaser/goreleaser/pkg/context"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

var runtimeTarget = runtime.GOOS + "_" + runtime.GOARCH
Expand Down Expand Up @@ -91,7 +92,7 @@ func TestBuild(t *testing.T) {
{
ID: "foo",
Env: []string{"GO111MODULE=off"},
Binary: "bin/foo",
Binary: "bin/foo-{{ .Version }}",
Targets: []string{
"linux_amd64",
"darwin_amd64",
Expand All @@ -110,6 +111,7 @@ func TestBuild(t *testing.T) {
var ctx = context.New(config)
ctx.Env["GO_FLAGS"] = "-v"
ctx.Git.CurrentTag = "5.6.7"
ctx.Version = "v" + ctx.Git.CurrentTag
var build = ctx.Config.Builds[0]
for _, target := range build.Targets {
var ext string
Expand All @@ -119,99 +121,101 @@ func TestBuild(t *testing.T) {
if target == "js_wasm" {
ext = ".wasm"
}
bin, terr := tmpl.New(ctx).Apply(build.Binary)
require.NoError(t, terr)
var err = Default.Build(ctx, build, api.Options{
Target: target,
Name: build.Binary,
Path: filepath.Join(folder, "dist", target, build.Binary),
Name: bin,
Path: filepath.Join(folder, "dist", target, bin),
Ext: ext,
})
assert.NoError(t, err)
}
assert.ElementsMatch(t, ctx.Artifacts.List(), []*artifact.Artifact{
{
Name: "bin/foo",
Path: filepath.Join(folder, "dist", "linux_amd64", "bin", "foo"),
Name: "bin/foo-v5.6.7",
Path: filepath.Join(folder, "dist", "linux_amd64", "bin", "foo-v5.6.7"),
Goos: "linux",
Goarch: "amd64",
Type: artifact.Binary,
Extra: map[string]interface{}{
"Ext": "",
"Binary": "foo",
"Binary": "foo-v5.6.7",
"ID": "foo",
},
},
{
Name: "bin/foo",
Path: filepath.Join(folder, "dist", "linux_mips_softfloat", "bin", "foo"),
Name: "bin/foo-v5.6.7",
Path: filepath.Join(folder, "dist", "linux_mips_softfloat", "bin", "foo-v5.6.7"),
Goos: "linux",
Goarch: "mips",
Gomips: "softfloat",
Type: artifact.Binary,
Extra: map[string]interface{}{
"Ext": "",
"Binary": "foo",
"Binary": "foo-v5.6.7",
"ID": "foo",
},
},
{
Name: "bin/foo",
Path: filepath.Join(folder, "dist", "linux_mips64le_softfloat", "bin", "foo"),
Name: "bin/foo-v5.6.7",
Path: filepath.Join(folder, "dist", "linux_mips64le_softfloat", "bin", "foo-v5.6.7"),
Goos: "linux",
Goarch: "mips64le",
Gomips: "softfloat",
Type: artifact.Binary,
Extra: map[string]interface{}{
"Ext": "",
"Binary": "foo",
"Binary": "foo-v5.6.7",
"ID": "foo",
},
},
{
Name: "bin/foo",
Path: filepath.Join(folder, "dist", "darwin_amd64", "bin", "foo"),
Name: "bin/foo-v5.6.7",
Path: filepath.Join(folder, "dist", "darwin_amd64", "bin", "foo-v5.6.7"),
Goos: "darwin",
Goarch: "amd64",
Type: artifact.Binary,
Extra: map[string]interface{}{
"Ext": "",
"Binary": "foo",
"Binary": "foo-v5.6.7",
"ID": "foo",
},
},
{
Name: "bin/foo",
Path: filepath.Join(folder, "dist", "linux_arm_6", "bin", "foo"),
Name: "bin/foo-v5.6.7",
Path: filepath.Join(folder, "dist", "linux_arm_6", "bin", "foo-v5.6.7"),
Goos: "linux",
Goarch: "arm",
Goarm: "6",
Type: artifact.Binary,
Extra: map[string]interface{}{
"Ext": "",
"Binary": "foo",
"Binary": "foo-v5.6.7",
"ID": "foo",
},
},
{
Name: "bin/foo",
Path: filepath.Join(folder, "dist", "windows_amd64", "bin", "foo"),
Name: "bin/foo-v5.6.7",
Path: filepath.Join(folder, "dist", "windows_amd64", "bin", "foo-v5.6.7"),
Goos: "windows",
Goarch: "amd64",
Type: artifact.Binary,
Extra: map[string]interface{}{
"Ext": ".exe",
"Binary": "foo",
"Binary": "foo-v5.6.7",
"ID": "foo",
},
},
{
Name: "bin/foo",
Path: filepath.Join(folder, "dist", "js_wasm", "bin", "foo"),
Name: "bin/foo-v5.6.7",
Path: filepath.Join(folder, "dist", "js_wasm", "bin", "foo-v5.6.7"),
Goos: "js",
Goarch: "wasm",
Type: artifact.Binary,
Extra: map[string]interface{}{
"Ext": ".wasm",
"Binary": "foo",
"Binary": "foo-v5.6.7",
"ID": "foo",
},
},
Expand Down
16 changes: 9 additions & 7 deletions internal/pipe/build/build_test.go
Expand Up @@ -18,10 +18,6 @@ import (
"github.com/stretchr/testify/require"
)

var fakeArtifact = &artifact.Artifact{
Name: "fake",
}

type fakeBuilder struct {
fail bool
}
Expand All @@ -42,7 +38,9 @@ func (f *fakeBuilder) Build(ctx *context.Context, build config.Build, options ap
if err := ioutil.WriteFile(options.Path, []byte("foo"), 0755); err != nil {
return err
}
ctx.Artifacts.Add(fakeArtifact)
ctx.Artifacts.Add(&artifact.Artifact{
Name: options.Name,
})
return nil
}

Expand Down Expand Up @@ -104,7 +102,9 @@ func TestRunPipe(t *testing.T) {
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.Equal(t, ctx.Artifacts.List(), []*artifact.Artifact{{
Name: "testing",
}})
}

func TestRunFullPipe(t *testing.T) {
Expand Down Expand Up @@ -136,7 +136,9 @@ func TestRunFullPipe(t *testing.T) {
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.Equal(t, ctx.Artifacts.List(), []*artifact.Artifact{{
Name: "testing",
}})
assert.FileExists(t, post)
assert.FileExists(t, pre)
assert.FileExists(t, filepath.Join(folder, "build1_whatever", "testing"))
Expand Down

0 comments on commit 705ab90

Please sign in to comment.