diff --git a/.goreleaser.yml b/.goreleaser.yml index 921ec808b..8f1a31142 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -29,6 +29,8 @@ brew: folder: Formula homepage: http://goreleaser.github.io description: Deliver Go binaries as fast and easily as possible + test: | + system "#{bin}/goreleaser -v" dependencies: - git fpm: diff --git a/README.md b/README.md index d5ed8e0a0..5f736bd13 100644 --- a/README.md +++ b/README.md @@ -377,13 +377,18 @@ brew: - svn - bash - # Packages that run as a service - plist:| + # So you can brew test your formula. Default is empty. + plist: | ... - # Custom install script for brew. Default: "bin.install "program" - install:| + # Packages that run as a service. Default is empty. + test: | + system "#{bin}/program --version" + ... + + # Custom install script for brew. Default is 'bin.install "program"' + install: | bin.install "program" ... ``` diff --git a/config/config.go b/config/config.go index 39335eb2a..81f8030e8 100644 --- a/config/config.go +++ b/config/config.go @@ -35,6 +35,7 @@ type Homebrew struct { Plist string `yaml:",omitempty"` Install string `yaml:",omitempty"` Dependencies []string `yaml:",omitempty"` + Test string `yaml:",omitempty"` Conflicts []string `yaml:",omitempty"` Description string `yaml:",omitempty"` Homepage string `yaml:",omitempty"` diff --git a/pipeline/brew/brew.go b/pipeline/brew/brew.go index fbf9bc849..831901e9f 100644 --- a/pipeline/brew/brew.go +++ b/pipeline/brew/brew.go @@ -49,17 +49,21 @@ const formula = `class {{ .Name }} < Formula end {{- if .Caveats }} - def caveats "{{ .Caveats }}" end {{- end }} {{- if .Plist }} - def plist; <<-EOS.undent {{ .Plist }} - EOS + EOS + end + {{- end }} + + {{- if .Test }} + def test + {{ .Test }} end {{- end }} end @@ -79,6 +83,7 @@ type templateData struct { Install []string Dependencies []string Conflicts []string + Test string } // Pipe for brew deployment @@ -168,6 +173,7 @@ 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 } diff --git a/pipeline/brew/brew_test.go b/pipeline/brew/brew_test.go index 202e05d8a..84aa08449 100644 --- a/pipeline/brew/brew_test.go +++ b/pipeline/brew/brew_test.go @@ -59,18 +59,21 @@ func TestFullFormulae(t *testing.T) { data.Conflicts = []string{"conflicting_dep"} data.Plist = "it works" data.Install = []string{"custom install script", "another install script"} + data.Test = `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, `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"`) } func TestFormulaeSimple(t *testing.T) {