Repository: goreleaser/goreleaser
Pull request #2261 (2021-05-27 02:21:23)

fix: improve brew formula
closes https://github.com/goreleaser/goreleaser/issues/2159

would be amazing if someone can help testing this 🙏

vercel[bot]: This pull request is being automatically deployed with Vercel ([learn more](https://vercel.link/github-learn-more)).  
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: [https://vercel.com/goreleaser/goreleaser/68s9ZQrp6FZvgSC8Qg2i8huQfJ1Q](https://vercel.com/goreleaser/goreleaser/68s9ZQrp6FZvgSC8Qg2i8huQfJ1Q)  
✅ Preview: *In Progress*


codecov[bot]: # [Codecov](https://codecov.io/gh/goreleaser/goreleaser/pull/2261?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser) Report
> Merging [#2261](https://codecov.io/gh/goreleaser/goreleaser/pull/2261?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser) (14e183d) into [master](https://codecov.io/gh/goreleaser/goreleaser/commit/f2d0c61d7c5a79717c429833ea6aca9d4b0059f6?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser) (f2d0c61) will **increase** coverage by `0.08%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/goreleaser/goreleaser/pull/2261/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/2261?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser)

```diff
@@            Coverage Diff             @@
##           master    #2261      +/-   ##
==========================================
+ Coverage   82.64%   82.73%   +0.08%     
==========================================
  Files          78       78              
  Lines        4230     4252      +22     
==========================================
+ Hits         3496     3518      +22     
  Misses        596      596              
  Partials      138      138              
```


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

------

[Continue to review full report at Codecov](https://codecov.io/gh/goreleaser/goreleaser/pull/2261?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/2261?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser). Last update [f2d0c61...14e183d](https://codecov.io/gh/goreleaser/goreleaser/pull/2261?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/internal/pipe/brew/brew.go b/internal/pipe/brew/brew.go
index aa844360..644b55ba 100644
--- a/internal/pipe/brew/brew.go
+++ b/internal/pipe/brew/brew.go
@@ -198,8 +198,39 @@ func buildFormula(ctx *context.Context, brew config.Homebrew, client client.Clie
 	return doBuildFormula(ctx, data)
 }
 
+func fixDataDownloads(data templateData) templateData {
+	if data.MacOSAmd64.DownloadURL != "" {
+		data.HasMacOSDownloads = true
+		data.MacOSArches = append(data.MacOSArches, ":x86_64")
+	}
+	if data.MacOSArm64.DownloadURL != "" {
+		data.HasMacOSDownloads = true
+		data.MacOSArches = append(data.MacOSArches, ":aarch64")
+	}
+	if data.LinuxAmd64.DownloadURL != "" {
+		data.HasLinuxDownloads = true
+		data.LinuxArches = append(data.LinuxArches, ":x86_64")
+	}
+	if data.LinuxArm64.DownloadURL != "" {
+		data.HasLinuxDownloads = true
+		data.LinuxArches = append(data.LinuxArches, ":aarch64")
+	}
+	if data.LinuxArm.DownloadURL != "" {
+		data.HasLinuxDownloads = true
+		data.LinuxArches = append(data.LinuxArches, ":arm")
+	}
+	return data
+}
+
 func doBuildFormula(ctx *context.Context, data templateData) (string, error) {
-	t, err := template.New(data.Name).Parse(formulaTemplate)
+	data = fixDataDownloads(data)
+
+	t, err := template.
+		New(data.Name).
+		Funcs(template.FuncMap{
+			"join": strings.Join,
+		}).
+		Parse(formulaTemplate)
 	if err != nil {
 		return "", err
 	}
diff --git a/internal/pipe/brew/template.go b/internal/pipe/brew/template.go
index fa96df49..cba2ead6 100644
--- a/internal/pipe/brew/template.go
+++ b/internal/pipe/brew/template.go
@@ -3,26 +3,30 @@ package brew
 import "github.com/goreleaser/goreleaser/pkg/config"
 
 type templateData struct {
-	Name             string
-	Desc             string
-	Homepage         string
-	Version          string
-	License          string
-	Caveats          []string
-	Plist            string
-	DownloadStrategy string
-	Install          []string
-	PostInstall      string
-	Dependencies     []config.HomebrewDependency
-	Conflicts        []string
-	Tests            []string
-	CustomRequire    string
-	CustomBlock      []string
-	MacOSAmd64       downloadable
-	MacOSArm64       downloadable
-	LinuxAmd64       downloadable
-	LinuxArm         downloadable
-	LinuxArm64       downloadable
+	Name              string
+	Desc              string
+	Homepage          string
+	Version           string
+	License           string
+	Caveats           []string
+	Plist             string
+	DownloadStrategy  string
+	Install           []string
+	PostInstall       string
+	Dependencies      []config.HomebrewDependency
+	Conflicts         []string
+	Tests             []string
+	CustomRequire     string
+	CustomBlock       []string
+	MacOSAmd64        downloadable
+	MacOSArm64        downloadable
+	LinuxAmd64        downloadable
+	LinuxArm          downloadable
+	LinuxArm64        downloadable
+	HasMacOSDownloads bool
+	HasLinuxDownloads bool
+	MacOSArches       []string
+	LinuxArches       []string
 }
 
 type downloadable struct {
@@ -45,46 +49,62 @@ class {{ .Name }} < Formula
   license "{{ .License }}"
   {{ end -}}
   bottle :unneeded
-  {{- if and (not .MacOSAmd64.DownloadURL) (not .MacOSArm64.DownloadURL) (or .LinuxAmd64.DownloadURL .LinuxArm.DownloadURL .LinuxArm64.DownloadURL) }}
+  {{- if and (not .HasLinuxDownloads) .HasMacOSDownloads }}
+  depends_on :macos
+  {{- end }}
+  {{- if and (not .HasMacOSDownloads) .HasLinuxDownloads }}
   depends_on :linux
   {{- end }}
   {{- printf "\n" }}
-  {{- if .MacOSAmd64.DownloadURL }}
-  if OS.mac? && Hardware::CPU.intel?
-    url "{{ .MacOSAmd64.DownloadURL }}"
-    {{- if .DownloadStrategy }}, :using => {{ .DownloadStrategy }}{{- end }}
-    sha256 "{{ .MacOSAmd64.SHA256 }}"
-  end
-  {{- end }}
-  {{- if .MacOSArm64.DownloadURL }}
-  if OS.mac? && Hardware::CPU.arm?
-    url "{{ .MacOSArm64.DownloadURL }}"
-    {{- if .DownloadStrategy }}, :using => {{ .DownloadStrategy }}{{- end }}
-    sha256 "{{ .MacOSArm64.SHA256 }}"
-  end
-  {{- end }}
 
-  {{- if .LinuxAmd64.DownloadURL }}
-  if OS.linux? && Hardware::CPU.intel?
-    url "{{ .LinuxAmd64.DownloadURL }}"
-    {{- if .DownloadStrategy }}, :using => {{ .DownloadStrategy }}{{- end }}
-    sha256 "{{ .LinuxAmd64.SHA256 }}"
-  end
-  {{- end }}
+  {{- if .HasMacOSDownloads }}
+  on_macos do
+    {{- if .MacOSAmd64.DownloadURL }}
+    if Hardware::CPU.intel?
+      url "{{ .MacOSAmd64.DownloadURL }}"
+      {{- if .DownloadStrategy }}, :using => {{ .DownloadStrategy }}{{- end }}
+      sha256 "{{ .MacOSAmd64.SHA256 }}"
+    end
+    {{- end }}
+    {{- if .MacOSArm64.DownloadURL }}
+    if Hardware::CPU.arm?
+      url "{{ .MacOSArm64.DownloadURL }}"
+      {{- if .DownloadStrategy }}, :using => {{ .DownloadStrategy }}{{- end }}
+      sha256 "{{ .MacOSArm64.SHA256 }}"
+    end
+    {{- end }}
 
-  {{- if .LinuxArm.DownloadURL }}
-  if OS.linux? && Hardware::CPU.arm? && !Hardware::CPU.is_64_bit?
-    url "{{ .LinuxArm.DownloadURL }}"
-    {{- if .DownloadStrategy }}, :using => {{ .DownloadStrategy }}{{- end }}
-    sha256 "{{ .LinuxArm.SHA256 }}"
+    depends_on arch: [{{ join .MacOSArches ", " }}]
   end
   {{- end }}
 
-  {{- if .LinuxArm64.DownloadURL }}
-  if OS.linux? && Hardware::CPU.arm? && Hardware::CPU.is_64_bit?
-    url "{{ .LinuxArm64.DownloadURL }}"
-    {{- if .DownloadStrategy }}, :using => {{ .DownloadStrategy }}{{- end }}
-    sha256 "{{ .LinuxArm64.SHA256 }}"
+  {{- if and .HasMacOSDownloads .HasLinuxDownloads }}{{ printf "\n" }}{{ end }}
+
+  {{- if .HasLinuxDownloads }}
+  on_linux do
+    {{- if .LinuxAmd64.DownloadURL }}
+    if Hardware::CPU.intel?
+      url "{{ .LinuxAmd64.DownloadURL }}"
+      {{- if .DownloadStrategy }}, :using => {{ .DownloadStrategy }}{{- end }}
+      sha256 "{{ .LinuxAmd64.SHA256 }}"
+    end
+    {{- end }}
+    {{- if .LinuxArm.DownloadURL }}
+    if Hardware::CPU.arm? && !Hardware::CPU.is_64_bit?
+      url "{{ .LinuxArm.DownloadURL }}"
+      {{- if .DownloadStrategy }}, :using => {{ .DownloadStrategy }}{{- end }}
+      sha256 "{{ .LinuxArm.SHA256 }}"
+    end
+    {{- end }}
+    {{- if .LinuxArm64.DownloadURL }}
+    if Hardware::CPU.arm? && Hardware::CPU.is_64_bit?
+      url "{{ .LinuxArm64.DownloadURL }}"
+      {{- if .DownloadStrategy }}, :using => {{ .DownloadStrategy }}{{- end }}
+      sha256 "{{ .LinuxArm64.SHA256 }}"
+    end
+    {{- end }}
+
+    depends_on arch: [{{ join .LinuxArches ", " }}]
   end
   {{- end }}
 


Test patch:
diff --git a/internal/pipe/brew/brew_test.go b/internal/pipe/brew/brew_test.go
index d38cdc71..f0959abf 100644
--- a/internal/pipe/brew/brew_test.go
+++ b/internal/pipe/brew/brew_test.go
@@ -130,7 +130,6 @@ func TestFormulaeSimple(t *testing.T) {
 	require.NoError(t, err)
 	assertDefaultTemplateData(t, formulae)
 	require.NotContains(t, formulae, "def caveats")
-	require.NotContains(t, formulae, "depends_on")
 	require.NotContains(t, formulae, "def plist;")
 }
 
diff --git a/internal/pipe/brew/testdata/custom_block.rb.golden b/internal/pipe/brew/testdata/custom_block.rb.golden
index 25ac5f6e..ab90b212 100644
--- a/internal/pipe/brew/testdata/custom_block.rb.golden
+++ b/internal/pipe/brew/testdata/custom_block.rb.golden
@@ -7,10 +7,15 @@ class CustomBlock < Formula
   homepage "https://github.com/goreleaser"
   version "1.0.1"
   bottle :unneeded
+  depends_on :macos
 
-  if OS.mac? && Hardware::CPU.intel?
-    url "https://dummyhost/download/v1.0.1/bin.tar.gz"
-    sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
+  on_macos do
+    if Hardware::CPU.intel?
+      url "https://dummyhost/download/v1.0.1/bin.tar.gz"
+      sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
+    end
+
+    depends_on arch: [:x86_64]
   end
 
   head "https://github.com/caarlos0/test.git"
diff --git a/internal/pipe/brew/testdata/custom_download_strategy.rb.golden b/internal/pipe/brew/testdata/custom_download_strategy.rb.golden
index 1491e927..6b253c86 100644
--- a/internal/pipe/brew/testdata/custom_download_strategy.rb.golden
+++ b/internal/pipe/brew/testdata/custom_download_strategy.rb.golden
@@ -7,10 +7,15 @@ class CustomDownloadStrategy < Formula
   homepage "https://github.com/goreleaser"
   version "1.0.1"
   bottle :unneeded
+  depends_on :macos
 
-  if OS.mac? && Hardware::CPU.intel?
-    url "https://dummyhost/download/v1.0.1/bin.tar.gz", :using => GitHubPrivateRepositoryReleaseDownloadStrategy
-    sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
+  on_macos do
+    if Hardware::CPU.intel?
+      url "https://dummyhost/download/v1.0.1/bin.tar.gz", :using => GitHubPrivateRepositoryReleaseDownloadStrategy
+      sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
+    end
+
+    depends_on arch: [:x86_64]
   end
 
   depends_on "zsh" => :optional
diff --git a/internal/pipe/brew/testdata/custom_require.rb.golden b/internal/pipe/brew/testdata/custom_require.rb.golden
index 3baaef0e..bb45ecbd 100644
--- a/internal/pipe/brew/testdata/custom_require.rb.golden
+++ b/internal/pipe/brew/testdata/custom_require.rb.golden
@@ -8,10 +8,15 @@ class CustomRequire < Formula
   homepage "https://github.com/goreleaser"
   version "1.0.1"
   bottle :unneeded
+  depends_on :macos
 
-  if OS.mac? && Hardware::CPU.intel?
-    url "https://dummyhost/download/v1.0.1/bin.tar.gz", :using => CustomDownloadStrategy
-    sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
+  on_macos do
+    if Hardware::CPU.intel?
+      url "https://dummyhost/download/v1.0.1/bin.tar.gz", :using => CustomDownloadStrategy
+      sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
+    end
+
+    depends_on arch: [:x86_64]
   end
 
   depends_on "zsh" => :optional
diff --git a/internal/pipe/brew/testdata/default.rb.golden b/internal/pipe/brew/testdata/default.rb.golden
index 91c4f54a..33b95713 100644
--- a/internal/pipe/brew/testdata/default.rb.golden
+++ b/internal/pipe/brew/testdata/default.rb.golden
@@ -7,10 +7,15 @@ class Default < Formula
   homepage "https://github.com/goreleaser"
   version "1.0.1"
   bottle :unneeded
+  depends_on :macos
 
-  if OS.mac? && Hardware::CPU.intel?
-    url "https://dummyhost/download/v1.0.1/bin.tar.gz"
-    sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
+  on_macos do
+    if Hardware::CPU.intel?
+      url "https://dummyhost/download/v1.0.1/bin.tar.gz"
+      sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
+    end
+
+    depends_on arch: [:x86_64]
   end
 
   depends_on "zsh" => :optional
diff --git a/internal/pipe/brew/testdata/default_gitlab.rb.golden b/internal/pipe/brew/testdata/default_gitlab.rb.golden
index b99b5421..43f77f4f 100644
--- a/internal/pipe/brew/testdata/default_gitlab.rb.golden
+++ b/internal/pipe/brew/testdata/default_gitlab.rb.golden
@@ -7,10 +7,15 @@ class DefaultGitlab < Formula
   homepage "https://gitlab.com/goreleaser"
   version "1.0.1"
   bottle :unneeded
+  depends_on :macos
 
-  if OS.mac? && Hardware::CPU.intel?
-    url "https://dummyhost/download/v1.0.1/bin.tar.gz"
-    sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
+  on_macos do
+    if Hardware::CPU.intel?
+      url "https://dummyhost/download/v1.0.1/bin.tar.gz"
+      sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
+    end
+
+    depends_on arch: [:x86_64]
   end
 
   depends_on "zsh" => :optional
diff --git a/internal/pipe/brew/testdata/foo_is_bar.rb.golden b/internal/pipe/brew/testdata/foo_is_bar.rb.golden
index e4920feb..3bd69854 100644
--- a/internal/pipe/brew/testdata/foo_is_bar.rb.golden
+++ b/internal/pipe/brew/testdata/foo_is_bar.rb.golden
@@ -7,10 +7,15 @@ class FooIsBar < Formula
   homepage ""
   version "1.0.1"
   bottle :unneeded
+  depends_on :macos
 
-  if OS.mac? && Hardware::CPU.intel?
-    url "https://dummyhost/download/v1.0.1/bin.tar.gz"
-    sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
+  on_macos do
+    if Hardware::CPU.intel?
+      url "https://dummyhost/download/v1.0.1/bin.tar.gz"
+      sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
+    end
+
+    depends_on arch: [:x86_64]
   end
 
   def install
diff --git a/internal/pipe/brew/testdata/multiple_armv5.rb.golden b/internal/pipe/brew/testdata/multiple_armv5.rb.golden
index 7480086c..5887c79f 100644
--- a/internal/pipe/brew/testdata/multiple_armv5.rb.golden
+++ b/internal/pipe/brew/testdata/multiple_armv5.rb.golden
@@ -8,17 +8,26 @@ class MultipleArmv5 < Formula
   version "1.0.1"
   bottle :unneeded
 
-  if OS.mac? && Hardware::CPU.intel?
-    url "https://dummyhost/download/v1.0.1/bin.tar.gz"
-    sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
-  end
-  if OS.linux? && Hardware::CPU.arm? && !Hardware::CPU.is_64_bit?
-    url "https://dummyhost/download/v1.0.1/armv5.tar.gz"
-    sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
+  on_macos do
+    if Hardware::CPU.intel?
+      url "https://dummyhost/download/v1.0.1/bin.tar.gz"
+      sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
+    end
+
+    depends_on arch: [:x86_64]
   end
-  if OS.linux? && Hardware::CPU.arm? && Hardware::CPU.is_64_bit?
-    url "https://dummyhost/download/v1.0.1/arm64.tar.gz"
-    sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
+
+  on_linux do
+    if Hardware::CPU.arm? && !Hardware::CPU.is_64_bit?
+      url "https://dummyhost/download/v1.0.1/armv5.tar.gz"
+      sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
+    end
+    if Hardware::CPU.arm? && Hardware::CPU.is_64_bit?
+      url "https://dummyhost/download/v1.0.1/arm64.tar.gz"
+      sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
+    end
+
+    depends_on arch: [:aarch64, :arm]
   end
 
   depends_on "zsh"
diff --git a/internal/pipe/brew/testdata/multiple_armv6.rb.golden b/internal/pipe/brew/testdata/multiple_armv6.rb.golden
index 83877a67..62f3be05 100644
--- a/internal/pipe/brew/testdata/multiple_armv6.rb.golden
+++ b/internal/pipe/brew/testdata/multiple_armv6.rb.golden
@@ -8,17 +8,26 @@ class MultipleArmv6 < Formula
   version "1.0.1"
   bottle :unneeded
 
-  if OS.mac? && Hardware::CPU.intel?
-    url "https://dummyhost/download/v1.0.1/bin.tar.gz"
-    sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
-  end
-  if OS.linux? && Hardware::CPU.arm? && !Hardware::CPU.is_64_bit?
-    url "https://dummyhost/download/v1.0.1/armv6.tar.gz"
-    sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
+  on_macos do
+    if Hardware::CPU.intel?
+      url "https://dummyhost/download/v1.0.1/bin.tar.gz"
+      sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
+    end
+
+    depends_on arch: [:x86_64]
   end
-  if OS.linux? && Hardware::CPU.arm? && Hardware::CPU.is_64_bit?
-    url "https://dummyhost/download/v1.0.1/arm64.tar.gz"
-    sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
+
+  on_linux do
+    if Hardware::CPU.arm? && !Hardware::CPU.is_64_bit?
+      url "https://dummyhost/download/v1.0.1/armv6.tar.gz"
+      sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
+    end
+    if Hardware::CPU.arm? && Hardware::CPU.is_64_bit?
+      url "https://dummyhost/download/v1.0.1/arm64.tar.gz"
+      sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
+    end
+
+    depends_on arch: [:aarch64, :arm]
   end
 
   depends_on "zsh"
diff --git a/internal/pipe/brew/testdata/multiple_armv7.rb.golden b/internal/pipe/brew/testdata/multiple_armv7.rb.golden
index 074a1526..86761d01 100644
--- a/internal/pipe/brew/testdata/multiple_armv7.rb.golden
+++ b/internal/pipe/brew/testdata/multiple_armv7.rb.golden
@@ -8,17 +8,26 @@ class MultipleArmv7 < Formula
   version "1.0.1"
   bottle :unneeded
 
-  if OS.mac? && Hardware::CPU.intel?
-    url "https://dummyhost/download/v1.0.1/bin.tar.gz"
-    sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
-  end
-  if OS.linux? && Hardware::CPU.arm? && !Hardware::CPU.is_64_bit?
-    url "https://dummyhost/download/v1.0.1/armv7.tar.gz"
-    sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
+  on_macos do
+    if Hardware::CPU.intel?
+      url "https://dummyhost/download/v1.0.1/bin.tar.gz"
+      sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
+    end
+
+    depends_on arch: [:x86_64]
   end
-  if OS.linux? && Hardware::CPU.arm? && Hardware::CPU.is_64_bit?
-    url "https://dummyhost/download/v1.0.1/arm64.tar.gz"
-    sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
+
+  on_linux do
+    if Hardware::CPU.arm? && !Hardware::CPU.is_64_bit?
+      url "https://dummyhost/download/v1.0.1/armv7.tar.gz"
+      sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
+    end
+    if Hardware::CPU.arm? && Hardware::CPU.is_64_bit?
+      url "https://dummyhost/download/v1.0.1/arm64.tar.gz"
+      sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
+    end
+
+    depends_on arch: [:aarch64, :arm]
   end
 
   depends_on "zsh"
diff --git a/internal/pipe/brew/testdata/test.rb.golden b/internal/pipe/brew/testdata/test.rb.golden
index 87d67479..86d50dd1 100644
--- a/internal/pipe/brew/testdata/test.rb.golden
+++ b/internal/pipe/brew/testdata/test.rb.golden
@@ -9,25 +9,34 @@ class Test < Formula
   license "MIT"
   bottle :unneeded
 
-  if OS.mac? && Hardware::CPU.intel?
-    url "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Darwin_x86_64.tar.gz"
-    sha256 "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c68"
-  end
-  if OS.mac? && Hardware::CPU.arm?
-    url "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Darwin_arm64.tar.gz"
-    sha256 "1633f61598ab0791e213135923624eb342196b349490sadasdsadsadasdasdsd"
-  end
-  if OS.linux? && Hardware::CPU.intel?
-    url "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Linux_x86_64.tar.gz"
-    sha256 "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67"
-  end
-  if OS.linux? && Hardware::CPU.arm? && !Hardware::CPU.is_64_bit?
-    url "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Arm6.tar.gz"
-    sha256 "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67"
+  on_macos do
+    if Hardware::CPU.intel?
+      url "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Darwin_x86_64.tar.gz"
+      sha256 "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c68"
+    end
+    if Hardware::CPU.arm?
+      url "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Darwin_arm64.tar.gz"
+      sha256 "1633f61598ab0791e213135923624eb342196b349490sadasdsadsadasdasdsd"
+    end
+
+    depends_on arch: [:x86_64, :aarch64]
   end
-  if OS.linux? && Hardware::CPU.arm? && Hardware::CPU.is_64_bit?
-    url "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Arm64.tar.gz"
-    sha256 "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67"
+
+  on_linux do
+    if Hardware::CPU.intel?
+      url "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Linux_x86_64.tar.gz"
+      sha256 "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67"
+    end
+    if Hardware::CPU.arm? && !Hardware::CPU.is_64_bit?
+      url "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Arm6.tar.gz"
+      sha256 "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67"
+    end
+    if Hardware::CPU.arm? && Hardware::CPU.is_64_bit?
+      url "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Arm64.tar.gz"
+      sha256 "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67"
+    end
+
+    depends_on arch: [:x86_64, :aarch64, :arm]
   end
 
   devel do
diff --git a/internal/pipe/brew/testdata/test_linux_only.rb.golden b/internal/pipe/brew/testdata/test_linux_only.rb.golden
index f18815b7..0ac23ddb 100644
--- a/internal/pipe/brew/testdata/test_linux_only.rb.golden
+++ b/internal/pipe/brew/testdata/test_linux_only.rb.golden
@@ -9,17 +9,21 @@ class Test < Formula
   bottle :unneeded
   depends_on :linux
 
-  if OS.linux? && Hardware::CPU.intel?
-    url "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Linux_x86_64.tar.gz"
-    sha256 "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67"
-  end
-  if OS.linux? && Hardware::CPU.arm? && !Hardware::CPU.is_64_bit?
-    url "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Arm6.tar.gz"
-    sha256 "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67"
-  end
-  if OS.linux? && Hardware::CPU.arm? && Hardware::CPU.is_64_bit?
-    url "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Arm64.tar.gz"
-    sha256 "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67"
+  on_linux do
+    if Hardware::CPU.intel?
+      url "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Linux_x86_64.tar.gz"
+      sha256 "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67"
+    end
+    if Hardware::CPU.arm? && !Hardware::CPU.is_64_bit?
+      url "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Arm6.tar.gz"
+      sha256 "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67"
+    end
+    if Hardware::CPU.arm? && Hardware::CPU.is_64_bit?
+      url "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Arm64.tar.gz"
+      sha256 "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67"
+    end
+
+    depends_on arch: [:x86_64, :aarch64, :arm]
   end
 
   def install