Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from Mar 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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": build.Binary,
"Binary": filepath.Base(build.Binary),
"Ext": options.Ext,
"ID": build.ID,
},
Expand Down
30 changes: 15 additions & 15 deletions internal/builders/golang/build_test.go
Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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,
Expand All @@ -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",
Expand All @@ -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,
Expand All @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions internal/pipe/archive/archive.go
Expand Up @@ -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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey, I think you missed lock.Unlock() here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

}
if _, err = os.Stat(archivePath); !os.IsNotExist(err) {
lock.Unlock()
return fmt.Errorf("archive named %s already exists. Check your archive name template", archivePath)
Expand Down
46 changes: 24 additions & 22 deletions internal/pipe/archive/archive_test.go
Expand Up @@ -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)
}

Expand All @@ -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)
Expand Down Expand Up @@ -73,43 +74,43 @@ 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",
},
}
var linuxArmBuild = &artifact.Artifact{
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",
},
}
var linuxMipsBuild = &artifact.Artifact{
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",
Expand All @@ -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",
Expand Down Expand Up @@ -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)),
)
Expand All @@ -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")),
)
Expand Down Expand Up @@ -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",
Expand All @@ -291,15 +292,16 @@ 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",
"Extension": ".exe",
"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) {
Expand Down
2 changes: 1 addition & 1 deletion internal/pipe/scoop/scoop.go
Expand Up @@ -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
}
16 changes: 4 additions & 12 deletions internal/pipe/scoop/scoop_test.go
Expand Up @@ -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",
},
},
},
Expand All @@ -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",
},
},
},
Expand Down