From fc1ef8a2a23406ecb790f07fece7fbe77e31b40d Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Tue, 21 Apr 2020 16:11:18 -0300 Subject: [PATCH] fix: scoop wrap_in_directory (#1458) Signed-off-by: Carlos Alexandro Becker --- internal/pipe/archive/archive.go | 7 +- internal/pipe/archive/archive_test.go | 7 +- internal/pipe/scoop/scoop.go | 4 +- internal/pipe/scoop/scoop_test.go | 134 ++++++++++++++++++ .../test_buildmanifest_wrap.json.golden | 19 +++ 5 files changed, 166 insertions(+), 5 deletions(-) create mode 100644 internal/pipe/scoop/testdata/test_buildmanifest_wrap.json.golden diff --git a/internal/pipe/archive/archive.go b/internal/pipe/archive/archive.go index cb332e67b91..71e202738e1 100644 --- a/internal/pipe/archive/archive.go +++ b/internal/pipe/archive/archive.go @@ -170,9 +170,10 @@ func create(ctx *context.Context, archive config.Archive, binaries []*artifact.A Goarm: binaries[0].Goarm, Gomips: binaries[0].Gomips, Extra: map[string]interface{}{ - "Builds": binaries, - "ID": archive.ID, - "Format": archive.Format, + "Builds": binaries, + "ID": archive.ID, + "Format": archive.Format, + "WrappedIn": wrap, }, }) return nil diff --git a/internal/pipe/archive/archive_test.go b/internal/pipe/archive/archive_test.go index d23c39b4b4a..d150b7ab0ee 100644 --- a/internal/pipe/archive/archive_test.go +++ b/internal/pipe/archive/archive_test.go @@ -494,6 +494,10 @@ func TestRunPipeWrap(t *testing.T) { }) require.NoError(t, Pipe{}.Run(ctx)) + var archives = ctx.Artifacts.Filter(artifact.ByType(artifact.UploadableArchive)).List() + require.Len(t, archives, 1) + require.Equal(t, "foo_macOS", archives[0].ExtraOr("WrappedIn", "")) + // Check archive contents f, err := os.Open(filepath.Join(dist, "foo.tar.gz")) require.NoError(t, err) @@ -648,11 +652,12 @@ func TestBinaryOverride(t *testing.T) { darwin := archives.Filter(artifact.ByGoos("darwin")).List()[0] require.Equal(tt, "foobar_0.0.1_darwin_amd64."+format, darwin.Name) require.Equal(tt, format, darwin.ExtraOr("Format", "")) + require.Empty(tt, darwin.ExtraOr("WrappedIn", "")) archives = ctx.Artifacts.Filter(artifact.ByType(artifact.UploadableBinary)) windows := archives.Filter(artifact.ByGoos("windows")).List()[0] require.Equal(tt, "foobar_0.0.1_windows_amd64.exe", windows.Name) - require.Equal(tt, format, windows.ExtraOr("Format", "")) + require.Empty(tt, windows.ExtraOr("WrappedIn", "")) }) } } diff --git a/internal/pipe/scoop/scoop.go b/internal/pipe/scoop/scoop.go index 27bed73ee14..957ba0ad024 100644 --- a/internal/pipe/scoop/scoop.go +++ b/internal/pipe/scoop/scoop.go @@ -6,6 +6,7 @@ import ( "encoding/json" "errors" "fmt" + "path/filepath" "strings" "github.com/goreleaser/goreleaser/internal/artifact" @@ -196,8 +197,9 @@ func buildManifest(ctx *context.Context, artifacts []*artifact.Artifact) (bytes. func binaries(a *artifact.Artifact) []string { // nolint: prealloc var bins []string + var wrap = a.ExtraOr("WrappedIn", "").(string) for _, b := range a.ExtraOr("Builds", []*artifact.Artifact{}).([]*artifact.Artifact) { - bins = append(bins, b.Name) + bins = append(bins, filepath.Join(wrap, b.Name)) } return bins } diff --git a/internal/pipe/scoop/scoop_test.go b/internal/pipe/scoop/scoop_test.go index 99d205dec9c..6c901a88612 100644 --- a/internal/pipe/scoop/scoop_test.go +++ b/internal/pipe/scoop/scoop_test.go @@ -128,6 +128,65 @@ func Test_doRun(t *testing.T) { }, shouldNotErr, }, + { + "wrap in directory", + args{ + &context.Context{ + TokenType: context.TokenTypeGitHub, + Git: context.GitInfo{ + CurrentTag: "v1.0.1", + }, + Version: "1.0.1", + Artifacts: artifact.New(), + Config: config.Project{ + Builds: []config.Build{ + {Binary: "test", Goarch: []string{"amd64"}, Goos: []string{"windows"}}, + }, + Dist: ".", + ProjectName: "run-pipe", + Archives: []config.Archive{ + {Format: "tar.gz", WrapInDirectory: "true"}, + }, + Release: config.Release{ + GitHub: config.Repo{ + Owner: "test", + Name: "test", + }, + }, + Scoop: config.Scoop{ + Bucket: config.Repo{ + Owner: "test", + Name: "test", + }, + Description: "A run pipe test formula", + Homepage: "https://github.com/goreleaser", + }, + }, + }, + &DummyClient{}, + }, + []*artifact.Artifact{ + { + Name: "foo_1.0.1_windows_amd64.tar.gz", + Goos: "windows", + Goarch: "amd64", + Path: file, + Extra: map[string]interface{}{ + "Wrap": "foo_1.0.1_windows_amd64", + }, + }, + { + Name: "foo_1.0.1_windows_386.tar.gz", + Goos: "windows", + Goarch: "386", + Path: file, + Extra: map[string]interface{}{ + "Wrap": "foo_1.0.1_windows_386", + }, + }, + }, + shouldNotErr, + }, { "valid enterprise github", args{ @@ -864,6 +923,81 @@ func Test_buildManifest(t *testing.T) { } } +func TestWrapInDirectory(t *testing.T) { + folder, err := ioutil.TempDir("", "goreleasertest") + require.NoError(t, err) + var file = filepath.Join(folder, "archive") + require.NoError(t, ioutil.WriteFile(file, []byte("lorem ipsum"), 0644)) + var ctx = &context.Context{ + TokenType: context.TokenTypeGitLab, + Git: context.GitInfo{ + CurrentTag: "v1.0.1", + }, + Version: "1.0.1", + Artifacts: artifact.New(), + Config: config.Project{ + GitLabURLs: config.GitLabURLs{ + Download: "https://gitlab.com", + }, + Builds: []config.Build{ + {Binary: "test"}, + }, + Dist: ".", + ProjectName: "run-pipe", + Archives: []config.Archive{ + {Format: "tar.gz", WrapInDirectory: "true"}, + }, + Release: config.Release{ + GitHub: config.Repo{ + Owner: "test", + Name: "test", + }, + }, + Scoop: config.Scoop{ + Bucket: config.Repo{ + Owner: "test", + Name: "test", + }, + Description: "A run pipe test formula", + Homepage: "https://gitlab.com/goreleaser", + URLTemplate: "http://gitlab.mycompany.com/foo/bar/uploads/{{ .ArtifactUploadHash }}/{{ .ArtifactName }}", + Persist: []string{"data.cfg", "etc"}, + }, + }, + } + require.NoError(t, 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{}{ + "ArtifactUploadHash": "820ead5d9d2266c728dce6d4d55b6460", + "WrappedIn": "foo_1.0.1_windows_amd64", + "Builds": []*artifact.Artifact{ + { + Name: "foo.exe", + }, + { + Name: "bar.exe", + }, + }, + }, + }, + }) + + require.NoError(t, err) + + var golden = "testdata/test_buildmanifest_wrap.json.golden" + if *update { + require.NoError(t, ioutil.WriteFile(golden, out.Bytes(), 0655)) + } + bts, err := ioutil.ReadFile(golden) + require.NoError(t, err) + require.Equal(t, string(bts), out.String()) +} + type DummyClient struct { CreatedFile bool Content string diff --git a/internal/pipe/scoop/testdata/test_buildmanifest_wrap.json.golden b/internal/pipe/scoop/testdata/test_buildmanifest_wrap.json.golden new file mode 100644 index 00000000000..fded9339add --- /dev/null +++ b/internal/pipe/scoop/testdata/test_buildmanifest_wrap.json.golden @@ -0,0 +1,19 @@ +{ + "version": "1.0.1", + "architecture": { + "64bit": { + "url": "http://gitlab.mycompany.com/foo/bar/uploads/820ead5d9d2266c728dce6d4d55b6460/foo_1.0.1_windows_amd64.tar.gz", + "bin": [ + "foo_1.0.1_windows_amd64/foo.exe", + "foo_1.0.1_windows_amd64/bar.exe" + ], + "hash": "5e2bf57d3f40c4b6df69daf1936cb766f832374b4fc0259a7cbff06e2f70f269" + } + }, + "homepage": "https://gitlab.com/goreleaser", + "description": "A run pipe test formula", + "persist": [ + "data.cfg", + "etc" + ] +} \ No newline at end of file