From 3c1f856ddf9ea9452ac6fdb5a0e3dc3eaaee38e3 Mon Sep 17 00:00:00 2001 From: Dominik Schulz Date: Wed, 28 Mar 2018 16:14:27 +0200 Subject: [PATCH] fix: improve homebrew formula This commit improves the homebrew formula pipeline step to support more customizations. --- config/config.go | 31 +++++----- docs/120-homebrew.md | 11 ++++ pipeline/brew/brew.go | 34 +++++------ pipeline/brew/brew_test.go | 2 +- pipeline/brew/template.go | 56 ++++++++++++------- pipeline/brew/testdata/run_pipe.rb.golden | 9 ++- .../run_pipe_download_strategy.rb.golden | 9 ++- .../testdata/run_pipe_enterprise.rb.golden | 9 ++- pipeline/brew/testdata/test.rb.golden | 8 ++- 9 files changed, 107 insertions(+), 62 deletions(-) diff --git a/config/config.go b/config/config.go index 007d19d4a..a57faf73e 100644 --- a/config/config.go +++ b/config/config.go @@ -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 diff --git a/docs/120-homebrew.md b/docs/120-homebrew.md index 37f69b60e..a2ac7bcc8 100644 --- a/docs/120-homebrew.md +++ b/docs/120-homebrew.md @@ -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: | diff --git a/pipeline/brew/brew.go b/pipeline/brew/brew.go index c61606d94..3b3164fc6 100644 --- a/pipeline/brew/brew.go +++ b/pipeline/brew/brew.go @@ -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 } diff --git a/pipeline/brew/brew_test.go b/pipeline/brew/brew_test.go index 7b433ccb4..111b9d4e3 100644 --- a/pipeline/brew/brew_test.go +++ b/pipeline/brew/brew_test.go @@ -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" diff --git a/pipeline/brew/template.go b/pipeline/brew/template.go index 392c9db07..a6fffa9b7 100644 --- a/pipeline/brew/template.go +++ b/pipeline/brew/template.go @@ -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 -}} diff --git a/pipeline/brew/testdata/run_pipe.rb.golden b/pipeline/brew/testdata/run_pipe.rb.golden index 72b0fcfcf..acc1e53e2 100644 --- a/pipeline/brew/testdata/run_pipe.rb.golden +++ b/pipeline/brew/testdata/run_pipe.rb.golden @@ -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 whatever - EOS + EOS end test do diff --git a/pipeline/brew/testdata/run_pipe_download_strategy.rb.golden b/pipeline/brew/testdata/run_pipe_download_strategy.rb.golden index fe5efc9b6..16f6ff58b 100644 --- a/pipeline/brew/testdata/run_pipe_download_strategy.rb.golden +++ b/pipeline/brew/testdata/run_pipe_download_strategy.rb.golden @@ -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 whatever - EOS + EOS end test do diff --git a/pipeline/brew/testdata/run_pipe_enterprise.rb.golden b/pipeline/brew/testdata/run_pipe_enterprise.rb.golden index d0df1ac82..752770a5c 100644 --- a/pipeline/brew/testdata/run_pipe_enterprise.rb.golden +++ b/pipeline/brew/testdata/run_pipe_enterprise.rb.golden @@ -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 whatever - EOS + EOS end test do diff --git a/pipeline/brew/testdata/test.rb.golden b/pipeline/brew/testdata/test.rb.golden index 9c110e37f..285d0552d 100644 --- a/pipeline/brew/testdata/test.rb.golden +++ b/pipeline/brew/testdata/test.rb.golden @@ -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