mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-02-09 13:36:56 +02:00
Merge pull request #308 from goreleaser/brew-test
Improve brew pipe code and the template itself
This commit is contained in:
commit
a8a9f3bef9
@ -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
|
||||
|
@ -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 {
|
||||
|
@ -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) {
|
||||
|
74
pipeline/brew/template.go
Normal file
74
pipeline/brew/template.go
Normal file
@ -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
|
||||
`
|
30
pipeline/brew/testdata/test.rb
vendored
Normal file
30
pipeline/brew/testdata/test.rb
vendored
Normal file
@ -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
|
Loading…
x
Reference in New Issue
Block a user