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

fix: improve homebrew formula

This commit improves the homebrew formula pipeline step to support
more customizations.
This commit is contained in:
Dominik Schulz 2018-03-28 16:14:27 +02:00 committed by Carlos Alexandro Becker
parent fe85f656e2
commit 3c1f856ddf
9 changed files with 107 additions and 62 deletions

View File

@ -34,20 +34,23 @@ func (r Repo) String() string {
// Homebrew contains the brew section
type Homebrew struct {
Name string `yaml:",omitempty"`
GitHub Repo `yaml:",omitempty"`
CommitAuthor CommitAuthor `yaml:"commit_author,omitempty"`
Folder string `yaml:",omitempty"`
Caveats string `yaml:",omitempty"`
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"`
SkipUpload bool `yaml:"skip_upload,omitempty"`
DownloadStrategy string `yaml:"download_strategy,omitempty"`
Name string `yaml:",omitempty"`
GitHub Repo `yaml:",omitempty"`
CommitAuthor CommitAuthor `yaml:"commit_author,omitempty"`
Folder string `yaml:",omitempty"`
Caveats string `yaml:",omitempty"`
Plist string `yaml:",omitempty"`
Install string `yaml:",omitempty"`
Dependencies []string `yaml:",omitempty"`
BuildDependencies []string `yaml:"build_dependencies,omitempty"`
Test string `yaml:",omitempty"`
Special string `yaml:",omitempty"`
Conflicts []string `yaml:",omitempty"`
Description string `yaml:",omitempty"`
Homepage string `yaml:",omitempty"`
SkipUpload bool `yaml:"skip_upload,omitempty"`
DownloadStrategy string `yaml:"download_strategy,omitempty"`
SourceTarball string `yaml:"-"`
}
// Scoop contains the scoop.sh section

View File

@ -61,6 +61,11 @@ brew:
- git
- zsh
# Packages your source package depends on.
build_dependencies:
- make
- gcc
# Packages that conflict with your package.
conflicts:
- svn
@ -78,6 +83,12 @@ brew:
system "#{bin}/program --version"
...
# Specify any additional formula content in the special section.
# Default is empty.
special: |
system "make completion"
...
# Custom install script for brew.
# Default is 'bin.install "program"'.
install: |

View File

@ -165,22 +165,24 @@ func dataFor(ctx *context.Context, client client.Client, artifact artifact.Artif
}
var cfg = ctx.Config.Brew
return templateData{
Name: formulaNameFor(ctx.Config.Brew.Name),
DownloadURL: ctx.Config.GitHubURLs.Download,
Desc: cfg.Description,
Homepage: cfg.Homepage,
Repo: ctx.Config.Release.GitHub,
Tag: ctx.Git.CurrentTag,
Version: ctx.Version,
Caveats: cfg.Caveats,
File: artifact.Name,
SHA256: sum,
Dependencies: cfg.Dependencies,
Conflicts: cfg.Conflicts,
Plist: cfg.Plist,
Install: split(cfg.Install),
Tests: split(cfg.Test),
DownloadStrategy: cfg.DownloadStrategy,
Name: formulaNameFor(ctx.Config.Brew.Name),
DownloadURL: ctx.Config.GitHubURLs.Download,
Desc: cfg.Description,
Homepage: cfg.Homepage,
Repo: ctx.Config.Release.GitHub,
Tag: ctx.Git.CurrentTag,
Version: ctx.Version,
Caveats: split(cfg.Caveats),
File: artifact.Name,
SHA256: sum,
Dependencies: cfg.Dependencies,
BuildDependencies: cfg.BuildDependencies,
Conflicts: cfg.Conflicts,
Plist: cfg.Plist,
Install: split(cfg.Install),
Tests: split(cfg.Test),
Special: split(cfg.Special),
DownloadStrategy: cfg.DownloadStrategy,
}, nil
}

View File

