mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-01-10 03:47:03 +02:00
wip improving formulaes
This commit is contained in:
parent
8b5a11381d
commit
a3db024e98
@ -5,13 +5,13 @@ package brew
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"text/template"
|
||||
|
||||
"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 +23,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{}
|
||||
|
||||
@ -117,8 +49,8 @@ func doRun(ctx *context.Context, client client.Client) error {
|
||||
log.Warn("skipped because release is marked as draft")
|
||||
return nil
|
||||
}
|
||||
if ctx.Config.Archive.Format == "binary" {
|
||||
log.Info("skipped because archive format is binary")
|
||||
if ctx.Config.Archive.Format == "binary" && len(ctx.Config.Builds) > 1 {
|
||||
log.Warn("brew formulas can't be generated with multiple builds released in binary format")
|
||||
return nil
|
||||
}
|
||||
var group = ctx.Binaries["darwinamd64"]
|
||||
@ -138,7 +70,8 @@ func doRun(ctx *context.Context, client client.Client) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return client.CreateFile(ctx, content, path)
|
||||
fmt.Println(content.String())
|
||||
return nil //client.CreateFile(ctx, content, path)
|
||||
}
|
||||
|
||||
func buildFormula(ctx *context.Context, client client.Client, folder string) (bytes.Buffer, error) {
|
||||
@ -149,14 +82,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 +110,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 {
|
||||
|
@ -2,6 +2,7 @@ package brew
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@ -55,25 +56,24 @@ 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)
|
||||
|
||||
f2, err := os.Create("testdata/full_formula.rb")
|
||||
assert.NoError(err)
|
||||
fmt.Fprintf(f2, formulae)
|
||||
assert.Equal(string(bts), formulae)
|
||||
}
|
||||
|
||||
func TestFormulaeSimple(t *testing.T) {
|
||||
|
73
pipeline/brew/template.go
Normal file
73
pipeline/brew/template.go
Normal file
@ -0,0 +1,73 @@
|
||||
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
|
||||
`
|
31
pipeline/brew/testdata/full_formula.rb
vendored
Normal file
31
pipeline/brew/testdata/full_formula.rb
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
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
|
31
pipeline/brew/testdata/test.rb
vendored
Normal file
31
pipeline/brew/testdata/test.rb
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
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…
Reference in New Issue
Block a user