Repository: goreleaser/goreleaser
Pull request #909 (2019-01-01 16:52:13)

fix: support multiple binaries in scoop pipe
now it should be able to support multiple builds and therefore multiple binaries.

refs https://github.com/goreleaser/goreleaser/issues/705

codecov-io: # [Codecov](https://codecov.io/gh/goreleaser/goreleaser/pull/909?src=pr&el=h1) Report
> Merging [#909](https://codecov.io/gh/goreleaser/goreleaser/pull/909?src=pr&el=desc) into [master](https://codecov.io/gh/goreleaser/goreleaser/commit/850205abf17bb51e75fc57f3b03bb80d981efa98?src=pr&el=desc) will **increase** coverage by `0.02%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/goreleaser/goreleaser/pull/909/graphs/tree.svg?width=650&token=3bJvv6b7hN&height=150&src=pr)](https://codecov.io/gh/goreleaser/goreleaser/pull/909?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master     #909      +/-   ##
==========================================
+ Coverage    88.2%   88.22%   +0.02%     
==========================================
  Files          48       48              
  Lines        2399     2404       +5     
==========================================
+ Hits         2116     2121       +5     
  Misses        223      223              
  Partials       60       60
```


| [Impacted Files](https://codecov.io/gh/goreleaser/goreleaser/pull/909?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [internal/pipe/scoop/scoop.go](https://codecov.io/gh/goreleaser/goreleaser/pull/909/diff?src=pr&el=tree#diff-aW50ZXJuYWwvcGlwZS9zY29vcC9zY29vcC5nbw==) | `88.37% <100%> (+0.71%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/goreleaser/goreleaser/pull/909?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/goreleaser/goreleaser/pull/909?src=pr&el=footer). Last update [850205a...cc4ad10](https://codecov.io/gh/goreleaser/goreleaser/pull/909?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/internal/pipe/scoop/scoop.go b/internal/pipe/scoop/scoop.go
index 8b16f776..8faa2ebc 100644
--- a/internal/pipe/scoop/scoop.go
+++ b/internal/pipe/scoop/scoop.go
@@ -109,9 +109,9 @@ type Manifest struct {
 
 // Resource represents a combination of a url and a binary name for an architecture
 type Resource struct {
-	URL  string `json:"url"`  // URL to the archive
-	Bin  string `json:"bin"`  // name of binary inside the archive
-	Hash string `json:"hash"` // the archive checksum
+	URL  string   `json:"url"`  // URL to the archive
+	Bin  []string `json:"bin"`  // name of binary inside the archive
+	Hash string   `json:"hash"` // the archive checksum
 }
 
 func buildManifest(ctx *context.Context, artifacts []artifact.Artifact) (bytes.Buffer, error) {
@@ -145,7 +145,7 @@ func buildManifest(ctx *context.Context, artifacts []artifact.Artifact) (bytes.B
 
 		manifest.Architecture[arch] = Resource{
 			URL:  url,
-			Bin:  ctx.Config.Builds[0].Binary + ".exe", // TODO: this is wrong
+			Bin:  binaries(artifact),
 			Hash: sum,
 		}
 	}
@@ -157,3 +157,12 @@ func buildManifest(ctx *context.Context, artifacts []artifact.Artifact) (bytes.B
 	_, err = result.Write(data)
 	return result, err
 }
+
+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")
+	}
+	return bins
+}


Test patch:
diff --git a/internal/pipe/scoop/scoop_test.go b/internal/pipe/scoop/scoop_test.go
index 52cfc11f..53251e16 100644
--- a/internal/pipe/scoop/scoop_test.go
+++ b/internal/pipe/scoop/scoop_test.go
@@ -5,9 +5,8 @@ import (
 	"flag"
 	"io/ioutil"
 	"os"
-	"testing"
-
 	"path/filepath"
+	"testing"
 
 	"github.com/goreleaser/goreleaser/internal/artifact"
 	"github.com/goreleaser/goreleaser/internal/client"
@@ -403,9 +402,6 @@ func Test_buildManifest(t *testing.T) {
 					GitHubURLs: config.GitHubURLs{
 						Download: "https://github.com",
 					},
-					Builds: []config.Build{
-						{Binary: "test"},
-					},
 					Dist:        ".",
 					ProjectName: "run-pipe",
 					Archive: config.Archive{
@@ -471,21 +467,61 @@ func Test_buildManifest(t *testing.T) {
 	}
 
 	for _, tt := range tests {
-		var ctx = tt.ctx
-		Pipe{}.Default(ctx)
-		out, err := buildManifest(ctx, []artifact.Artifact{
-			{Name: "foo_1.0.1_windows_amd64.tar.gz", Goos: "windows", Goarch: "amd64", Path: file},
-			{Name: "foo_1.0.1_windows_386.tar.gz", Goos: "windows", Goarch: "386", Path: file},
-		})
+		t.Run(tt.filename, func(t *testing.T) {
+			var ctx = tt.ctx
+			Pipe{}.Default(ctx)
+			out, err := buildManifest(ctx, []artifact.Artifact{
+				{
+					Name:   "foo_1.0.1_windows_amd64.tar.gz",
+					Goos:   "windows",
+					Goarch: "amd64",
+					Path:   file,
+					Extra: map[string]interface{}{
+						"Builds": []artifact.Artifact{
+							{
+								Extra: map[string]interface{}{
+									"Binary": "foo",
+								},
+							},
+							{
+								Extra: map[string]interface{}{
+									"Binary": "bar",
+								},
+							},
+						},
+					},
+				},
+				{
+					Name:   "foo_1.0.1_windows_386.tar.gz",
+					Goos:   "windows",
+					Goarch: "386",
+					Path:   file,
+					Extra: map[string]interface{}{
+						"Builds": []artifact.Artifact{
+							{
+								Extra: map[string]interface{}{
+									"Binary": "foo",
+								},
+							},
+							{
+								Extra: map[string]interface{}{
+									"Binary": "bar",
+								},
+							},
+						},
+					},
+				},
+			})
 
-		require.NoError(t, err)
+			require.NoError(t, err)
 
-		if *update {
-			require.NoError(t, ioutil.WriteFile(tt.filename, out.Bytes(), 0655))
-		}
-		bts, err := ioutil.ReadFile(tt.filename)
-		require.NoError(t, err)
-		require.Equal(t, string(bts), out.String())
+			if *update {
+				require.NoError(t, ioutil.WriteFile(tt.filename, out.Bytes(), 0655))
+			}
+			bts, err := ioutil.ReadFile(tt.filename)
+			require.NoError(t, err)
+			require.Equal(t, string(bts), out.String())
+		})
 	}
 }
 
diff --git a/internal/pipe/scoop/testdata/test_buildmanifest.json.golden b/internal/pipe/scoop/testdata/test_buildmanifest.json.golden
index 4dcc6e50..63d433c5 100644
--- a/internal/pipe/scoop/testdata/test_buildmanifest.json.golden
+++ b/internal/pipe/scoop/testdata/test_buildmanifest.json.golden
@@ -3,12 +3,18 @@
     "architecture": {
         "32bit": {
             "url": "https://github.com/test/test/releases/download/v1.0.1/foo_1.0.1_windows_386.tar.gz",
-            "bin": "test.exe",
+            "bin": [
+                "foo.exe",
+                "bar.exe"
+            ],
             "hash": "5e2bf57d3f40c4b6df69daf1936cb766f832374b4fc0259a7cbff06e2f70f269"
         },
         "64bit": {
             "url": "https://github.com/test/test/releases/download/v1.0.1/foo_1.0.1_windows_amd64.tar.gz",
-            "bin": "test.exe",
+            "bin": [
+                "foo.exe",
+                "bar.exe"
+            ],
             "hash": "5e2bf57d3f40c4b6df69daf1936cb766f832374b4fc0259a7cbff06e2f70f269"
         }
     },
diff --git a/internal/pipe/scoop/testdata/test_buildmanifest_url_template.json.golden b/internal/pipe/scoop/testdata/test_buildmanifest_url_template.json.golden
index 7ba4487b..7eb5a394 100644
--- a/internal/pipe/scoop/testdata/test_buildmanifest_url_template.json.golden
+++ b/internal/pipe/scoop/testdata/test_buildmanifest_url_template.json.golden
@@ -3,12 +3,18 @@
     "architecture": {
         "32bit": {
             "url": "http://github.mycompany.com/foo/bar/v1.0.1/foo_1.0.1_windows_386.tar.gz",
-            "bin": "test.exe",
+            "bin": [
+                "foo.exe",
+                "bar.exe"
+            ],
             "hash": "5e2bf57d3f40c4b6df69daf1936cb766f832374b4fc0259a7cbff06e2f70f269"
         },
         "64bit": {
             "url": "http://github.mycompany.com/foo/bar/v1.0.1/foo_1.0.1_windows_amd64.tar.gz",
-            "bin": "test.exe",
+            "bin": [
+                "foo.exe",
+                "bar.exe"
+            ],
             "hash": "5e2bf57d3f40c4b6df69daf1936cb766f832374b4fc0259a7cbff06e2f70f269"
         }
     },