You've already forked goreleaser
mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-09-16 09:26:52 +02:00
fix: builds.binary template (#1476)
* 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>
This commit is contained in:
committed by
GitHub
parent
7756891c0e
commit
705ab90e4f
@@ -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,
|
||||
},
|
||||
|
@@ -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
|
||||
@@ -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",
|
||||
@@ -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
|
||||
@@ -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",
|
||||
},
|
||||
},
|
||||
|
@@ -18,10 +18,6 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
var fakeArtifact = &artifact.Artifact{
|
||||
Name: "fake",
|
||||
}
|
||||
|
||||
type fakeBuilder struct {
|
||||
fail bool
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
@@ -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"))
|
||||
|
Reference in New Issue
Block a user