diff --git a/.goreleaser.yml b/.goreleaser.yml index 8f1a31142..f1fe588f8 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -31,8 +31,6 @@ brew: description: Deliver Go binaries as fast and easily as possible test: | system "#{bin}/goreleaser -v" - dependencies: - - git fpm: homepage: http://goreleaser.github.io description: Deliver Go binaries as fast and easily as possible diff --git a/pipeline/brew/brew.go b/pipeline/brew/brew.go index 99cca0e7f..1475d8745 100644 --- a/pipeline/brew/brew.go +++ b/pipeline/brew/brew.go @@ -11,7 +11,6 @@ import ( "github.com/apex/log" "github.com/goreleaser/goreleaser/checksum" - "github.com/goreleaser/goreleaser/config" "github.com/goreleaser/goreleaser/context" "github.com/goreleaser/goreleaser/internal/archiveformat" "github.com/goreleaser/goreleaser/internal/client" @@ -23,74 +22,6 @@ var ErrNoDarwin64Build = errors.New("brew tap requires a darwin amd64 build") const platform = "darwinamd64" -const formula = `class {{ .Name }} < Formula - desc "{{ .Desc }}" - homepage "{{ .Homepage }}" - url "https://github.com/{{ .Repo.Owner }}/{{ .Repo.Name }}/releases/download/{{ .Tag }}/{{ .File }}" - version "{{ .Version }}" - sha256 "{{ .SHA256 }}" - - - {{- if .Dependencies }} - {{ range $index, $element := .Dependencies }} - depends_on "{{ . }}" - {{- end }} - {{- end }} - - - {{- if .Conflicts }} - {{ range $index, $element := .Conflicts }} - conflicts_with "{{ . }}" - {{- end }} - {{- end }} - - def install - {{- range $index, $element := .Install }} - {{ . -}} - {{- end }} - end - - - {{- if .Caveats }} - def caveats - "{{ .Caveats }}" - end - {{- end }} - - - {{- if .Plist }} - def plist; <<-EOS.undent - {{ .Plist }} - EOS - end - {{- end }} - - - {{- if .Test }} - def test - {{ .Test }} - end - {{- end }} -end -` - -type templateData struct { - Name string - Desc string - Homepage string - Repo config.Repo // FIXME: will not work for anything but github right now. - Tag string - Version string - Caveats string - File string - SHA256 string - Plist string - Install []string - Dependencies []string - Conflicts []string - Test string -} - // Pipe for brew deployment type Pipe struct{} @@ -118,9 +49,10 @@ func doRun(ctx *context.Context, client client.Client) error { return nil } if ctx.Config.Archive.Format == "binary" { - log.Info("skipped because archive format is binary") + log.Warn("skipped because archive format is binary") return nil } + var group = ctx.Binaries["darwinamd64"] if group == nil { return ErrNoDarwin64Build @@ -149,14 +81,13 @@ func buildFormula(ctx *context.Context, client client.Client, folder string) (by return doBuildFormula(data) } -func doBuildFormula(data templateData) (bytes.Buffer, error) { - var out bytes.Buffer - tmpl, err := template.New(data.Name).Parse(formula) +func doBuildFormula(data templateData) (out bytes.Buffer, err error) { + tmpl, err := template.New(data.Name).Parse(formulaTemplate) if err != nil { return out, err } err = tmpl.Execute(&out, data) - return out, err + return } func dataFor(ctx *context.Context, client client.Client, folder string) (result templateData, err error) { @@ -178,9 +109,9 @@ func dataFor(ctx *context.Context, client client.Client, folder string) (result Dependencies: ctx.Config.Brew.Dependencies, Conflicts: ctx.Config.Brew.Conflicts, Plist: ctx.Config.Brew.Plist, - Test: ctx.Config.Brew.Test, Install: strings.Split(ctx.Config.Brew.Install, "\n"), - }, err + Tests: strings.Split(ctx.Config.Brew.Test, "\n"), + }, nil } func formulaNameFor(name string) string { diff --git a/pipeline/brew/brew_test.go b/pipeline/brew/brew_test.go index 84aa08449..64b83cedf 100644 --- a/pipeline/brew/brew_test.go +++ b/pipeline/brew/brew_test.go @@ -55,25 +55,21 @@ func TestFullFormulae(t *testing.T) { assert := assert.New(t) data := defaultTemplateData data.Caveats = "Here are some caveats" - data.Dependencies = []string{"gtk", "git"} - data.Conflicts = []string{"conflicting_dep"} + data.Dependencies = []string{"gtk+"} + data.Conflicts = []string{"svn"} data.Plist = "it works" data.Install = []string{"custom install script", "another install script"} - data.Test = `system "#{bin}/foo -version"` + data.Tests = []string{`system "#{bin}/foo -version"`} out, err := doBuildFormula(data) assert.NoError(err) formulae := out.String() - assertDefaultTemplateData(t, formulae) - assert.Contains(formulae, "def caveats") - assert.Contains(formulae, "Here are some caveats") - assert.Contains(formulae, `depends_on "gtk"`) - assert.Contains(formulae, `depends_on "git"`) - assert.Contains(formulae, `conflicts_with "conflicting_dep"`) - assert.Contains(formulae, "custom install script") - assert.Contains(formulae, "another install script") - assert.Contains(formulae, "def plist;") - assert.Contains(formulae, "def test") - assert.Contains(formulae, `system "#{bin}/foo -version"`) + + f, err := os.Open("testdata/test.rb") + assert.NoError(err) + bts, err := ioutil.ReadAll(f) + assert.NoError(err) + + assert.Equal(string(bts), formulae) } func TestFormulaeSimple(t *testing.T) { diff --git a/pipeline/brew/template.go b/pipeline/brew/template.go new file mode 100644 index 000000000..87e5b74de --- /dev/null +++ b/pipeline/brew/template.go @@ -0,0 +1,74 @@ +package brew + +import "github.com/goreleaser/goreleaser/config" + +type templateData struct { + Name string + Desc string + Homepage string + Repo config.Repo // FIXME: will not work for anything but github right now. + Tag string + Version string + Caveats string + File string + SHA256 string + Plist string + Install []string + Dependencies []string + Conflicts []string + Tests []string +} + +const formulaTemplate = `class {{ .Name }} < Formula + desc "{{ .Desc }}" + homepage "{{ .Homepage }}" + url "https://github.com/{{ .Repo.Owner }}/{{ .Repo.Name }}/releases/download/{{ .Tag }}/{{ .File }}" + version "{{ .Version }}" + sha256 "{{ .SHA256 }}" + + {{- if .Dependencies }} + + {{ range $index, $element := .Dependencies -}} + depends_on "{{ . }}" + {{- end }} + {{- end -}} + + {{- if .Conflicts }} + {{ range $index, $element := .Conflicts -}} + conflicts_with "{{ . }}" + {{- end }} + {{- end }} + + def install + {{- range $index, $element := .Install }} + {{ . -}} + {{- end }} + end + + {{- if .Caveats }} + + def caveats + "{{ .Caveats }}" + end + {{- end -}} + + {{- if .Plist }} + + plist_options :startup => false + + def plist; <<-EOS.undent + {{ .Plist }} + EOS + end + {{- end -}} + + {{- if .Tests }} + + test do + {{- range $index, $element := .Tests }} + {{ . -}} + {{- end }} + end + {{- end }} +end +` diff --git a/pipeline/brew/testdata/test.rb b/pipeline/brew/testdata/test.rb new file mode 100644 index 000000000..242b56f8d --- /dev/null +++ b/pipeline/brew/testdata/test.rb @@ -0,0 +1,30 @@ +class Test < Formula + desc "Some desc" + homepage "https://google.com" + url "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Darwin_x86_64.tar.gz" + version "0.1.3" + sha256 "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c68" + + depends_on "gtk+" + conflicts_with "svn" + + def install + custom install script + another install script + end + + def caveats + "Here are some caveats" + end + + plist_options :startup => false + + def plist; <<-EOS.undent + it works + EOS + end + + test do + system "#{bin}/foo -version" + end +end