@ -58,7 +58,7 @@ func assertDefaultTemplateData(t *testing.T, formulae string) {
func TestFullFormulae(t *testing.T) {
data := defaultTemplateData
data.Caveats = "Here are some caveats"
data.Caveats = []string{"Here are some caveats"}
data.Dependencies = []string{"gtk+"}
data.Conflicts = []string{"svn"}
data.Plist = "it works"

View File

@ -3,22 +3,24 @@ package brew
import "github.com/goreleaser/goreleaser/config"
type templateData struct {
Name string
Desc string
Homepage string
DownloadURL 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
DownloadStrategy string
Install []string
Dependencies []string
Conflicts []string
Tests []string
Name string
Desc string
Homepage string
DownloadURL 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
DownloadStrategy string
Install []string
Dependencies []string
BuildDependencies []string
Conflicts []string
Tests []string
Special []string
}
const formulaTemplate = `class {{ .Name }} < Formula
@ -28,6 +30,13 @@ const formulaTemplate = `class {{ .Name }} < Formula
{{- if .DownloadStrategy }}, :using => {{ .DownloadStrategy }}{{- end }}
version "{{ .Version }}"
sha256 "{{ .SHA256 }}"
head "https://github.com/{{ .Repo.Owner }}/{{ .Repo.Name }}.git"
{{- if .BuildDependencies }}
{{ range $index, $element := .BuildDependencies }}
depends_on "{{ . }}" => :build
{{- end }}
{{- end -}}
{{- if .Dependencies }}
{{ range $index, $element := .Dependencies }}
@ -41,6 +50,12 @@ const formulaTemplate = `class {{ .Name }} < Formula
{{- end }}
{{- end }}
{{- if .Special }}
{{- range $index, $element := .Special }}
{{ . -}}
{{- end -}}
{{- end }}
def install
{{- range $index, $element := .Install }}
{{ . -}}
@ -49,8 +64,11 @@ const formulaTemplate = `class {{ .Name }} < Formula
{{- if .Caveats }}
def caveats
"{{ .Caveats }}"
def caveats; <<-EOS.undent
{{- range $index, $element := .Caveats }}
{{ . -}}
{{- end }}
EOS
end
{{- end -}}
@ -60,7 +78,7 @@ const formulaTemplate = `class {{ .Name }} < Formula
def plist; <<~EOS
{{ .Plist }}
EOS
EOS
end
{{- end -}}

View File

@ -4,26 +4,29 @@ class RunPipe < Formula
url "https://github.com/test/test/releases/download/v1.0.1/bin.tar.gz"
version "1.0.1"
sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
head "https://github.com/test/test.git"
depends_on "zsh"
depends_on "bash"
conflicts_with "gtk+"
conflicts_with "qt"
def install
bin.install "foo"
end
def caveats
"don't do this"
def caveats; <<-EOS.undent
don't do this
EOS
end
plist_options :startup => false
def plist; <<~EOS
<xml>whatever</xml>
EOS
EOS
end
test do

View File

@ -4,26 +4,29 @@ class RunPipe < Formula
url "http://github.example.org/test/test/releases/download/v1.0.1/bin.tar.gz", :using => GitHubPrivateRepositoryReleaseDownloadStrategy
version "1.0.1"
sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
head "https://github.com/test/test.git"
depends_on "zsh"
depends_on "bash"
conflicts_with "gtk+"
conflicts_with "qt"
def install
bin.install "foo"
end
def caveats
"don't do this"
def caveats; <<-EOS.undent
don't do this
EOS
end
plist_options :startup => false
def plist; <<~EOS
<xml>whatever</xml>
EOS
EOS
end
test do

View File

@ -4,26 +4,29 @@ class RunPipe < Formula
url "http://github.example.org/test/test/releases/download/v1.0.1/bin.tar.gz"
version "1.0.1"
sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
head "https://github.com/test/test.git"
depends_on "zsh"
depends_on "bash"
conflicts_with "gtk+"
conflicts_with "qt"
def install
bin.install "foo"
end
def caveats
"don't do this"
def caveats; <<-EOS.undent
don't do this
EOS
end
plist_options :startup => false
def plist; <<~EOS
<xml>whatever</xml>
EOS
EOS
end
test do

View File

@ -4,6 +4,7 @@ class Test < Formula
url "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Darwin_x86_64.tar.gz"
version "0.1.3"
sha256 "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c68"
head "https://github.com/caarlos0/test.git"
depends_on "gtk+"
@ -14,15 +15,16 @@ class Test < Formula
another install script
end
def caveats
"Here are some caveats"
def caveats; <<-EOS.undent
Here are some caveats
EOS
end
plist_options :startup => false
def plist; <<~EOS
it works
EOS
EOS
end
test do