1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-24 04:16:27 +02:00

Merge pull request #307 from goreleaser/brew-test

homebrew test support
This commit is contained in:
Carlos Alexandro Becker 2017-07-16 13:09:42 -03:00 committed by GitHub
commit 8b5a11381d
5 changed files with 32 additions and 10 deletions

View File

@ -29,6 +29,8 @@ brew:
folder: Formula folder: Formula
homepage: http://goreleaser.github.io homepage: http://goreleaser.github.io
description: Deliver Go binaries as fast and easily as possible description: Deliver Go binaries as fast and easily as possible
test: |
system "#{bin}/goreleaser -v"
dependencies: dependencies:
- git - git
fpm: fpm:

View File

@ -377,13 +377,18 @@ brew:
- svn - svn
- bash - bash
# Packages that run as a service # So you can brew test your formula. Default is empty.
plist:| plist: |
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
... ...
# Custom install script for brew. Default: "bin.install "program" # Packages that run as a service. Default is empty.
install:| test: |
system "#{bin}/program --version"
...
# Custom install script for brew. Default is 'bin.install "program"'
install: |
bin.install "program" bin.install "program"
... ...
``` ```

View File

@ -35,6 +35,7 @@ type Homebrew struct {
Plist string `yaml:",omitempty"` Plist string `yaml:",omitempty"`
Install string `yaml:",omitempty"` Install string `yaml:",omitempty"`
Dependencies []string `yaml:",omitempty"` Dependencies []string `yaml:",omitempty"`
Test string `yaml:",omitempty"`
Conflicts []string `yaml:",omitempty"` Conflicts []string `yaml:",omitempty"`
Description string `yaml:",omitempty"` Description string `yaml:",omitempty"`
Homepage string `yaml:",omitempty"` Homepage string `yaml:",omitempty"`

View File

@ -30,12 +30,14 @@ const formula = `class {{ .Name }} < Formula
version "{{ .Version }}" version "{{ .Version }}"
sha256 "{{ .SHA256 }}" sha256 "{{ .SHA256 }}"
{{- if .Dependencies }} {{- if .Dependencies }}
{{ range $index, $element := .Dependencies }} {{ range $index, $element := .Dependencies }}
depends_on "{{ . }}" depends_on "{{ . }}"
{{- end }} {{- end }}
{{- end }} {{- end }}
{{- if .Conflicts }} {{- if .Conflicts }}
{{ range $index, $element := .Conflicts }} {{ range $index, $element := .Conflicts }}
conflicts_with "{{ . }}" conflicts_with "{{ . }}"
@ -48,18 +50,25 @@ const formula = `class {{ .Name }} < Formula
{{- end }} {{- end }}
end end
{{- if .Caveats }}
{{- if .Caveats }}
def caveats def caveats
"{{ .Caveats }}" "{{ .Caveats }}"
end end
{{- end }} {{- end }}
{{- if .Plist }}
{{- if .Plist }}
def plist; <<-EOS.undent def plist; <<-EOS.undent
{{ .Plist }} {{ .Plist }}
EOS EOS
end
{{- end }}
{{- if .Test }}
def test
{{ .Test }}
end end
{{- end }} {{- end }}
end end
@ -79,6 +88,7 @@ type templateData struct {
Install []string Install []string
Dependencies []string Dependencies []string
Conflicts []string Conflicts []string
Test string
} }
// Pipe for brew deployment // Pipe for brew deployment
@ -168,6 +178,7 @@ func dataFor(ctx *context.Context, client client.Client, folder string) (result
Dependencies: ctx.Config.Brew.Dependencies, Dependencies: ctx.Config.Brew.Dependencies,
Conflicts: ctx.Config.Brew.Conflicts, Conflicts: ctx.Config.Brew.Conflicts,
Plist: ctx.Config.Brew.Plist, Plist: ctx.Config.Brew.Plist,
Test: ctx.Config.Brew.Test,
Install: strings.Split(ctx.Config.Brew.Install, "\n"), Install: strings.Split(ctx.Config.Brew.Install, "\n"),
}, err }, err
} }

View File

@ -59,18 +59,21 @@ func TestFullFormulae(t *testing.T) {
data.Conflicts = []string{"conflicting_dep"} data.Conflicts = []string{"conflicting_dep"}
data.Plist = "it works" data.Plist = "it works"
data.Install = []string{"custom install script", "another install script"} data.Install = []string{"custom install script", "another install script"}
data.Test = `system "#{bin}/foo -version"`
out, err := doBuildFormula(data) out, err := doBuildFormula(data)
assert.NoError(err) assert.NoError(err)
formulae := out.String() formulae := out.String()
assertDefaultTemplateData(t, formulae) assertDefaultTemplateData(t, formulae)
assert.Contains(formulae, "def caveats") assert.Contains(formulae, "def caveats")
assert.Contains(formulae, "Here are some caveats") assert.Contains(formulae, "Here are some caveats")
assert.Contains(formulae, "depends_on \"gtk\"") assert.Contains(formulae, `depends_on "gtk"`)
assert.Contains(formulae, "depends_on \"git\"") assert.Contains(formulae, `depends_on "git"`)
assert.Contains(formulae, "conflicts_with \"conflicting_dep\"") assert.Contains(formulae, `conflicts_with "conflicting_dep"`)
assert.Contains(formulae, "custom install script") assert.Contains(formulae, "custom install script")
assert.Contains(formulae, "another install script") assert.Contains(formulae, "another install script")
assert.Contains(formulae, "def plist;") assert.Contains(formulae, "def plist;")
assert.Contains(formulae, "def test")
assert.Contains(formulae, `system "#{bin}/foo -version"`)
} }
func TestFormulaeSimple(t *testing.T) { func TestFormulaeSimple(t *testing.T) {