From 23df4b562ccd264b6dc61f51d767ad0a8d5f1ae5 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Sat, 5 Jan 2019 12:30:26 -0200 Subject: [PATCH] fix: support multiple binaries in scoop pipe (#909) * fix: support multiple binaries in scoop pipe * fix: lint --- internal/pipe/scoop/scoop.go | 17 ++++- internal/pipe/scoop/scoop_test.go | 74 ++++++++++++++----- .../testdata/test_buildmanifest.json.golden | 10 ++- ...est_buildmanifest_url_template.json.golden | 10 ++- 4 files changed, 84 insertions(+), 27 deletions(-) diff --git a/internal/pipe/scoop/scoop.go b/internal/pipe/scoop/scoop.go index 8b16f7761..8faa2ebc0 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 +} diff --git a/internal/pipe/scoop/scoop_test.go b/internal/pipe/scoop/scoop_test.go index 52cfc11fb..53251e169 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) + + 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()) }) - - 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()) } } diff --git a/internal/pipe/scoop/testdata/test_buildmanifest.json.golden b/internal/pipe/scoop/testdata/test_buildmanifest.json.golden index 4dcc6e500..63d433c53 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 7ba4487b9..7eb5a394f 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" } },