diff --git a/internal/pipe/brew/brew.go b/internal/pipe/brew/brew.go index af52f98ce..875def103 100644 --- a/internal/pipe/brew/brew.go +++ b/internal/pipe/brew/brew.go @@ -261,6 +261,7 @@ func dataFor(ctx *context.Context, cfg config.Homebrew, cl client.Client, artifa Conflicts: cfg.Conflicts, Plist: cfg.Plist, Install: split(cfg.Install), + PostInstall: cfg.PostInstall, Tests: split(cfg.Test), DownloadStrategy: cfg.DownloadStrategy, CustomRequire: cfg.CustomRequire, diff --git a/internal/pipe/brew/brew_test.go b/internal/pipe/brew/brew_test.go index 2956c818a..5520fa735 100644 --- a/internal/pipe/brew/brew_test.go +++ b/internal/pipe/brew/brew_test.go @@ -77,6 +77,7 @@ func TestFullFormulae(t *testing.T) { data.Dependencies = []config.HomebrewDependency{{Name: "gtk+"}} data.Conflicts = []string{"svn"} data.Plist = "it works" + data.PostInstall = `system "touch", "/tmp/foo"` data.CustomBlock = []string{"devel do", ` url "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Darwin_x86_64.tar.gz"`, ` sha256 "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c68"`, "end"} data.Install = []string{"custom install script", "another install script"} data.Tests = []string{`system "#{bin}/{{.ProjectName}} -version"`} diff --git a/internal/pipe/brew/template.go b/internal/pipe/brew/template.go index 207a7f9cb..7911db94a 100644 --- a/internal/pipe/brew/template.go +++ b/internal/pipe/brew/template.go @@ -11,6 +11,7 @@ type templateData struct { Plist string DownloadStrategy string Install []string + PostInstall string Dependencies []config.HomebrewDependency Conflicts []string Tests []string @@ -95,6 +96,13 @@ class {{ .Name }} < Formula {{- end }} end + {{- with .PostInstall }} + + def post_install + {{ . }} + end + {{- end -}} + {{- with .Caveats }} def caveats; <<~EOS diff --git a/internal/pipe/brew/testdata/test.rb.golden b/internal/pipe/brew/testdata/test.rb.golden index a51aaa44c..885176a38 100644 --- a/internal/pipe/brew/testdata/test.rb.golden +++ b/internal/pipe/brew/testdata/test.rb.golden @@ -38,6 +38,10 @@ class Test < Formula another install script end + def post_install + system "touch", "/tmp/foo" + end + def caveats; <<~EOS Here are some caveats EOS diff --git a/pkg/config/config.go b/pkg/config/config.go index fa8fb7027..c3878fe80 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -95,6 +95,7 @@ type Homebrew struct { Caveats string `yaml:",omitempty"` Plist string `yaml:",omitempty"` Install string `yaml:",omitempty"` + PostInstall string `yaml:"post_install,omitempty"` Dependencies []HomebrewDependency `yaml:",omitempty"` Test string `yaml:",omitempty"` Conflicts []string `yaml:",omitempty"`