Skip to content

Commit

Permalink
feat: remove trailing whitespace from generated brew formula (gorelea…
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasmalkmus committed Nov 25, 2020
1 parent dbe5c29 commit 69acb34
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 21 deletions.
24 changes: 23 additions & 1 deletion internal/pipe/brew/brew.go
@@ -1,6 +1,7 @@
package brew

import (
"bufio"
"bytes"
"errors"
"fmt"
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions internal/pipe/brew/testdata/custom_block.rb.golden
Expand Up @@ -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"

Expand Down
Expand Up @@ -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"

Expand Down
4 changes: 2 additions & 2 deletions internal/pipe/brew/testdata/custom_require.rb.golden
Expand Up @@ -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"

Expand Down
4 changes: 2 additions & 2 deletions internal/pipe/brew/testdata/default.rb.golden
Expand Up @@ -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"

Expand Down
4 changes: 2 additions & 2 deletions internal/pipe/brew/testdata/default_gitlab.rb.golden
Expand Up @@ -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"

Expand Down
4 changes: 2 additions & 2 deletions internal/pipe/brew/testdata/multiple_armv5.rb.golden
Expand Up @@ -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"

Expand Down
4 changes: 2 additions & 2 deletions internal/pipe/brew/testdata/multiple_armv6.rb.golden
Expand Up @@ -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"

Expand Down
4 changes: 2 additions & 2 deletions internal/pipe/brew/testdata/multiple_armv7.rb.golden
Expand Up @@ -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"

Expand Down
6 changes: 3 additions & 3 deletions internal/pipe/brew/testdata/test.rb.golden
Expand Up @@ -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
Expand Down

0 comments on commit 69acb34

Please sign in to comment.