From 6d000e5cb1b1feaebfb84ecc44aebadbadeb7188 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Wed, 17 Aug 2022 22:58:41 -0300 Subject: [PATCH] feat: allow to specify version of brew deps (#3319) * feat: add version for homebrew dependencies * resolve conflicts * resolve conflicts * feat: allow to specify version of brew deps Signed-off-by: Carlos A Becker * docs: brew Signed-off-by: Carlos A Becker Signed-off-by: Carlos A Becker Co-authored-by: Purushotham --- internal/pipe/brew/brew_test.go | 24 +++++++++++-------- internal/pipe/brew/template.go | 2 +- .../TestFullPipe/custom_block.rb.golden | 3 ++- .../custom_download_strategy.rb.golden | 3 ++- .../TestFullPipe/custom_require.rb.golden | 3 ++- .../testdata/TestFullPipe/default.rb.golden | 3 ++- .../TestFullPipe/default_gitlab.rb.golden | 3 ++- .../valid_tap_templates.rb.golden | 3 ++- pkg/config/config.go | 5 ++-- www/docs/customization/homebrew.md | 7 ++++++ 10 files changed, 37 insertions(+), 19 deletions(-) diff --git a/internal/pipe/brew/brew_test.go b/internal/pipe/brew/brew_test.go index 1056ad14a12..38ea0064a3e 100644 --- a/internal/pipe/brew/brew_test.go +++ b/internal/pipe/brew/brew_test.go @@ -268,16 +268,20 @@ func TestFullPipe(t *testing.T) { IDs: []string{ "foo", }, - Description: "Run pipe test formula and FOO={{ .Env.FOO }}", - Caveats: "don't do this {{ .ProjectName }}", - Test: "system \"true\"\nsystem \"#{bin}/foo\", \"-h\"", - Plist: `whatever`, - Dependencies: []config.HomebrewDependency{{Name: "zsh", Type: "optional"}, {Name: "bash"}}, - Conflicts: []string{"gtk+", "qt"}, - Service: "run foo/bar\nkeep_alive true", - PostInstall: "system \"echo\"\ntouch \"/tmp/hi\"", - Install: `bin.install "{{ .ProjectName }}"`, - Goamd64: "v1", + Description: "Run pipe test formula and FOO={{ .Env.FOO }}", + Caveats: "don't do this {{ .ProjectName }}", + Test: "system \"true\"\nsystem \"#{bin}/foo\", \"-h\"", + Plist: `whatever`, + Dependencies: []config.HomebrewDependency{ + {Name: "zsh", Type: "optional"}, + {Name: "bash", Version: "3.2.57"}, + {Name: "fish", Type: "optional", Version: "v1.2.3"}, + }, + Conflicts: []string{"gtk+", "qt"}, + Service: "run foo/bar\nkeep_alive true", + PostInstall: "system \"echo\"\ntouch \"/tmp/hi\"", + Install: `bin.install "{{ .ProjectName }}"`, + Goamd64: "v1", }, }, }, diff --git a/internal/pipe/brew/template.go b/internal/pipe/brew/template.go index d78bba6a062..799ce4b22c9 100644 --- a/internal/pipe/brew/template.go +++ b/internal/pipe/brew/template.go @@ -48,7 +48,7 @@ class {{ .Name }} < Formula {{- with .Dependencies }} {{ range $index, $element := . }} depends_on "{{ .Name }}" - {{- if .Type }} => :{{ .Type }}{{- end }} + {{- if .Type }} => :{{ .Type }}{{- else if .Version }} => "{{ .Version }}"{{- 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 0ead5913588..5bef8efc042 100644 --- a/internal/pipe/brew/testdata/TestFullPipe/custom_block.rb.golden +++ b/internal/pipe/brew/testdata/TestFullPipe/custom_block.rb.golden @@ -8,7 +8,8 @@ class CustomBlock < Formula version "1.0.1" depends_on "zsh" => :optional - depends_on "bash" + depends_on "bash" => "3.2.57" + depends_on "fish" => :optional depends_on :macos 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 b70ac164fd4..90525b1f195 100644 --- a/internal/pipe/brew/testdata/TestFullPipe/custom_download_strategy.rb.golden +++ b/internal/pipe/brew/testdata/TestFullPipe/custom_download_strategy.rb.golden @@ -8,7 +8,8 @@ class CustomDownloadStrategy < Formula version "1.0.1" depends_on "zsh" => :optional - depends_on "bash" + depends_on "bash" => "3.2.57" + depends_on "fish" => :optional depends_on :macos 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 8268f1cb7f1..6dee341f2aa 100644 --- a/internal/pipe/brew/testdata/TestFullPipe/custom_require.rb.golden +++ b/internal/pipe/brew/testdata/TestFullPipe/custom_require.rb.golden @@ -9,7 +9,8 @@ class CustomRequire < Formula version "1.0.1" depends_on "zsh" => :optional - depends_on "bash" + depends_on "bash" => "3.2.57" + depends_on "fish" => :optional depends_on :macos on_macos do diff --git a/internal/pipe/brew/testdata/TestFullPipe/default.rb.golden b/internal/pipe/brew/testdata/TestFullPipe/default.rb.golden index 98000a4eee9..d8d4b479ba6 100644 --- a/internal/pipe/brew/testdata/TestFullPipe/default.rb.golden +++ b/internal/pipe/brew/testdata/TestFullPipe/default.rb.golden @@ -8,7 +8,8 @@ class Default < Formula version "1.0.1" depends_on "zsh" => :optional - depends_on "bash" + depends_on "bash" => "3.2.57" + depends_on "fish" => :optional depends_on :macos 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 f3b8a28e4ea..23dc20da5d4 100644 --- a/internal/pipe/brew/testdata/TestFullPipe/default_gitlab.rb.golden +++ b/internal/pipe/brew/testdata/TestFullPipe/default_gitlab.rb.golden @@ -8,7 +8,8 @@ class DefaultGitlab < Formula version "1.0.1" depends_on "zsh" => :optional - depends_on "bash" + depends_on "bash" => "3.2.57" + depends_on "fish" => :optional depends_on :macos on_macos do 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 787b5440aaf..28a01583e89 100644 --- a/internal/pipe/brew/testdata/TestFullPipe/valid_tap_templates.rb.golden +++ b/internal/pipe/brew/testdata/TestFullPipe/valid_tap_templates.rb.golden @@ -8,7 +8,8 @@ class ValidTapTemplates < Formula version "1.0.1" depends_on "zsh" => :optional - depends_on "bash" + depends_on "bash" => "3.2.57" + depends_on "fish" => :optional depends_on :macos on_macos do diff --git a/pkg/config/config.go b/pkg/config/config.go index 69aa20ba911..22242a7b9ae 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -82,8 +82,9 @@ type RepoRef struct { // HomebrewDependency represents Homebrew dependency. type HomebrewDependency struct { - Name string `yaml:"name,omitempty" json:"name,omitempty"` - Type string `yaml:"type,omitempty" json:"type,omitempty"` + Name string `yaml:"name,omitempty" json:"name,omitempty"` + Type string `yaml:"type,omitempty" json:"type,omitempty"` + Version string `yaml:"version,omitempty" json:"version,omitempty"` } // 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 756a7c55a4b..e19e7a63f7c 100644 --- a/www/docs/customization/homebrew.md +++ b/www/docs/customization/homebrew.md @@ -113,6 +113,13 @@ brews: - name: git - name: zsh type: optional + - name: fish + version: v1.2.3 + # if providing both version and type, only the type will be taken into account. + - name: elvish + type: optional + version: v1.2.3 + # Packages that conflict with your package. conflicts: