You've already forked goreleaser
							
							
				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:
		
				
					committed by
					
						 GitHub
						GitHub
					
				
			
			
				
	
			
			
			
						parent
						
							93d134bda8
						
					
				
				
					commit
					fa608c302e
				
			| @@ -81,7 +81,7 @@ func (*Builder) Build(ctx *context.Context, build config.Build, options api.Opti | |||||||
| 		Goarm:  target.arm, | 		Goarm:  target.arm, | ||||||
| 		Gomips: target.mips, | 		Gomips: target.mips, | ||||||
| 		Extra: map[string]interface{}{ | 		Extra: map[string]interface{}{ | ||||||
| 			"Binary": build.Binary, | 			"Binary": filepath.Base(build.Binary), | ||||||
| 			"Ext":    options.Ext, | 			"Ext":    options.Ext, | ||||||
| 			"ID":     build.ID, | 			"ID":     build.ID, | ||||||
| 		}, | 		}, | ||||||
|   | |||||||
| @@ -91,7 +91,7 @@ func TestBuild(t *testing.T) { | |||||||
| 			{ | 			{ | ||||||
| 				ID:     "foo", | 				ID:     "foo", | ||||||
| 				Env:    []string{"GO111MODULE=off"}, | 				Env:    []string{"GO111MODULE=off"}, | ||||||
| 				Binary: "foo", | 				Binary: "bin/foo", | ||||||
| 				Targets: []string{ | 				Targets: []string{ | ||||||
| 					"linux_amd64", | 					"linux_amd64", | ||||||
| 					"darwin_amd64", | 					"darwin_amd64", | ||||||
| @@ -129,8 +129,8 @@ func TestBuild(t *testing.T) { | |||||||
| 	} | 	} | ||||||
| 	assert.ElementsMatch(t, ctx.Artifacts.List(), []*artifact.Artifact{ | 	assert.ElementsMatch(t, ctx.Artifacts.List(), []*artifact.Artifact{ | ||||||
| 		{ | 		{ | ||||||
| 			Name:   "foo", | 			Name:   "bin/foo", | ||||||
| 			Path:   filepath.Join(folder, "dist", "linux_amd64", "foo"), | 			Path:   filepath.Join(folder, "dist", "linux_amd64", "bin", "foo"), | ||||||
| 			Goos:   "linux", | 			Goos:   "linux", | ||||||
| 			Goarch: "amd64", | 			Goarch: "amd64", | ||||||
| 			Type:   artifact.Binary, | 			Type:   artifact.Binary, | ||||||
| @@ -141,8 +141,8 @@ func TestBuild(t *testing.T) { | |||||||
| 			}, | 			}, | ||||||
| 		}, | 		}, | ||||||
| 		{ | 		{ | ||||||
| 			Name:   "foo", | 			Name:   "bin/foo", | ||||||
| 			Path:   filepath.Join(folder, "dist", "linux_mips_softfloat", "foo"), | 			Path:   filepath.Join(folder, "dist", "linux_mips_softfloat", "bin", "foo"), | ||||||
| 			Goos:   "linux", | 			Goos:   "linux", | ||||||
| 			Goarch: "mips", | 			Goarch: "mips", | ||||||
| 			Gomips: "softfloat", | 			Gomips: "softfloat", | ||||||
| @@ -154,8 +154,8 @@ func TestBuild(t *testing.T) { | |||||||
| 			}, | 			}, | ||||||
| 		}, | 		}, | ||||||
| 		{ | 		{ | ||||||
| 			Name:   "foo", | 			Name:   "bin/foo", | ||||||
| 			Path:   filepath.Join(folder, "dist", "linux_mips64le_softfloat", "foo"), | 			Path:   filepath.Join(folder, "dist", "linux_mips64le_softfloat", "bin", "foo"), | ||||||
| 			Goos:   "linux", | 			Goos:   "linux", | ||||||
| 			Goarch: "mips64le", | 			Goarch: "mips64le", | ||||||
| 			Gomips: "softfloat", | 			Gomips: "softfloat", | ||||||
| @@ -167,8 +167,8 @@ func TestBuild(t *testing.T) { | |||||||
| 			}, | 			}, | ||||||
| 		}, | 		}, | ||||||
| 		{ | 		{ | ||||||
| 			Name:   "foo", | 			Name:   "bin/foo", | ||||||
| 			Path:   filepath.Join(folder, "dist", "darwin_amd64", "foo"), | 			Path:   filepath.Join(folder, "dist", "darwin_amd64", "bin", "foo"), | ||||||
| 			Goos:   "darwin", | 			Goos:   "darwin", | ||||||
| 			Goarch: "amd64", | 			Goarch: "amd64", | ||||||
| 			Type:   artifact.Binary, | 			Type:   artifact.Binary, | ||||||
| @@ -179,8 +179,8 @@ func TestBuild(t *testing.T) { | |||||||
| 			}, | 			}, | ||||||
| 		}, | 		}, | ||||||
| 		{ | 		{ | ||||||
| 			Name:   "foo", | 			Name:   "bin/foo", | ||||||
| 			Path:   filepath.Join(folder, "dist", "linux_arm_6", "foo"), | 			Path:   filepath.Join(folder, "dist", "linux_arm_6", "bin", "foo"), | ||||||
| 			Goos:   "linux", | 			Goos:   "linux", | ||||||
| 			Goarch: "arm", | 			Goarch: "arm", | ||||||
| 			Goarm:  "6", | 			Goarm:  "6", | ||||||
| @@ -192,8 +192,8 @@ func TestBuild(t *testing.T) { | |||||||
| 			}, | 			}, | ||||||
| 		}, | 		}, | ||||||
| 		{ | 		{ | ||||||
| 			Name:   "foo", | 			Name:   "bin/foo", | ||||||
| 			Path:   filepath.Join(folder, "dist", "windows_amd64", "foo"), | 			Path:   filepath.Join(folder, "dist", "windows_amd64", "bin", "foo"), | ||||||
| 			Goos:   "windows", | 			Goos:   "windows", | ||||||
| 			Goarch: "amd64", | 			Goarch: "amd64", | ||||||
| 			Type:   artifact.Binary, | 			Type:   artifact.Binary, | ||||||
| @@ -204,8 +204,8 @@ func TestBuild(t *testing.T) { | |||||||
| 			}, | 			}, | ||||||
| 		}, | 		}, | ||||||
| 		{ | 		{ | ||||||
| 			Name:   "foo", | 			Name:   "bin/foo", | ||||||
| 			Path:   filepath.Join(folder, "dist", "js_wasm", "foo"), | 			Path:   filepath.Join(folder, "dist", "js_wasm", "bin", "foo"), | ||||||
| 			Goos:   "js", | 			Goos:   "js", | ||||||
| 			Goarch: "wasm", | 			Goarch: "wasm", | ||||||
| 			Type:   artifact.Binary, | 			Type:   artifact.Binary, | ||||||
|   | |||||||
| @@ -117,6 +117,10 @@ func create(ctx *context.Context, archive config.Archive, binaries []*artifact.A | |||||||
| 	} | 	} | ||||||
| 	archivePath := filepath.Join(ctx.Config.Dist, folder+"."+format) | 	archivePath := filepath.Join(ctx.Config.Dist, folder+"."+format) | ||||||
| 	lock.Lock() | 	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) { | 	if _, err = os.Stat(archivePath); !os.IsNotExist(err) { | ||||||
| 		lock.Unlock() | 		lock.Unlock() | ||||||
| 		return fmt.Errorf("archive named %s already exists. Check your archive name template", archivePath) | 		return fmt.Errorf("archive named %s already exists. Check your archive name template", archivePath) | ||||||
|   | |||||||
| @@ -24,8 +24,9 @@ func TestDescription(t *testing.T) { | |||||||
| } | } | ||||||
|  |  | ||||||
| func createFakeBinary(t *testing.T, dist, arch, bin string) { | func createFakeBinary(t *testing.T, dist, arch, bin string) { | ||||||
| 	require.NoError(t, os.Mkdir(filepath.Join(dist, arch), 0755)) | 	var path = filepath.Join(dist, arch, bin) | ||||||
| 	_, err := os.Create(filepath.Join(dist, arch, bin)) | 	require.NoError(t, os.MkdirAll(filepath.Dir(path), 0755)) | ||||||
|  | 	_, err := os.Create(path) | ||||||
| 	require.NoError(t, err) | 	require.NoError(t, err) | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -37,9 +38,9 @@ func TestRunPipe(t *testing.T) { | |||||||
| 			var dist = filepath.Join(folder, format+"_dist") | 			var dist = filepath.Join(folder, format+"_dist") | ||||||
| 			require.NoError(t, os.Mkdir(dist, 0755)) | 			require.NoError(t, os.Mkdir(dist, 0755)) | ||||||
| 			for _, arch := range []string{"darwinamd64", "linux386", "linuxarm7", "linuxmipssoftfloat"} { | 			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"} { | 			for _, tt := range []string{"darwin", "linux", "windows"} { | ||||||
| 				_, err := os.Create(filepath.Join(folder, fmt.Sprintf("README.%s.md", tt))) | 				_, err := os.Create(filepath.Join(folder, fmt.Sprintf("README.%s.md", tt))) | ||||||
| 				require.NoError(t, err) | 				require.NoError(t, err) | ||||||
| @@ -73,22 +74,22 @@ func TestRunPipe(t *testing.T) { | |||||||
| 			var darwinBuild = &artifact.Artifact{ | 			var darwinBuild = &artifact.Artifact{ | ||||||
| 				Goos:   "darwin", | 				Goos:   "darwin", | ||||||
| 				Goarch: "amd64", | 				Goarch: "amd64", | ||||||
| 				Name:   "mybin", | 				Name:   "bin/mybin", | ||||||
| 				Path:   filepath.Join(dist, "darwinamd64", "mybin"), | 				Path:   filepath.Join(dist, "darwinamd64", "bin", "mybin"), | ||||||
| 				Type:   artifact.Binary, | 				Type:   artifact.Binary, | ||||||
| 				Extra: map[string]interface{}{ | 				Extra: map[string]interface{}{ | ||||||
| 					"Binary": "mybin", | 					"Binary": "bin/mybin", | ||||||
| 					"ID":     "default", | 					"ID":     "default", | ||||||
| 				}, | 				}, | ||||||
| 			} | 			} | ||||||
| 			var linux386Build = &artifact.Artifact{ | 			var linux386Build = &artifact.Artifact{ | ||||||
| 				Goos:   "linux", | 				Goos:   "linux", | ||||||
| 				Goarch: "386", | 				Goarch: "386", | ||||||
| 				Name:   "mybin", | 				Name:   "bin/mybin", | ||||||
| 				Path:   filepath.Join(dist, "linux386", "mybin"), | 				Path:   filepath.Join(dist, "linux386", "bin", "mybin"), | ||||||
| 				Type:   artifact.Binary, | 				Type:   artifact.Binary, | ||||||
| 				Extra: map[string]interface{}{ | 				Extra: map[string]interface{}{ | ||||||
| 					"Binary": "mybin", | 					"Binary": "bin/mybin", | ||||||
| 					"ID":     "default", | 					"ID":     "default", | ||||||
| 				}, | 				}, | ||||||
| 			} | 			} | ||||||
| @@ -96,11 +97,11 @@ func TestRunPipe(t *testing.T) { | |||||||
| 				Goos:   "linux", | 				Goos:   "linux", | ||||||
| 				Goarch: "arm", | 				Goarch: "arm", | ||||||
| 				Goarm:  "7", | 				Goarm:  "7", | ||||||
| 				Name:   "mybin", | 				Name:   "bin/mybin", | ||||||
| 				Path:   filepath.Join(dist, "linuxarm7", "mybin"), | 				Path:   filepath.Join(dist, "linuxarm7", "bin", "mybin"), | ||||||
| 				Type:   artifact.Binary, | 				Type:   artifact.Binary, | ||||||
| 				Extra: map[string]interface{}{ | 				Extra: map[string]interface{}{ | ||||||
| 					"Binary": "mybin", | 					"Binary": "bin/mybin", | ||||||
| 					"ID":     "default", | 					"ID":     "default", | ||||||
| 				}, | 				}, | ||||||
| 			} | 			} | ||||||
| @@ -108,8 +109,8 @@ func TestRunPipe(t *testing.T) { | |||||||
| 				Goos:   "linux", | 				Goos:   "linux", | ||||||
| 				Goarch: "mips", | 				Goarch: "mips", | ||||||
| 				Gomips: "softfloat", | 				Gomips: "softfloat", | ||||||
| 				Name:   "mybin", | 				Name:   "bin/mybin", | ||||||
| 				Path:   filepath.Join(dist, "linuxmipssoftfloat", "mybin"), | 				Path:   filepath.Join(dist, "linuxmipssoftfloat", "bin", "mybin"), | ||||||
| 				Type:   artifact.Binary, | 				Type:   artifact.Binary, | ||||||
| 				Extra: map[string]interface{}{ | 				Extra: map[string]interface{}{ | ||||||
| 					"Binary": "mybin", | 					"Binary": "mybin", | ||||||
| @@ -119,8 +120,8 @@ func TestRunPipe(t *testing.T) { | |||||||
| 			var windowsBuild = &artifact.Artifact{ | 			var windowsBuild = &artifact.Artifact{ | ||||||
| 				Goos:   "windows", | 				Goos:   "windows", | ||||||
| 				Goarch: "amd64", | 				Goarch: "amd64", | ||||||
| 				Name:   "mybin.exe", | 				Name:   "bin/mybin.exe", | ||||||
| 				Path:   filepath.Join(dist, "windowsamd64", "mybin.exe"), | 				Path:   filepath.Join(dist, "windowsamd64", "bin", "mybin.exe"), | ||||||
| 				Type:   artifact.Binary, | 				Type:   artifact.Binary, | ||||||
| 				Extra: map[string]interface{}{ | 				Extra: map[string]interface{}{ | ||||||
| 					"Binary":    "mybin", | 					"Binary":    "mybin", | ||||||
| @@ -159,7 +160,7 @@ func TestRunPipe(t *testing.T) { | |||||||
| 							"foo/bar", | 							"foo/bar", | ||||||
| 							"foo/bar/foobar", | 							"foo/bar/foobar", | ||||||
| 							"foo/bar/foobar/blah.txt", | 							"foo/bar/foobar/blah.txt", | ||||||
| 							"mybin", | 							"bin/mybin", | ||||||
| 						}, | 						}, | ||||||
| 						tarFiles(t, filepath.Join(dist, name)), | 						tarFiles(t, filepath.Join(dist, name)), | ||||||
| 					) | 					) | ||||||
| @@ -171,7 +172,7 @@ func TestRunPipe(t *testing.T) { | |||||||
| 					[]string{ | 					[]string{ | ||||||
| 						"README.windows.md", | 						"README.windows.md", | ||||||
| 						"foo/bar/foobar/blah.txt", | 						"foo/bar/foobar/blah.txt", | ||||||
| 						"mybin.exe", | 						"bin/mybin.exe", | ||||||
| 					}, | 					}, | ||||||
| 					zipFiles(t, filepath.Join(dist, "foobar_0.0.1_windows_amd64.zip")), | 					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) { | func TestRunPipeDistRemoved(t *testing.T) { | ||||||
| 	var ctx = context.New( | 	var ctx = context.New( | ||||||
| 		config.Project{ | 		config.Project{ | ||||||
| 			Dist: "/path/nope", | 			Dist: "/tmp/path/to/nope", | ||||||
| 			Archives: []config.Archive{ | 			Archives: []config.Archive{ | ||||||
| 				{ | 				{ | ||||||
| 					NameTemplate: "nope", | 					NameTemplate: "nope", | ||||||
| @@ -291,7 +292,7 @@ func TestRunPipeDistRemoved(t *testing.T) { | |||||||
| 		Goos:   "windows", | 		Goos:   "windows", | ||||||
| 		Goarch: "amd64", | 		Goarch: "amd64", | ||||||
| 		Name:   "mybin.exe", | 		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, | 		Type:   artifact.Binary, | ||||||
| 		Extra: map[string]interface{}{ | 		Extra: map[string]interface{}{ | ||||||
| 			"Binary":    "mybin", | 			"Binary":    "mybin", | ||||||
| @@ -299,7 +300,8 @@ func TestRunPipeDistRemoved(t *testing.T) { | |||||||
| 			"ID":        "default", | 			"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) { | func TestRunPipeInvalidGlob(t *testing.T) { | ||||||
|   | |||||||
| @@ -196,7 +196,7 @@ func binaries(a *artifact.Artifact) []string { | |||||||
| 	// nolint: prealloc | 	// nolint: prealloc | ||||||
| 	var bins []string | 	var bins []string | ||||||
| 	for _, b := range a.ExtraOr("Builds", []*artifact.Artifact{}).([]*artifact.Artifact) { | 	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 | 	return bins | ||||||
| } | } | ||||||
|   | |||||||
| @@ -825,14 +825,10 @@ func Test_buildManifest(t *testing.T) { | |||||||
| 						"ArtifactUploadHash": "820ead5d9d2266c728dce6d4d55b6460", | 						"ArtifactUploadHash": "820ead5d9d2266c728dce6d4d55b6460", | ||||||
| 						"Builds": []*artifact.Artifact{ | 						"Builds": []*artifact.Artifact{ | ||||||
| 							{ | 							{ | ||||||
| 								Extra: map[string]interface{}{ | 								Name: "foo", | ||||||
| 									"Binary": "foo", |  | ||||||
| 								}, |  | ||||||
| 							}, | 							}, | ||||||
| 							{ | 							{ | ||||||
| 								Extra: map[string]interface{}{ | 								Name: "bar", | ||||||
| 									"Binary": "bar", |  | ||||||
| 								}, |  | ||||||
| 							}, | 							}, | ||||||
| 						}, | 						}, | ||||||
| 					}, | 					}, | ||||||
| @@ -846,14 +842,10 @@ func Test_buildManifest(t *testing.T) { | |||||||
| 						"ArtifactUploadHash": "820ead5d9d2266c728dce6d4d55b6460", | 						"ArtifactUploadHash": "820ead5d9d2266c728dce6d4d55b6460", | ||||||
| 						"Builds": []*artifact.Artifact{ | 						"Builds": []*artifact.Artifact{ | ||||||
| 							{ | 							{ | ||||||
| 								Extra: map[string]interface{}{ | 								Name: "foo", | ||||||
| 									"Binary": "foo", |  | ||||||
| 								}, |  | ||||||
| 							}, | 							}, | ||||||
| 							{ | 							{ | ||||||
| 								Extra: map[string]interface{}{ | 								Name: "bar", | ||||||
| 									"Binary": "bar", |  | ||||||
| 								}, |  | ||||||
| 							}, | 							}, | ||||||
| 						}, | 						}, | ||||||
| 					}, | 					}, | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user