Skip to content

Commit

Permalink
fix: brew style (#3274)
Browse files Browse the repository at this point in the history
* fix: brew style

closes #3236

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>

* fix: more fixes

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>

* fix: more fixes

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
  • Loading branch information
caarlos0 committed Aug 6, 2022
1 parent 5a43334 commit d630605
Show file tree
Hide file tree
Showing 21 changed files with 228 additions and 183 deletions.
42 changes: 26 additions & 16 deletions internal/pipe/brew/brew_test.go
Expand Up @@ -75,7 +75,7 @@ var defaultTemplateData = templateData{
},
{
DownloadURL: "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Darwin_arm64.tar.gz",
SHA256: "1633f61598ab0791e213135923624eb342196b349490sadasdsadsadasdasdsd",
SHA256: "1df5fdc2bad4ed4c28fbdc77b6c542988c0dc0e2ae34e0dc912bbb1c66646c58",
OS: "darwin",
Arch: "arm64",
Install: []string{`bin.install "test"`},
Expand Down Expand Up @@ -103,9 +103,9 @@ func TestFullFormulae(t *testing.T) {
data.Dependencies = []config.HomebrewDependency{{Name: "gtk+"}}
data.Conflicts = []string{"svn"}
data.Plist = "it works"
data.PostInstall = []string{`system "touch", "/tmp/foo"`, `system "echo", "done"`}
data.PostInstall = []string{`touch "/tmp/foo"`, `system "echo", "done"`}
data.CustomBlock = []string{"devel do", ` url "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Darwin_x86_64.tar.gz"`, ` sha256 "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c68"`, "end"}
data.Tests = []string{`system "#{bin}/{{.ProjectName}} -version"`}
data.Tests = []string{`system "#{bin}/{{.ProjectName}}", "-version"`}
formulae, err := doBuildFormula(context.New(config.Project{
ProjectName: "foo",
}), data)
Expand Down Expand Up @@ -145,8 +145,8 @@ func TestFormulaeSimple(t *testing.T) {
}

func TestSplit(t *testing.T) {
parts := split("system \"true\"\nsystem \"#{bin}/foo -h\"")
require.Equal(t, []string{"system \"true\"", "system \"#{bin}/foo -h\""}, parts)
parts := split("system \"true\"\nsystem \"#{bin}/foo\", \"-h\"")
require.Equal(t, []string{"system \"true\"", "system \"#{bin}/foo\", \"-h\""}, parts)
parts = split("")
require.Equal(t, []string{}, parts)
parts = split("\n ")
Expand Down Expand Up @@ -268,14 +268,14 @@ func TestFullPipe(t *testing.T) {
IDs: []string{
"foo",
},
Description: "A run pipe test formula and FOO={{ .Env.FOO }}",
Description: "Run pipe test formula and FOO={{ .Env.FOO }}",
Caveats: "don't do this {{ .ProjectName }}",
Test: "system \"true\"\nsystem \"#{bin}/foo -h\"",
Test: "system \"true\"\nsystem \"#{bin}/foo\", \"-h\"",
Plist: `<xml>whatever</xml>`,
Dependencies: []config.HomebrewDependency{{Name: "zsh", Type: "optional"}, {Name: "bash"}},
Conflicts: []string{"gtk+", "qt"},
Service: "run foo/bar\nkeep_alive true",
PostInstall: "system \"echo\"\nsystem \"touch\" \"/tmp/hi\"",
PostInstall: "system \"echo\"\ntouch \"/tmp/hi\"",
Install: `bin.install "{{ .ProjectName }}"`,
Goamd64: "v1",
},
Expand Down Expand Up @@ -353,8 +353,11 @@ func TestRunPipeNameTemplate(t *testing.T) {
ProjectName: "foo",
Brews: []config.Homebrew{
{
Name: "foo_{{ .Env.FOO_BAR }}",
Goamd64: "v1",
Name: "foo_{{ .Env.FOO_BAR }}",
Description: "Foo bar",
Homepage: "https://goreleaser.com",
Goamd64: "v1",
Install: `bin.install "foo"`,
Tap: config.RepoRef{
Owner: "foo",
Name: "bar",
Expand Down Expand Up @@ -524,12 +527,13 @@ func TestRunPipeForMultipleAmd64Versions(t *testing.T) {
Brews: []config.Homebrew{
{
Name: name,
Description: "A run pipe test formula",
Description: "Run pipe test formula",
Tap: config.RepoRef{
Owner: "test",
Name: "test",
},
Homepage: "https://github.com/goreleaser",
Install: `bin.install "foo"`,
},
},
GitHubURLs: config.GitHubURLs{
Expand Down Expand Up @@ -648,9 +652,9 @@ func TestRunPipeForMultipleArmVersions(t *testing.T) {
Brews: []config.Homebrew{
{
Name: name,
Description: "A run pipe test formula and FOO={{ .Env.FOO }}",
Description: "Run pipe test formula and FOO={{ .Env.FOO }}",
Caveats: "don't do this {{ .ProjectName }}",
Test: "system \"true\"\nsystem \"#{bin}/foo -h\"",
Test: "system \"true\"\nsystem \"#{bin}/foo\", \"-h\"",
Plist: `<xml>whatever</xml>`,
Dependencies: []config.HomebrewDependency{{Name: "zsh"}, {Name: "bash", Type: "recommended"}},
Conflicts: []string{"gtk+", "qt"},
Expand Down Expand Up @@ -921,7 +925,9 @@ func TestRunPipeBinaryRelease(t *testing.T) {
ProjectName: "foo",
Brews: []config.Homebrew{
{
Name: "foo",
Name: "foo",
Homepage: "https://goreleaser.com",
Description: "Fake desc",
Tap: config.RepoRef{
Owner: "foo",
Name: "bar",
Expand Down Expand Up @@ -1159,7 +1165,9 @@ func TestRunPipeUniversalBinary(t *testing.T) {
ProjectName: "unibin",
Brews: []config.Homebrew{
{
Name: "unibin",
Name: "unibin",
Homepage: "https://goreleaser.com",
Description: "Fake desc",
Tap: config.RepoRef{
Owner: "unibin",
Name: "bar",
Expand Down Expand Up @@ -1215,7 +1223,9 @@ func TestRunPipeUniversalBinaryNotReplacing(t *testing.T) {
ProjectName: "unibin",
Brews: []config.Homebrew{
{
Name: "unibin",
Name: "unibin",
Homepage: "https://goreleaser.com",
Description: "Fake desc",
Tap: config.RepoRef{
Owner: "unibin",
Name: "bar",
Expand Down
46 changes: 24 additions & 22 deletions internal/pipe/brew/template.go
Expand Up @@ -45,6 +45,13 @@ class {{ .Name }} < Formula
{{- if .License }}
license "{{ .License }}"
{{- end }}
{{- with .Dependencies }}
{{ range $index, $element := . }}
depends_on "{{ .Name }}"
{{- if .Type }} => :{{ .Type }}{{- end }}
{{- end }}
{{- end -}}
{{- if and (not .LinuxPackages) .MacOSPackages }}
depends_on :macos
{{- end }}
Expand All @@ -58,7 +65,7 @@ class {{ .Name }} < Formula
{{- range $element := .MacOSPackages }}
{{- if eq $element.Arch "all" }}
url "{{ $element.DownloadURL }}"
{{- if .DownloadStrategy }}, :using => {{ .DownloadStrategy }}{{- end }}
{{- if .DownloadStrategy }}, using: {{ .DownloadStrategy }}{{- end }}
sha256 "{{ $element.SHA256 }}"
def install
Expand All @@ -68,7 +75,7 @@ class {{ .Name }} < Formula
end
{{- else if $.HasOnlyAmd64MacOsPkg }}
url "{{ $element.DownloadURL }}"
{{- if .DownloadStrategy }}, :using => {{ .DownloadStrategy }}{{- end }}
{{- if .DownloadStrategy }}, using: {{ .DownloadStrategy }}{{- end }}
sha256 "{{ $element.SHA256 }}"
def install
Expand All @@ -94,7 +101,7 @@ class {{ .Name }} < Formula
if Hardware::CPU.arm?
{{- end}}
url "{{ $element.DownloadURL }}"
{{- if .DownloadStrategy }}, :using => {{ .DownloadStrategy }}{{- end }}
{{- if .DownloadStrategy }}, using: {{ .DownloadStrategy }}{{- end }}
sha256 "{{ $element.SHA256 }}"
def install
Expand Down Expand Up @@ -123,7 +130,7 @@ class {{ .Name }} < Formula
if Hardware::CPU.arm? && Hardware::CPU.is_64_bit?
{{- end }}
url "{{ $element.DownloadURL }}"
{{- if .DownloadStrategy }}, :using => {{ .DownloadStrategy }}{{- end }}
{{- if .DownloadStrategy }}, using: {{ .DownloadStrategy }}{{- end }}
sha256 "{{ $element.SHA256 }}"
def install
Expand All @@ -136,22 +143,15 @@ class {{ .Name }} < Formula
end
{{- end }}
{{- with .CustomBlock }}
{{- with .Conflicts }}
{{ range $index, $element := . }}
{{ . }}
conflicts_with "{{ . }}"
{{- end }}
{{- end }}
{{- with .Dependencies }}
{{ range $index, $element := . }}
depends_on "{{ .Name }}"
{{- if .Type }} => :{{ .Type }}{{- end }}
{{- end }}
{{- end -}}
{{- with .Conflicts }}
{{- with .CustomBlock }}
{{ range $index, $element := . }}
conflicts_with "{{ . }}"
{{ . }}
{{- end }}
{{- end }}
Expand All @@ -166,21 +166,23 @@ class {{ .Name }} < Formula
{{- with .Caveats }}
def caveats; <<~EOS
def caveats
<<~EOS
{{- range $index, $element := . }}
{{ . -}}
{{ . -}}
{{- end }}
EOS
EOS
end
{{- end -}}
{{- with .Plist }}
plist_options :startup => false
plist_options startup: false
def plist; <<~EOS
{{ . }}
EOS
def plist
<<~EOS
{{ . }}
EOS
end
{{- end -}}
Expand Down
30 changes: 16 additions & 14 deletions internal/pipe/brew/testdata/TestFullFormulae.rb.golden
Expand Up @@ -8,6 +8,8 @@ class Test < Formula
version "0.1.3"
license "MIT"

depends_on "gtk+"

on_macos do
if Hardware::CPU.intel?
url "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Darwin_x86_64.tar.gz"
Expand All @@ -19,7 +21,7 @@ class Test < Formula
end
if Hardware::CPU.arm?
url "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Darwin_arm64.tar.gz"
sha256 "1633f61598ab0791e213135923624eb342196b349490sadasdsadsadasdasdsd"
sha256 "1df5fdc2bad4ed4c28fbdc77b6c542988c0dc0e2ae34e0dc912bbb1c66646c58"

def install
bin.install "test"
Expand Down Expand Up @@ -54,33 +56,33 @@ class Test < Formula
end
end

conflicts_with "svn"

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 post_install
system "touch", "/tmp/foo"
touch "/tmp/foo"
system "echo", "done"
end

def caveats; <<~EOS
Here are some caveats
EOS
def caveats
<<~EOS
Here are some caveats
EOS
end

plist_options :startup => false
plist_options startup: false

def plist; <<~EOS
it works
EOS
def plist
<<~EOS
it works
EOS
end

test do
system "#{bin}/foo -version"
system "#{bin}/foo", "-version"
end
end
Expand Up @@ -19,7 +19,7 @@ class Test < Formula
end
if Hardware::CPU.arm?
url "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Darwin_arm64.tar.gz"
sha256 "1633f61598ab0791e213135923624eb342196b349490sadasdsadsadasdasdsd"
sha256 "1df5fdc2bad4ed4c28fbdc77b6c542988c0dc0e2ae34e0dc912bbb1c66646c58"

def install
bin.install "test"
Expand Down
32 changes: 17 additions & 15 deletions internal/pipe/brew/testdata/TestFullPipe/custom_block.rb.golden
Expand Up @@ -3,9 +3,12 @@

# This file was generated by GoReleaser. DO NOT EDIT.
class CustomBlock < Formula
desc "A run pipe test formula and FOO=foo_is_bar"
desc "Run pipe test formula and FOO=foo_is_bar"
homepage "https://github.com/goreleaser"
version "1.0.1"

depends_on "zsh" => :optional
depends_on "bash"
depends_on :macos

on_macos do
Expand All @@ -27,29 +30,28 @@ class CustomBlock < Formula
end
end

head "https://github.com/caarlos0/test.git"

depends_on "zsh" => :optional
depends_on "bash"

conflicts_with "gtk+"
conflicts_with "qt"

head "https://github.com/caarlos0/test.git"

def post_install
system "echo"
system "touch" "/tmp/hi"
touch "/tmp/hi"
end

def caveats; <<~EOS
don't do this custom_block
EOS
def caveats
<<~EOS
don't do this custom_block
EOS
end

plist_options :startup => false
plist_options startup: false

def plist; <<~EOS
<xml>whatever</xml>
EOS
def plist
<<~EOS
<xml>whatever</xml>
EOS
end

service do
Expand All @@ -59,6 +61,6 @@ class CustomBlock < Formula

test do
system "true"
system "#{bin}/foo -h"
system "#{bin}/foo", "-h"
end
end

0 comments on commit d630605

Please sign in to comment.