From ee1483712733f4c2db4e13a113a65d6948f4fdef Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Fri, 15 Dec 2023 12:14:01 -0300 Subject: [PATCH] feat(homebrew): add os to dependency (#4481) closes #4480 --- internal/pipe/brew/brew_test.go | 2 ++ internal/pipe/brew/template.go | 1 + .../pipe/brew/testdata/TestFullPipe/custom_block.rb.golden | 2 ++ .../TestFullPipe/custom_download_strategy.rb.golden | 2 ++ .../brew/testdata/TestFullPipe/custom_require.rb.golden | 2 ++ internal/pipe/brew/testdata/TestFullPipe/default.rb.golden | 2 ++ .../brew/testdata/TestFullPipe/default_gitlab.rb.golden | 2 ++ .../pipe/brew/testdata/TestFullPipe/git_remote.rb.golden | 2 ++ internal/pipe/brew/testdata/TestFullPipe/open_pr.rb.golden | 2 ++ .../TestFullPipe/valid_repository_templates.rb.golden | 2 ++ pkg/config/config.go | 1 + www/docs/customization/homebrew.md | 5 +++++ www/docs/static/schema.json | 7 +++++++ 13 files changed, 32 insertions(+) diff --git a/internal/pipe/brew/brew_test.go b/internal/pipe/brew/brew_test.go index b19e21534e5..437274f3dd3 100644 --- a/internal/pipe/brew/brew_test.go +++ b/internal/pipe/brew/brew_test.go @@ -313,6 +313,8 @@ func TestFullPipe(t *testing.T) { {Name: "zsh", Type: "optional"}, {Name: "bash", Version: "3.2.57"}, {Name: "fish", Type: "optional", Version: "v1.2.3"}, + {Name: "powershell", Type: "optional", OS: "mac"}, + {Name: "ash", Version: "1.0.0", OS: "linux"}, }, Conflicts: []string{"gtk+", "qt"}, Service: "run foo/bar\nkeep_alive true", diff --git a/internal/pipe/brew/template.go b/internal/pipe/brew/template.go index 799ce4b22c9..0e41847524c 100644 --- a/internal/pipe/brew/template.go +++ b/internal/pipe/brew/template.go @@ -49,6 +49,7 @@ class {{ .Name }} < Formula {{ range $index, $element := . }} depends_on "{{ .Name }}" {{- if .Type }} => :{{ .Type }}{{- else if .Version }} => "{{ .Version }}"{{- end }} + {{- with .OS }} if OS.{{ . }}?{{- end }} {{- end }} {{- end -}} diff --git a/internal/pipe/brew/testdata/TestFullPipe/custom_block.rb.golden b/internal/pipe/brew/testdata/TestFullPipe/custom_block.rb.golden index 86fe1f8fec1..d942cb06a17 100644 --- a/internal/pipe/brew/testdata/TestFullPipe/custom_block.rb.golden +++ b/internal/pipe/brew/testdata/TestFullPipe/custom_block.rb.golden @@ -7,8 +7,10 @@ class CustomBlock < Formula homepage "https://github.com/goreleaser" version "1.0.1" + depends_on "ash" => "1.0.0" if OS.linux? depends_on "bash" => "3.2.57" depends_on "fish" => :optional + depends_on "powershell" => :optional if OS.mac? depends_on "zsh" => :optional on_macos do 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 330a4644720..2ae65a8ab04 100644 --- a/internal/pipe/brew/testdata/TestFullPipe/custom_download_strategy.rb.golden +++ b/internal/pipe/brew/testdata/TestFullPipe/custom_download_strategy.rb.golden @@ -7,8 +7,10 @@ class CustomDownloadStrategy < Formula homepage "https://github.com/goreleaser" version "1.0.1" + depends_on "ash" => "1.0.0" if OS.linux? depends_on "bash" => "3.2.57" depends_on "fish" => :optional + depends_on "powershell" => :optional if OS.mac? depends_on "zsh" => :optional on_macos do diff --git a/internal/pipe/brew/testdata/TestFullPipe/custom_require.rb.golden b/internal/pipe/brew/testdata/TestFullPipe/custom_require.rb.golden index a9698cdc856..129a0fbf1b3 100644 --- a/internal/pipe/brew/testdata/TestFullPipe/custom_require.rb.golden +++ b/internal/pipe/brew/testdata/TestFullPipe/custom_require.rb.golden @@ -8,8 +8,10 @@ class CustomRequire < Formula homepage "https://github.com/goreleaser" version "1.0.1" + depends_on "ash" => "1.0.0" if OS.linux? depends_on "bash" => "3.2.57" depends_on "fish" => :optional + depends_on "powershell" => :optional if OS.mac? depends_on "zsh" => :optional on_macos do diff --git a/internal/pipe/brew/testdata/TestFullPipe/default.rb.golden b/internal/pipe/brew/testdata/TestFullPipe/default.rb.golden index 43a55b0c5e7..96ddb60deec 100644 --- a/internal/pipe/brew/testdata/TestFullPipe/default.rb.golden +++ b/internal/pipe/brew/testdata/TestFullPipe/default.rb.golden @@ -7,8 +7,10 @@ class Default < Formula homepage "https://github.com/goreleaser" version "1.0.1" + depends_on "ash" => "1.0.0" if OS.linux? depends_on "bash" => "3.2.57" depends_on "fish" => :optional + depends_on "powershell" => :optional if OS.mac? depends_on "zsh" => :optional on_macos do diff --git a/internal/pipe/brew/testdata/TestFullPipe/default_gitlab.rb.golden b/internal/pipe/brew/testdata/TestFullPipe/default_gitlab.rb.golden index e4e70042cd8..6260b495a0b 100644 --- a/internal/pipe/brew/testdata/TestFullPipe/default_gitlab.rb.golden +++ b/internal/pipe/brew/testdata/TestFullPipe/default_gitlab.rb.golden @@ -7,8 +7,10 @@ class DefaultGitlab < Formula homepage "https://gitlab.com/goreleaser" version "1.0.1" + depends_on "ash" => "1.0.0" if OS.linux? depends_on "bash" => "3.2.57" depends_on "fish" => :optional + depends_on "powershell" => :optional if OS.mac? depends_on "zsh" => :optional on_macos do diff --git a/internal/pipe/brew/testdata/TestFullPipe/git_remote.rb.golden b/internal/pipe/brew/testdata/TestFullPipe/git_remote.rb.golden index 7db4e44ff7f..7b9b5600ccb 100644 --- a/internal/pipe/brew/testdata/TestFullPipe/git_remote.rb.golden +++ b/internal/pipe/brew/testdata/TestFullPipe/git_remote.rb.golden @@ -7,8 +7,10 @@ class GitRemote < Formula homepage "https://github.com/goreleaser" version "1.0.1" + depends_on "ash" => "1.0.0" if OS.linux? depends_on "bash" => "3.2.57" depends_on "fish" => :optional + depends_on "powershell" => :optional if OS.mac? depends_on "zsh" => :optional on_macos do diff --git a/internal/pipe/brew/testdata/TestFullPipe/open_pr.rb.golden b/internal/pipe/brew/testdata/TestFullPipe/open_pr.rb.golden index ac45ea74c03..e2c530a98c6 100644 --- a/internal/pipe/brew/testdata/TestFullPipe/open_pr.rb.golden +++ b/internal/pipe/brew/testdata/TestFullPipe/open_pr.rb.golden @@ -7,8 +7,10 @@ class OpenPr < Formula homepage "https://github.com/goreleaser" version "1.0.1" + depends_on "ash" => "1.0.0" if OS.linux? depends_on "bash" => "3.2.57" depends_on "fish" => :optional + depends_on "powershell" => :optional if OS.mac? depends_on "zsh" => :optional on_macos do diff --git a/internal/pipe/brew/testdata/TestFullPipe/valid_repository_templates.rb.golden b/internal/pipe/brew/testdata/TestFullPipe/valid_repository_templates.rb.golden index 7e50e705491..cdc104f2403 100644 --- a/internal/pipe/brew/testdata/TestFullPipe/valid_repository_templates.rb.golden +++ b/internal/pipe/brew/testdata/TestFullPipe/valid_repository_templates.rb.golden @@ -7,8 +7,10 @@ class ValidRepositoryTemplates < Formula homepage "" version "1.0.1" + depends_on "ash" => "1.0.0" if OS.linux? depends_on "bash" => "3.2.57" depends_on "fish" => :optional + depends_on "powershell" => :optional if OS.mac? depends_on "zsh" => :optional on_macos do diff --git a/pkg/config/config.go b/pkg/config/config.go index e0582f52b56..b1bd8fcef2f 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -156,6 +156,7 @@ type HomebrewDependency struct { Name string `yaml:"name,omitempty" json:"name,omitempty"` Type string `yaml:"type,omitempty" json:"type,omitempty"` Version string `yaml:"version,omitempty" json:"version,omitempty"` + OS string `yaml:"os,omitempty" json:"os,omitempty" jsonschema:"enum=mac,enum=linux"` } // type alias to prevent stack overflowing in the custom unmarshaler. diff --git a/www/docs/customization/homebrew.md b/www/docs/customization/homebrew.md index df8a09268ee..f2fee0dc754 100644 --- a/www/docs/customization/homebrew.md +++ b/www/docs/customization/homebrew.md @@ -115,6 +115,11 @@ brews: # Packages your package depends on. dependencies: - name: git + # Allow to specify the OS in which the dependency is required. + # Valid options are `mac` and `linux`. + # + # Since: v1.23.0 + os: mac - name: zsh type: optional - name: fish diff --git a/www/docs/static/schema.json b/www/docs/static/schema.json index d55759c3076..1e5710290b8 100644 --- a/www/docs/static/schema.json +++ b/www/docs/static/schema.json @@ -1268,6 +1268,13 @@ }, "version": { "type": "string" + }, + "os": { + "type": "string", + "enum": [ + "mac", + "linux" + ] } }, "additionalProperties": false,