Repository: goreleaser/goreleaser
Pull request #2973 (2022-03-12 02:18:39)

feat: brew service block
closes https://github.com/goreleaser/goreleaser/issues/2970

codecov[bot]: # [Codecov](https://codecov.io/gh/goreleaser/goreleaser/pull/2973?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser) Report
> Merging [#2973](https://codecov.io/gh/goreleaser/goreleaser/pull/2973?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser) (e84f728) into [main](https://codecov.io/gh/goreleaser/goreleaser/commit/42258cf4733a9f42b17ad1b47fb7e6e2a10369c0?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser) (42258cf) will **increase** coverage by `0.00%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/goreleaser/goreleaser/pull/2973/graphs/tree.svg?width=650&height=150&src=pr&token=3bJvv6b7hN&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser)](https://codecov.io/gh/goreleaser/goreleaser/pull/2973?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser)

```diff
@@           Coverage Diff           @@
##             main    #2973   +/-   ##
=======================================
  Coverage   84.48%   84.48%           
=======================================
  Files         111      111           
  Lines        9009     9010    +1     
=======================================
+ Hits         7611     7612    +1     
  Misses       1124     1124           
  Partials      274      274           
```


| [Impacted Files](https://codecov.io/gh/goreleaser/goreleaser/pull/2973?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser) | Coverage Δ | |
|---|---|---|
| [pkg/config/config.go](https://codecov.io/gh/goreleaser/goreleaser/pull/2973/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser#diff-cGtnL2NvbmZpZy9jb25maWcuZ28=) | `87.15% <ø> (ø)` | |
| [internal/pipe/brew/brew.go](https://codecov.io/gh/goreleaser/goreleaser/pull/2973/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser#diff-aW50ZXJuYWwvcGlwZS9icmV3L2JyZXcuZ28=) | `84.05% <100.00%> (+0.05%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/goreleaser/goreleaser/pull/2973?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/goreleaser/goreleaser/pull/2973?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser). Last update [42258cf...e84f728](https://codecov.io/gh/goreleaser/goreleaser/pull/2973?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser).


Patch:
diff --git a/go.mod b/go.mod
index 1f883123..ce3c27f9 100644
--- a/go.mod
+++ b/go.mod
@@ -30,9 +30,9 @@ require (
 	github.com/muesli/mango-coral v1.0.1
 	github.com/muesli/roff v0.1.0
 	github.com/slack-go/slack v0.10.2
-	github.com/stretchr/testify v1.7.0
+	github.com/stretchr/testify v1.7.1
 	github.com/ulikunitz/xz v0.5.10
-	github.com/xanzy/go-gitlab v0.56.0
+	github.com/xanzy/go-gitlab v0.59.0
 	gocloud.dev v0.24.0
 	golang.org/x/crypto v0.0.0-20220131195533-30dcbda58838
 	golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8
diff --git a/go.sum b/go.sum
index 7d890a9e..dd699b3e 100644
--- a/go.sum
+++ b/go.sum
@@ -718,8 +718,9 @@ github.com/stretchr/testify v1.3.1-0.20190311161405-34c6fa2dc709/go.mod h1:M5WIy
 github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
 github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
 github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
-github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
 github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
+github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
+github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
 github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
 github.com/technoweenie/multipartstreamer v1.0.1 h1:XRztA5MXiR1TIRHxH2uNxXxaIkKQDeX7m2XsSOlQEnM=
 github.com/technoweenie/multipartstreamer v1.0.1/go.mod h1:jNVxdtShOxzAsukZwTSw6MDx5eUJoiEBsSvzDU9uzog=
@@ -736,8 +737,8 @@ github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLY
 github.com/ulikunitz/xz v0.5.9/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
 github.com/ulikunitz/xz v0.5.10 h1:t92gobL9l3HE202wg3rlk19F6X+JOxl9BBrCCMYEYd8=
 github.com/ulikunitz/xz v0.5.10/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
-github.com/xanzy/go-gitlab v0.56.0 h1:/QHBvk3IKVNwvXB/UOWVb5J6VCN6r2bg9/WxjUbFY/0=
-github.com/xanzy/go-gitlab v0.56.0/go.mod h1:F0QEXwmqiBUxCgJm8fE9S+1veX4XC9Z4cfaAbqwk4YM=
+github.com/xanzy/go-gitlab v0.59.0 h1:fAr6rT/YIdfmBavYgI42+Op7yAAex2Y4xOfvbjN9hxQ=
+github.com/xanzy/go-gitlab v0.59.0/go.mod h1:F0QEXwmqiBUxCgJm8fE9S+1veX4XC9Z4cfaAbqwk4YM=
 github.com/xanzy/ssh-agent v0.2.1/go.mod h1:mLlQY/MoOhWBj+gOGMQkOeiEvkx+8pJSI+0Bx9h2kr4=
 github.com/xanzy/ssh-agent v0.3.0/go.mod h1:3s9xbODqPuuhK9JV1R321M/FlMZSBvE5aY6eAcqrDh0=
 github.com/xanzy/ssh-agent v0.3.1 h1:AmzO1SSWxw73zxFZPRwaMN1MohDw8UyHnmuxyceTEGo=
diff --git a/internal/pipe/brew/brew.go b/internal/pipe/brew/brew.go
index 02260c90..4dc9a230 100644
--- a/internal/pipe/brew/brew.go
+++ b/internal/pipe/brew/brew.go
@@ -323,6 +323,7 @@ func dataFor(ctx *context.Context, cfg config.Homebrew, cl client.Client, artifa
 		Dependencies:  cfg.Dependencies,
 		Conflicts:     cfg.Conflicts,
 		Plist:         cfg.Plist,
+		Service:       split(cfg.Service),
 		PostInstall:   cfg.PostInstall,
 		Tests:         split(cfg.Test),
 		CustomRequire: cfg.CustomRequire,
diff --git a/internal/pipe/brew/template.go b/internal/pipe/brew/template.go
index 5859d836..4542fe4c 100644
--- a/internal/pipe/brew/template.go
+++ b/internal/pipe/brew/template.go
@@ -18,6 +18,7 @@ type templateData struct {
 	CustomBlock          []string
 	LinuxPackages        []releasePackage
 	MacOSPackages        []releasePackage
+	Service              []string
 	HasOnlyAmd64MacOsPkg bool
 }
 
@@ -181,6 +182,14 @@ class {{ .Name }} < Formula
   end
   {{- end -}}
 
+  {{- with .Service }}
+  service do
+    {{- range . }}
+      {{ . }}
+    {{- end }}
+  end
+  {{- end -}}
+
   {{- if .Tests }}
 
   test do
diff --git a/pkg/config/config.go b/pkg/config/config.go
index e00220e2..7103f832 100644
--- a/pkg/config/config.go
+++ b/pkg/config/config.go
@@ -169,6 +169,7 @@ type Homebrew struct {
 	CustomBlock           string               `yaml:"custom_block,omitempty"`
 	IDs                   []string             `yaml:"ids,omitempty"`
 	Goarm                 string               `yaml:"goarm,omitempty"`
+	Service               string               `yaml:"service,omitempty"`
 }
 
 // Krew contains the krew section.
diff --git a/www/docs/customization/homebrew.md b/www/docs/customization/homebrew.md
index 59e204cc..f967be84 100644
--- a/www/docs/customization/homebrew.md
+++ b/www/docs/customization/homebrew.md
@@ -120,6 +120,11 @@ brews:
       <?xml version="1.0" encoding="UTF-8"?>
       ...
 
+    # Service block.
+    service: |
+      run: foo/bar
+      ...
+
     # So you can `brew test` your formula.
     # Default is empty.
     test: |


Test patch:
diff --git a/internal/pipe/brew/brew_test.go b/internal/pipe/brew/brew_test.go
index 8a18af48..0b235b41 100644
--- a/internal/pipe/brew/brew_test.go
+++ b/internal/pipe/brew/brew_test.go
@@ -274,6 +274,7 @@ func TestFullPipe(t *testing.T) {
 							Plist:        `<xml>whatever</xml>`,
 							Dependencies: []config.HomebrewDependency{{Name: "zsh", Type: "optional"}, {Name: "bash"}},
 							Conflicts:    []string{"gtk+", "qt"},
+							Service:      "run foo/bar\nkeep_alive true",
 							Install:      `bin.install "{{ .ProjectName }}"`,
 						},
 					},
diff --git a/internal/pipe/brew/testdata/TestFullPipe/custom_block.rb.golden b/internal/pipe/brew/testdata/TestFullPipe/custom_block.rb.golden
index f5bde09d..5bf96050 100644
--- a/internal/pipe/brew/testdata/TestFullPipe/custom_block.rb.golden
+++ b/internal/pipe/brew/testdata/TestFullPipe/custom_block.rb.golden
@@ -46,6 +46,10 @@ class CustomBlock < Formula
     <xml>whatever</xml>
   EOS
   end
+  service do
+      run foo/bar
+      keep_alive true
+  end
 
   test do
     system "true"
diff --git a/internal/pipe/brew/testdata/TestFullPipe/custom_download_strategy.rb.golden b/internal/pipe/brew/testdata/TestFullPipe/custom_download_strategy.rb.golden
index 512b986f..0382bb66 100644
--- a/internal/pipe/brew/testdata/TestFullPipe/custom_download_strategy.rb.golden
+++ b/internal/pipe/brew/testdata/TestFullPipe/custom_download_strategy.rb.golden
@@ -44,6 +44,10 @@ class CustomDownloadStrategy < Formula
     <xml>whatever</xml>
   EOS
   end
+  service do
+      run foo/bar
+      keep_alive true
+  end
 
   test do
     system "true"
diff --git a/internal/pipe/brew/testdata/TestFullPipe/custom_require.rb.golden b/internal/pipe/brew/testdata/TestFullPipe/custom_require.rb.golden
index 7ad3661a..4b7af8ae 100644
--- a/internal/pipe/brew/testdata/TestFullPipe/custom_require.rb.golden
+++ b/internal/pipe/brew/testdata/TestFullPipe/custom_require.rb.golden
@@ -45,6 +45,10 @@ class CustomRequire < Formula
     <xml>whatever</xml>
   EOS
   end
+  service do
+      run foo/bar
+      keep_alive true
+  end
 
   test do
     system "true"
diff --git a/internal/pipe/brew/testdata/TestFullPipe/default.rb.golden b/internal/pipe/brew/testdata/TestFullPipe/default.rb.golden
index 97e8afda..383850d3 100644
--- a/internal/pipe/brew/testdata/TestFullPipe/default.rb.golden
+++ b/internal/pipe/brew/testdata/TestFullPipe/default.rb.golden
@@ -44,6 +44,10 @@ class Default < Formula
     <xml>whatever</xml>
   EOS
   end
+  service do
+      run foo/bar
+      keep_alive true
+  end
 
   test do
     system "true"
diff --git a/internal/pipe/brew/testdata/TestFullPipe/default_gitlab.rb.golden b/internal/pipe/brew/testdata/TestFullPipe/default_gitlab.rb.golden
index ffff82dc..cbd686fa 100644
--- a/internal/pipe/brew/testdata/TestFullPipe/default_gitlab.rb.golden
+++ b/internal/pipe/brew/testdata/TestFullPipe/default_gitlab.rb.golden
@@ -44,6 +44,10 @@ class DefaultGitlab < Formula
     <xml>whatever</xml>
   EOS
   end
+  service do
+      run foo/bar
+      keep_alive true
+  end
 
   test do
     system "true"
diff --git a/internal/pipe/brew/testdata/TestFullPipe/valid_tap_templates.rb.golden b/internal/pipe/brew/testdata/TestFullPipe/valid_tap_templates.rb.golden
index d8cf31df..6d544cf7 100644
--- a/internal/pipe/brew/testdata/TestFullPipe/valid_tap_templates.rb.golden
+++ b/internal/pipe/brew/testdata/TestFullPipe/valid_tap_templates.rb.golden
@@ -44,6 +44,10 @@ class ValidTapTemplates < Formula
     <xml>whatever</xml>
   EOS
   end
+  service do
+      run foo/bar
+      keep_alive true
+  end
 
   test do
     system "true"