diff --git a/internal/pipe/brew/brew.go b/internal/pipe/brew/brew.go index ebb368b5ac1e..6ba4458bbba2 100644 --- a/internal/pipe/brew/brew.go +++ b/internal/pipe/brew/brew.go @@ -1,6 +1,7 @@ package brew import ( + "bufio" "bytes" "errors" "fmt" @@ -257,7 +258,28 @@ func doBuildFormula(ctx *context.Context, data templateData) (string, error) { if err := t.Execute(&out, data); err != nil { return "", err } - return tmpl.New(ctx).Apply(out.String()) + + content, err := tmpl.New(ctx).Apply(out.String()) + if err != nil { + return "", err + } + out.Reset() + + // Sanitize the template output and get rid of trailing whitespace. + var ( + r = strings.NewReader(content) + s = bufio.NewScanner(r) + ) + for s.Scan() { + l := strings.TrimRight(s.Text(), " ") + _, _ = out.WriteString(l) + _ = out.WriteByte('\n') + } + if err := s.Err(); err != nil { + return "", err + } + + return out.String(), nil } func dataFor(ctx *context.Context, cfg config.Homebrew, cl client.Client, artifacts []*artifact.Artifact) (templateData, error) { diff --git a/internal/pipe/brew/testdata/custom_block.rb.golden b/internal/pipe/brew/testdata/custom_block.rb.golden index 5aa77ee1ba4c..57000dcd3a01 100644 --- a/internal/pipe/brew/testdata/custom_block.rb.golden +++ b/internal/pipe/brew/testdata/custom_block.rb.golden @@ -9,12 +9,12 @@ class CustomBlock < Formula url "https://dummyhost/download/v1.0.1/bin.tar.gz" sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" end - + head "https://github.com/caarlos0/test.git" - + depends_on "zsh" => :optional depends_on "bash" - + conflicts_with "gtk+" conflicts_with "qt" diff --git a/internal/pipe/brew/testdata/custom_download_strategy.rb.golden b/internal/pipe/brew/testdata/custom_download_strategy.rb.golden index 2b1c7fbfd037..096742005250 100644 --- a/internal/pipe/brew/testdata/custom_download_strategy.rb.golden +++ b/internal/pipe/brew/testdata/custom_download_strategy.rb.golden @@ -9,10 +9,10 @@ class CustomDownloadStrategy < Formula url "https://dummyhost/download/v1.0.1/bin.tar.gz", :using => GitHubPrivateRepositoryReleaseDownloadStrategy sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" end - + depends_on "zsh" => :optional depends_on "bash" - + conflicts_with "gtk+" conflicts_with "qt" diff --git a/internal/pipe/brew/testdata/custom_require.rb.golden b/internal/pipe/brew/testdata/custom_require.rb.golden index 2497c99d4266..33819dcc2bb4 100644 --- a/internal/pipe/brew/testdata/custom_require.rb.golden +++ b/internal/pipe/brew/testdata/custom_require.rb.golden @@ -10,10 +10,10 @@ class CustomRequire < Formula url "https://dummyhost/download/v1.0.1/bin.tar.gz", :using => CustomDownloadStrategy sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" end - + depends_on "zsh" => :optional depends_on "bash" - + conflicts_with "gtk+" conflicts_with "qt" diff --git a/internal/pipe/brew/testdata/default.rb.golden b/internal/pipe/brew/testdata/default.rb.golden index 65041f914021..ea5e0fc449d4 100644 --- a/internal/pipe/brew/testdata/default.rb.golden +++ b/internal/pipe/brew/testdata/default.rb.golden @@ -9,10 +9,10 @@ class Default < Formula url "https://dummyhost/download/v1.0.1/bin.tar.gz" sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" end - + depends_on "zsh" => :optional depends_on "bash" - + conflicts_with "gtk+" conflicts_with "qt" diff --git a/internal/pipe/brew/testdata/default_gitlab.rb.golden b/internal/pipe/brew/testdata/default_gitlab.rb.golden index a62ec7775ac7..b58c76195a17 100644 --- a/internal/pipe/brew/testdata/default_gitlab.rb.golden +++ b/internal/pipe/brew/testdata/default_gitlab.rb.golden @@ -9,10 +9,10 @@ class DefaultGitlab < Formula url "https://dummyhost/download/v1.0.1/bin.tar.gz" sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" end - + depends_on "zsh" => :optional depends_on "bash" - + conflicts_with "gtk+" conflicts_with "qt" diff --git a/internal/pipe/brew/testdata/multiple_armv5.rb.golden b/internal/pipe/brew/testdata/multiple_armv5.rb.golden index 47fee4e73466..e5e7b2815981 100644 --- a/internal/pipe/brew/testdata/multiple_armv5.rb.golden +++ b/internal/pipe/brew/testdata/multiple_armv5.rb.golden @@ -17,10 +17,10 @@ class MultipleArmv5 < Formula url "https://dummyhost/download/v1.0.1/arm64.tar.gz" sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" end - + depends_on "zsh" depends_on "bash" => :recommended - + conflicts_with "gtk+" conflicts_with "qt" diff --git a/internal/pipe/brew/testdata/multiple_armv6.rb.golden b/internal/pipe/brew/testdata/multiple_armv6.rb.golden index cea97a498186..0028051ad76b 100644 --- a/internal/pipe/brew/testdata/multiple_armv6.rb.golden +++ b/internal/pipe/brew/testdata/multiple_armv6.rb.golden @@ -17,10 +17,10 @@ class MultipleArmv6 < Formula url "https://dummyhost/download/v1.0.1/arm64.tar.gz" sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" end - + depends_on "zsh" depends_on "bash" => :recommended - + conflicts_with "gtk+" conflicts_with "qt" diff --git a/internal/pipe/brew/testdata/multiple_armv7.rb.golden b/internal/pipe/brew/testdata/multiple_armv7.rb.golden index 54d351585017..1c638a2538a7 100644 --- a/internal/pipe/brew/testdata/multiple_armv7.rb.golden +++ b/internal/pipe/brew/testdata/multiple_armv7.rb.golden @@ -17,10 +17,10 @@ class MultipleArmv7 < Formula url "https://dummyhost/download/v1.0.1/arm64.tar.gz" sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" end - + depends_on "zsh" depends_on "bash" => :recommended - + conflicts_with "gtk+" conflicts_with "qt" diff --git a/internal/pipe/brew/testdata/test.rb.golden b/internal/pipe/brew/testdata/test.rb.golden index 2ad3bbcddbb4..f81eb3020708 100644 --- a/internal/pipe/brew/testdata/test.rb.golden +++ b/internal/pipe/brew/testdata/test.rb.golden @@ -22,14 +22,14 @@ class Test < Formula url "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Arm64.tar.gz" sha256 "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67" end - + devel do url "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Darwin_x86_64.tar.gz" sha256 "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c68" end - + depends_on "gtk+" - + conflicts_with "svn" def install