1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-10-30 23:58:09 +02:00

fix: build.binary and artifact.extra.binary (#1399)

* fix: build.binary and artifact.extra.id

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

* fix: scoop usage of extra[binary]

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

* fix: unlock
This commit is contained in:
Carlos Alexandro Becker
2020-03-28 15:40:16 -03:00
committed by GitHub
parent 93d134bda8
commit fa608c302e
6 changed files with 49 additions and 51 deletions

View File

@@ -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": build.Binary,
"Binary": filepath.Base(build.Binary),
"Ext": options.Ext,
"ID": build.ID,
},

View File

@@ -91,7 +91,7 @@ func TestBuild(t *testing.T) {
{
ID: "foo",
Env: []string{"GO111MODULE=off"},
Binary: "foo",
Binary: "bin/foo",
Targets: []string{
"linux_amd64",
"darwin_amd64",
@@ -129,8 +129,8 @@ func TestBuild(t *testing.T) {
}
assert.ElementsMatch(t, ctx.Artifacts.List(), []*artifact.Artifact{
{
Name: "foo",
Path: filepath.Join(folder, "dist", "linux_amd64", "foo"),
Name: "bin/foo",
Path: filepath.Join(folder, "dist", "linux_amd64", "bin", "foo"),
Goos: "linux",
Goarch: "amd64",
Type: artifact.Binary,
@@ -141,8 +141,8 @@ func TestBuild(t *testing.T) {
},
},
{
Name: "foo",
Path: filepath.Join(folder, "dist", "linux_mips_softfloat", "foo"),
Name: "bin/foo",
Path: filepath.Join(folder, "dist", "linux_mips_softfloat", "bin", "foo"),
Goos: "linux",
Goarch: "mips",
Gomips: "softfloat",
@@ -154,8 +154,8 @@ func TestBuild(t *testing.T) {
},
},
{
Name: "foo",
Path: filepath.Join(folder, "dist", "linux_mips64le_softfloat", "foo"),
Name: "bin/foo",
Path: filepath.Join(folder, "dist", "linux_mips64le_softfloat", "bin", "foo"),
Goos: "linux",
Goarch: "mips64le",
Gomips: "softfloat",
@@ -167,8 +167,8 @@ func TestBuild(t *testing.T) {
},
},
{
Name: "foo",
Path: filepath.Join(folder, "dist", "darwin_amd64", "foo"),
Name: "bin/foo",
Path: filepath.Join(folder, "dist", "darwin_amd64", "bin", "foo"),
Goos: "darwin",
Goarch: "amd64",
Type: artifact.Binary,
@@ -179,8 +179,8 @@ func TestBuild(t *testing.T) {
},
},
{
Name: "foo",
Path: filepath.Join(folder, "dist", "linux_arm_6", "foo"),
Name: "bin/foo",
Path: filepath.Join(folder, "dist", "linux_arm_6", "bin", "foo"),
Goos: "linux",
Goarch: "arm",
Goarm: "6",
@@ -192,8 +192,8 @@ func TestBuild(t *testing.T) {
},
},
{
Name: "foo",
Path: filepath.Join(folder, "dist", "windows_amd64", "foo"),
Name: "bin/foo",
Path: filepath.Join(folder, "dist", "windows_amd64", "bin", "foo"),
Goos: "windows",
Goarch: "amd64",
Type: artifact.Binary,
@@ -204,8 +204,8 @@ func TestBuild(t *testing.T) {
},
},
{
Name: "foo",
Path: filepath.Join(folder, "dist", "js_wasm", "foo"),
Name: "bin/foo",
Path: filepath.Join(folder, "dist", "js_wasm", "bin", "foo"),
Goos: "js",
Goarch: "wasm",
Type: artifact.Binary,

View File

@@ -117,6 +117,10 @@ func create(ctx *context.Context, archive config.Archive, binaries []*artifact.A
}
archivePath := filepath.Join(ctx.Config.Dist, folder+"."+format)
lock.Lock()
if err := os.MkdirAll(filepath.Dir(archivePath), 0755|os.ModeDir); err != nil {
lock.Unlock()
return err
}
if _, err = os.Stat(archivePath); !os.IsNotExist(err) {
lock.Unlock()
return fmt.Errorf("archive named %s already exists. Check your archive name template", archivePath)

View File

@@ -24,8 +24,9 @@ func TestDescription(t *testing.T) {
}
func createFakeBinary(t *testing.T, dist, arch, bin string) {
require.NoError(t, os.Mkdir(filepath.Join(dist, arch), 0755))
_, err := os.Create(filepath.Join(dist, arch, bin))
var path = filepath.Join(dist, arch, bin)
require.NoError(t, os.MkdirAll(filepath.Dir(path), 0755))
_, err := os.Create(path)
require.NoError(t, err)
}
@@ -37,9 +38,9 @@ func TestRunPipe(t *testing.T) {
var dist = filepath.Join(folder, format+"_dist")
require.NoError(t, os.Mkdir(dist, 0755))
for _, arch := range []string{"darwinamd64", "linux386", "linuxarm7", "linuxmipssoftfloat"} {
createFakeBinary(t, dist, arch, "mybin")
createFakeBinary(t, dist, arch, "bin/mybin")
}
createFakeBinary(t, dist, "windowsamd64", "mybin.exe")
createFakeBinary(t, dist, "windowsamd64", "bin/mybin.exe")
for _, tt := range []string{"darwin", "linux", "windows"} {
_, err := os.Create(filepath.Join(folder, fmt.Sprintf("README.%s.md", tt)))
require.NoError(t, err)
@@ -73,22 +74,22 @@ func TestRunPipe(t *testing.T) {
var darwinBuild = &artifact.Artifact{
Goos: "darwin",
Goarch: "amd64",
Name: "mybin",
Path: filepath.Join(dist, "darwinamd64", "mybin"),
Name: "bin/mybin",
Path: filepath.Join(dist, "darwinamd64", "bin", "mybin"),
Type: artifact.Binary,
Extra: map[string]interface{}{
"Binary": "mybin",
"Binary": "bin/mybin",
"ID": "default",
},
}
var linux386Build = &artifact.Artifact{
Goos: "linux",
Goarch: "386",
Name: "mybin",
Path: filepath.Join(dist, "linux386", "mybin"),
Name: "bin/mybin",
Path: filepath.Join(dist, "linux386", "bin", "mybin"),
Type: artifact.Binary,
Extra: map[string]interface{}{
"Binary": "mybin",
"Binary": "bin/mybin",
"ID": "default",
},
}
@@ -96,11 +97,11 @@ func TestRunPipe(t *testing.T) {
Goos: "linux",
Goarch: "arm",
Goarm: "7",
Name: "mybin",
Path: filepath.Join(dist, "linuxarm7", "mybin"),
Name: "bin/mybin",
Path: filepath.Join(dist, "linuxarm7", "bin", "mybin"),
Type: artifact.Binary,
Extra: map[string]interface{}{
"Binary": "mybin",
"Binary": "bin/mybin",
"ID": "default",
},
}
@@ -108,8 +109,8 @@ func TestRunPipe(t *testing.T) {
Goos: "linux",
Goarch: "mips",
Gomips: "softfloat",
Name: "mybin",
Path: filepath.Join(dist, "linuxmipssoftfloat", "mybin"),
Name: "bin/mybin",
Path: filepath.Join(dist, "linuxmipssoftfloat", "bin", "mybin"),
Type: artifact.Binary,
Extra: map[string]interface{}{
"Binary": "mybin",
@@ -119,8 +120,8 @@ func TestRunPipe(t *testing.T) {
var windowsBuild = &artifact.Artifact{
Goos: "windows",
Goarch: "amd64",
Name: "mybin.exe",
Path: filepath.Join(dist, "windowsamd64", "mybin.exe"),
Name: "bin/mybin.exe",
Path: filepath.Join(dist, "windowsamd64", "bin", "mybin.exe"),
Type: artifact.Binary,
Extra: map[string]interface{}{
"Binary": "mybin",
@@ -159,7 +160,7 @@ func TestRunPipe(t *testing.T) {
"foo/bar",
"foo/bar/foobar",
"foo/bar/foobar/blah.txt",
"mybin",
"bin/mybin",
},
tarFiles(t, filepath.Join(dist, name)),
)
@@ -171,7 +172,7 @@ func TestRunPipe(t *testing.T) {
[]string{
"README.windows.md",
"foo/bar/foobar/blah.txt",
"mybin.exe",
"bin/mybin.exe",
},
zipFiles(t, filepath.Join(dist, "foobar_0.0.1_windows_amd64.zip")),
)
@@ -276,7 +277,7 @@ func TestRunPipeBinary(t *testing.T) {
func TestRunPipeDistRemoved(t *testing.T) {
var ctx = context.New(
config.Project{
Dist: "/path/nope",
Dist: "/tmp/path/to/nope",
Archives: []config.Archive{
{
NameTemplate: "nope",
@@ -291,7 +292,7 @@ func TestRunPipeDistRemoved(t *testing.T) {
Goos: "windows",
Goarch: "amd64",
Name: "mybin.exe",
Path: filepath.Join("/path/to/nope", "windowsamd64", "mybin.exe"),
Path: filepath.Join("/tmp/path/to/nope", "windowsamd64", "mybin.exe"),
Type: artifact.Binary,
Extra: map[string]interface{}{
"Binary": "mybin",
@@ -299,7 +300,8 @@ func TestRunPipeDistRemoved(t *testing.T) {
"ID": "default",
},
})
require.EqualError(t, Pipe{}.Run(ctx), `failed to create directory /path/nope/nope.zip: open /path/nope/nope.zip: no such file or directory`)
// not checking on error msg because it may change depending on OS/version
require.Error(t, Pipe{}.Run(ctx))
}
func TestRunPipeInvalidGlob(t *testing.T) {

View File

@@ -196,7 +196,7 @@ func binaries(a *artifact.Artifact) []string {
// nolint: prealloc
var bins []string
for _, b := range a.ExtraOr("Builds", []*artifact.Artifact{}).([]*artifact.Artifact) {
bins = append(bins, b.ExtraOr("Binary", "").(string)+".exe")
bins = append(bins, b.Name+".exe")
}
return bins
}

View File

@@ -825,14 +825,10 @@ func Test_buildManifest(t *testing.T) {
"ArtifactUploadHash": "820ead5d9d2266c728dce6d4d55b6460",
"Builds": []*artifact.Artifact{
{
Extra: map[string]interface{}{
"Binary": "foo",
},
Name: "foo",
},
{
Extra: map[string]interface{}{
"Binary": "bar",
},
Name: "bar",
},
},
},
@@ -846,14 +842,10 @@ func Test_buildManifest(t *testing.T) {
"ArtifactUploadHash": "820ead5d9d2266c728dce6d4d55b6460",
"Builds": []*artifact.Artifact{
{
Extra: map[string]interface{}{
"Binary": "foo",
},
Name: "foo",
},
{
Extra: map[string]interface{}{
"Binary": "bar",
},
Name: "bar",
},
},
},