From d43c74f0bf4a8b55865ee5630e5b8c117f1e5e98 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Wed, 11 Jul 2018 00:36:02 -0700 Subject: [PATCH 1/2] test: added a case for #720 --- pipeline/brew/brew_test.go | 9 +++++ .../brew/testdata/binary_overriden.rb.golden | 34 +++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 pipeline/brew/testdata/binary_overriden.rb.golden diff --git a/pipeline/brew/brew_test.go b/pipeline/brew/brew_test.go index 6a091950a..74ea870fa 100644 --- a/pipeline/brew/brew_test.go +++ b/pipeline/brew/brew_test.go @@ -107,6 +107,15 @@ func TestRunPipe(t *testing.T) { "custom_download_strategy": func(ctx *context.Context) { ctx.Config.Brew.DownloadStrategy = "GitHubPrivateRepositoryReleaseDownloadStrategy" }, + "binary_overriden": func(ctx *context.Context) { + ctx.Config.Archive.Format = "binary" + ctx.Config.Archive.FormatOverrides = []config.FormatOverride{ + { + Goos: "darwin", + Format: "zip", + }, + } + }, } { t.Run(name, func(t *testing.T) { folder, err := ioutil.TempDir("", "goreleasertest") diff --git a/pipeline/brew/testdata/binary_overriden.rb.golden b/pipeline/brew/testdata/binary_overriden.rb.golden new file mode 100644 index 000000000..9697088b9 --- /dev/null +++ b/pipeline/brew/testdata/binary_overriden.rb.golden @@ -0,0 +1,34 @@ +class BinaryOverriden < Formula + desc "A run pipe test formula" + homepage "https://github.com/goreleaser" + url "https://github.com/test/test/releases/download/v1.0.1/bin.tar.gz" + version "1.0.1" + sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" + + depends_on "zsh" + depends_on "bash" + + conflicts_with "gtk+" + conflicts_with "qt" + + def install + bin.install "foo" + end + + def caveats; <<~EOS + don't do this + EOS + end + + plist_options :startup => false + + def plist; <<~EOS + whatever + EOS + end + + test do + system "true" + system "#{bin}/foo -h" + end +end From c34cc672605bc19b41888e457eedc0a6cebbbe73 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Wed, 11 Jul 2018 00:43:26 -0700 Subject: [PATCH 2/2] fix: brew should aknowledge format overrides --- pipeline/brew/brew.go | 11 ++++++++++- pipeline/brew/brew_test.go | 7 ++++--- pipeline/brew/testdata/binary_overriden.rb.golden | 2 +- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/pipeline/brew/brew.go b/pipeline/brew/brew.go index 3d50cbc09..5f43e86ff 100644 --- a/pipeline/brew/brew.go +++ b/pipeline/brew/brew.go @@ -91,7 +91,7 @@ func doRun(ctx *context.Context, client client.Client) error { if ctx.Config.Brew.GitHub.Name == "" { return pipeline.Skip("brew section is not configured") } - if ctx.Config.Archive.Format == "binary" { + if getFormat(ctx) == "binary" { return pipeline.Skip("archive format is binary") } @@ -141,6 +141,15 @@ func doRun(ctx *context.Context, client client.Client) error { return client.CreateFile(ctx, ctx.Config.Brew.CommitAuthor, ctx.Config.Brew.GitHub, content, path, msg) } +func getFormat(ctx *context.Context) string { + for _, override := range ctx.Config.Archive.FormatOverrides { + if strings.HasPrefix("darwin", override.Goos) { + return override.Format + } + } + return ctx.Config.Archive.Format +} + func buildFormula(ctx *context.Context, artifact artifact.Artifact) (bytes.Buffer, error) { data, err := dataFor(ctx, artifact) if err != nil { diff --git a/pipeline/brew/brew_test.go b/pipeline/brew/brew_test.go index 74ea870fa..fe0b10daf 100644 --- a/pipeline/brew/brew_test.go +++ b/pipeline/brew/brew_test.go @@ -159,9 +159,10 @@ func TestRunPipe(t *testing.T) { }, } fn(ctx) - var path = filepath.Join(folder, "bin.tar.gz") + var format = getFormat(ctx) + var path = filepath.Join(folder, "bin."+format) ctx.Artifacts.Add(artifact.Artifact{ - Name: "bin.tar.gz", + Name: "bin." + format, Path: path, Goos: "darwin", Goarch: "amd64", @@ -177,7 +178,7 @@ func TestRunPipe(t *testing.T) { assert.True(t, client.CreatedFile) var golden = fmt.Sprintf("testdata/%s.rb.golden", name) if *update { - ioutil.WriteFile(golden, []byte(client.Content), 0655) + assert.NoError(t, ioutil.WriteFile(golden, []byte(client.Content), 0655)) } bts, err := ioutil.ReadFile(golden) assert.NoError(t, err) diff --git a/pipeline/brew/testdata/binary_overriden.rb.golden b/pipeline/brew/testdata/binary_overriden.rb.golden index 9697088b9..0a8b478af 100644 --- a/pipeline/brew/testdata/binary_overriden.rb.golden +++ b/pipeline/brew/testdata/binary_overriden.rb.golden @@ -1,7 +1,7 @@ class BinaryOverriden < Formula desc "A run pipe test formula" homepage "https://github.com/goreleaser" - url "https://github.com/test/test/releases/download/v1.0.1/bin.tar.gz" + url "https://github.com/test/test/releases/download/v1.0.1/bin.zip" version "1.0.1" sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"