From 938b50c399b25b0c33f447e6bfbb9303bd6c0a81 Mon Sep 17 00:00:00 2001 From: Paulo Sousa Date: Thu, 9 Mar 2017 14:24:49 -0300 Subject: [PATCH 1/3] homebrew: add custom install command --- README.md | 7 ++++++- config/config.go | 1 + pipeline/brew/brew.go | 14 ++++++++++++++ pipeline/brew/brew_test.go | 8 ++++++-- 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9265f3e38..e26e87611 100644 --- a/README.md +++ b/README.md @@ -280,9 +280,14 @@ brew: - bash # Packages that run as a service - plist: + plist:| ... + + # Custom install script for brew. Default: "bin.install "program" + install:| + bin.install "program" + ... ``` By defining the `brew` section, GoReleaser will take care of publishing the Homebrew tap. diff --git a/config/config.go b/config/config.go index d3e9132c1..aab5b195c 100644 --- a/config/config.go +++ b/config/config.go @@ -12,6 +12,7 @@ type Homebrew struct { Folder string Caveats string Plist string + Install string Dependencies []string Conflicts []string } diff --git a/pipeline/brew/brew.go b/pipeline/brew/brew.go index 836da1520..44dab5e2c 100644 --- a/pipeline/brew/brew.go +++ b/pipeline/brew/brew.go @@ -37,10 +37,22 @@ const formula = `class {{ .Name }} < Formula {{- end }} {{- end }} + {{- if .Install }} + + def install + {{- range $index, $element := .Install }} + {{ . -}} + {{- end }} + end + + {{- else }} + def install bin.install "{{ .BinaryName }}" end + {{- end }} + {{- if .Caveats }} def caveats @@ -71,6 +83,7 @@ type templateData struct { Format string SHA256 string Plist string + Install []string Dependencies []string Conflicts []string } @@ -188,6 +201,7 @@ func dataFor( Dependencies: ctx.Config.Brew.Dependencies, Conflicts: ctx.Config.Brew.Conflicts, Plist: ctx.Config.Brew.Plist, + Install: strings.Split(ctx.Config.Brew.Install, "\n"), }, err } diff --git a/pipeline/brew/brew_test.go b/pipeline/brew/brew_test.go index c78d7427e..1e90283f9 100644 --- a/pipeline/brew/brew_test.go +++ b/pipeline/brew/brew_test.go @@ -29,7 +29,6 @@ var defaultTemplateData = templateData{ File: "test_Darwin_x86_64", SHA256: "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c68", Format: "tar.gz", - Plist: "it works", } func assertDefaultTemplateData(t *testing.T, formulae string) { @@ -39,7 +38,6 @@ func assertDefaultTemplateData(t *testing.T, formulae string) { assert.Contains(formulae, "url \"https://github.com/caarlos0/test/releases/download/v0.1.3/test_Darwin_x86_64.tar.gz\"") assert.Contains(formulae, "sha256 \"1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c68\"") assert.Contains(formulae, "version \"0.1.3\"") - assert.Contains(formulae, "bin.install \"test\"") } func TestFullFormulae(t *testing.T) { @@ -48,6 +46,8 @@ func TestFullFormulae(t *testing.T) { data.Caveats = "Here are some caveats" data.Dependencies = []string{"gtk", "git"} data.Conflicts = []string{"conflicting_dep"} + data.Plist = "it works" + data.Install = []string{"custom install script", "another install script"} out, err := doBuildFormula(data) assert.NoError(err) formulae := out.String() @@ -57,6 +57,8 @@ func TestFullFormulae(t *testing.T) { 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;") } @@ -66,6 +68,8 @@ func TestFormulaeSimple(t *testing.T) { assert.NoError(err) formulae := out.String() assertDefaultTemplateData(t, formulae) + assert.Contains(formulae, "bin.install \"test\"") assert.NotContains(formulae, "def caveats") assert.NotContains(formulae, "depends_on") + assert.NotContains(formulae, "def plist;") } From a5104aca17d35a1dbeb7ae1559af359d84d487df Mon Sep 17 00:00:00 2001 From: Paulo Sousa Date: Thu, 9 Mar 2017 15:33:45 -0300 Subject: [PATCH 2/3] homebrew: fix indent on template and remove install commands logic from it --- pipeline/brew/brew.go | 21 +++++++++------------ pipeline/brew/brew_test.go | 1 - 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/pipeline/brew/brew.go b/pipeline/brew/brew.go index 44dab5e2c..320aa3086 100644 --- a/pipeline/brew/brew.go +++ b/pipeline/brew/brew.go @@ -37,22 +37,12 @@ const formula = `class {{ .Name }} < Formula {{- end }} {{- end }} - {{- if .Install }} - def install {{- range $index, $element := .Install }} {{ . -}} - {{- end }} + {{- end }} end - {{- else }} - - def install - bin.install "{{ .BinaryName }}" - end - - {{- end }} - {{- if .Caveats }} def caveats @@ -162,6 +152,7 @@ func dataFor( ) (result templateData, err error) { var homepage string var description string + var installCmds string rep, _, err := client.Repositories.Get( ctx, ctx.ReleaseRepo.Owner, ctx.ReleaseRepo.Name, ) @@ -186,6 +177,12 @@ func dataFor( } else { description = *rep.Description } + if ctx.Config.Brew.Install != "" { + installCmds = ctx.Config.Brew.Install + } else { + installCmds = "bin.install \"" + ctx.Config.Build.BinaryName + "\"" + } + return templateData{ Name: formulaNameFor(ctx.Config.Build.BinaryName), Desc: description, @@ -201,7 +198,7 @@ func dataFor( Dependencies: ctx.Config.Brew.Dependencies, Conflicts: ctx.Config.Brew.Conflicts, Plist: ctx.Config.Brew.Plist, - Install: strings.Split(ctx.Config.Brew.Install, "\n"), + Install: strings.Split(installCmds, "\n"), }, err } diff --git a/pipeline/brew/brew_test.go b/pipeline/brew/brew_test.go index 1e90283f9..a86f5f0e8 100644 --- a/pipeline/brew/brew_test.go +++ b/pipeline/brew/brew_test.go @@ -68,7 +68,6 @@ func TestFormulaeSimple(t *testing.T) { assert.NoError(err) formulae := out.String() assertDefaultTemplateData(t, formulae) - assert.Contains(formulae, "bin.install \"test\"") assert.NotContains(formulae, "def caveats") assert.NotContains(formulae, "depends_on") assert.NotContains(formulae, "def plist;") From 3ed26ed83b083dbd4267ad6bf5fc5282b2e5942c Mon Sep 17 00:00:00 2001 From: Paulo Sousa Date: Thu, 9 Mar 2017 16:33:17 -0300 Subject: [PATCH 3/3] homebrew: move default install cmd to defaults pipe --- pipeline/brew/brew.go | 9 +-------- pipeline/defaults/defaults.go | 3 +++ pipeline/defaults/defaults_test.go | 1 + 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/pipeline/brew/brew.go b/pipeline/brew/brew.go index 320aa3086..68236339e 100644 --- a/pipeline/brew/brew.go +++ b/pipeline/brew/brew.go @@ -152,7 +152,6 @@ func dataFor( ) (result templateData, err error) { var homepage string var description string - var installCmds string rep, _, err := client.Repositories.Get( ctx, ctx.ReleaseRepo.Owner, ctx.ReleaseRepo.Name, ) @@ -177,12 +176,6 @@ func dataFor( } else { description = *rep.Description } - if ctx.Config.Brew.Install != "" { - installCmds = ctx.Config.Brew.Install - } else { - installCmds = "bin.install \"" + ctx.Config.Build.BinaryName + "\"" - } - return templateData{ Name: formulaNameFor(ctx.Config.Build.BinaryName), Desc: description, @@ -198,7 +191,7 @@ func dataFor( Dependencies: ctx.Config.Brew.Dependencies, Conflicts: ctx.Config.Brew.Conflicts, Plist: ctx.Config.Brew.Plist, - Install: strings.Split(installCmds, "\n"), + Install: strings.Split(ctx.Config.Brew.Install, "\n"), }, err } diff --git a/pipeline/defaults/defaults.go b/pipeline/defaults/defaults.go index d36655fad..a59e8a82d 100644 --- a/pipeline/defaults/defaults.go +++ b/pipeline/defaults/defaults.go @@ -69,6 +69,9 @@ func (Pipe) Run(ctx *context.Context) error { } ctx.Config.Archive.Files = files } + if ctx.Config.Brew.Install == "" { + ctx.Config.Brew.Install = "bin.install \"" + ctx.Config.Build.BinaryName + "\"" + } return nil } diff --git a/pipeline/defaults/defaults_test.go b/pipeline/defaults/defaults_test.go index a8b390d5e..9ac36069c 100644 --- a/pipeline/defaults/defaults_test.go +++ b/pipeline/defaults/defaults_test.go @@ -25,6 +25,7 @@ func TestFillBasicData(t *testing.T) { assert.Contains(ctx.Config.Build.Goos, "linux") assert.Contains(ctx.Config.Build.Goarch, "386") assert.Contains(ctx.Config.Build.Goarch, "amd64") + assert.Contains(ctx.Config.Brew.Install, "bin.install \"goreleaser\"") assert.NotEmpty( ctx.Config.Archive.Replacements, ctx.Config.Archive.NameTemplate,