mirror of
https://github.com/goreleaser/goreleaser.git
synced 2024-12-27 01:33:39 +02:00
feat(brew): extra_install
Allows to add manpages and shell completion installs without overriding the default bin.install.
This commit is contained in:
parent
025b8757b8
commit
d7921d4638
@ -186,8 +186,7 @@ brews:
|
||||
- name: git
|
||||
conflicts:
|
||||
- goreleaser-pro
|
||||
install: |-
|
||||
bin.install "goreleaser"
|
||||
extra_install: |-
|
||||
bash_completion.install "completions/goreleaser.bash" => "goreleaser"
|
||||
zsh_completion.install "completions/goreleaser.zsh" => "_goreleaser"
|
||||
fish_completion.install "completions/goreleaser.fish"
|
||||
|
@ -325,30 +325,38 @@ func doBuildFormula(ctx *context.Context, data templateData) (string, error) {
|
||||
}
|
||||
|
||||
func installs(ctx *context.Context, cfg config.Homebrew, art *artifact.Artifact) ([]string, error) {
|
||||
applied, err := tmpl.New(ctx).WithArtifact(art).Apply(cfg.Install)
|
||||
tpl := tmpl.New(ctx).WithArtifact(art)
|
||||
|
||||
extraInstall, err := tpl.Apply(cfg.ExtraInstall)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if applied != "" {
|
||||
return split(applied), nil
|
||||
|
||||
install, err := tpl.Apply(cfg.Install)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if install != "" {
|
||||
return append(split(install), split(extraInstall)...), nil
|
||||
}
|
||||
|
||||
install := map[string]bool{}
|
||||
installMap := map[string]bool{}
|
||||
switch art.Type {
|
||||
case artifact.UploadableBinary:
|
||||
name := art.Name
|
||||
bin := artifact.ExtraOr(*art, artifact.ExtraBinary, art.Name)
|
||||
install[fmt.Sprintf("bin.install %q => %q", name, bin)] = true
|
||||
installMap[fmt.Sprintf("bin.install %q => %q", name, bin)] = true
|
||||
case artifact.UploadableArchive:
|
||||
for _, bin := range artifact.ExtraOr(*art, artifact.ExtraBinaries, []string{}) {
|
||||
install[fmt.Sprintf("bin.install %q", bin)] = true
|
||||
installMap[fmt.Sprintf("bin.install %q", bin)] = true
|
||||
}
|
||||
}
|
||||
|
||||
result := keys(install)
|
||||
result := keys(installMap)
|
||||
sort.Strings(result)
|
||||
log.Warnf("guessing install to be %q", strings.Join(result, ", "))
|
||||
return result, nil
|
||||
log.WithField("install", result).Info("guessing install")
|
||||
|
||||
return append(result, split(extraInstall)...), nil
|
||||
}
|
||||
|
||||
func keys(m map[string]bool) []string {
|
||||
|
@ -588,8 +588,9 @@ func TestRunPipeForMultipleAmd64Versions(t *testing.T) {
|
||||
Owner: "test",
|
||||
Name: "test",
|
||||
},
|
||||
Homepage: "https://github.com/goreleaser",
|
||||
Install: `bin.install "foo"`,
|
||||
Homepage: "https://github.com/goreleaser",
|
||||
Install: `bin.install "foo"`,
|
||||
ExtraInstall: `man1.install "./man/foo.1.gz"`,
|
||||
},
|
||||
},
|
||||
GitHubURLs: config.GitHubURLs{
|
||||
@ -982,6 +983,7 @@ func TestRunPipeBinaryRelease(t *testing.T) {
|
||||
Owner: "foo",
|
||||
Name: "bar",
|
||||
},
|
||||
ExtraInstall: `man1.install "./man/foo.1.gz"`,
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -1022,9 +1024,10 @@ func TestRunPipePullRequest(t *testing.T) {
|
||||
ProjectName: "foo",
|
||||
Brews: []config.Homebrew{
|
||||
{
|
||||
Name: "foo",
|
||||
Homepage: "https://goreleaser.com",
|
||||
Description: "Fake desc",
|
||||
Name: "foo",
|
||||
Homepage: "https://goreleaser.com",
|
||||
Description: "Fake desc",
|
||||
ExtraInstall: `man1.install "./man/foo.1.gz"`,
|
||||
Repository: config.RepoRef{
|
||||
Owner: "foo",
|
||||
Name: "bar",
|
||||
|
@ -14,6 +14,7 @@ class Foo < Formula
|
||||
|
||||
def install
|
||||
bin.install "foo_macos" => "foo"
|
||||
man1.install "./man/foo.1.gz"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -14,6 +14,7 @@ class V1 < Formula
|
||||
|
||||
def install
|
||||
bin.install "foo"
|
||||
man1.install "./man/foo.1.gz"
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -25,6 +26,7 @@ class V1 < Formula
|
||||
|
||||
def install
|
||||
bin.install "foo"
|
||||
man1.install "./man/foo.1.gz"
|
||||
end
|
||||
end
|
||||
if Hardware::CPU.intel?
|
||||
@ -33,6 +35,7 @@ class V1 < Formula
|
||||
|
||||
def install
|
||||
bin.install "foo"
|
||||
man1.install "./man/foo.1.gz"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -14,6 +14,7 @@ class V2 < Formula
|
||||
|
||||
def install
|
||||
bin.install "foo"
|
||||
man1.install "./man/foo.1.gz"
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -25,6 +26,7 @@ class V2 < Formula
|
||||
|
||||
def install
|
||||
bin.install "foo"
|
||||
man1.install "./man/foo.1.gz"
|
||||
end
|
||||
end
|
||||
if Hardware::CPU.intel?
|
||||
@ -33,6 +35,7 @@ class V2 < Formula
|
||||
|
||||
def install
|
||||
bin.install "foo"
|
||||
man1.install "./man/foo.1.gz"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -14,6 +14,7 @@ class V3 < Formula
|
||||
|
||||
def install
|
||||
bin.install "foo"
|
||||
man1.install "./man/foo.1.gz"
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -25,6 +26,7 @@ class V3 < Formula
|
||||
|
||||
def install
|
||||
bin.install "foo"
|
||||
man1.install "./man/foo.1.gz"
|
||||
end
|
||||
end
|
||||
if Hardware::CPU.intel?
|
||||
@ -33,6 +35,7 @@ class V3 < Formula
|
||||
|
||||
def install
|
||||
bin.install "foo"
|
||||
man1.install "./man/foo.1.gz"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -14,6 +14,7 @@ class V4 < Formula
|
||||
|
||||
def install
|
||||
bin.install "foo"
|
||||
man1.install "./man/foo.1.gz"
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -25,6 +26,7 @@ class V4 < Formula
|
||||
|
||||
def install
|
||||
bin.install "foo"
|
||||
man1.install "./man/foo.1.gz"
|
||||
end
|
||||
end
|
||||
if Hardware::CPU.intel?
|
||||
@ -33,6 +35,7 @@ class V4 < Formula
|
||||
|
||||
def install
|
||||
bin.install "foo"
|
||||
man1.install "./man/foo.1.gz"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -14,6 +14,7 @@ class Foo < Formula
|
||||
|
||||
def install
|
||||
bin.install "foo_macos" => "foo"
|
||||
man1.install "./man/foo.1.gz"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -226,6 +226,7 @@ type Homebrew struct {
|
||||
Caveats string `yaml:"caveats,omitempty" json:"caveats,omitempty"`
|
||||
Plist string `yaml:"plist,omitempty" json:"plist,omitempty" jsonschema:"deprecated=true,description=use service instead"` // Deprecated
|
||||
Install string `yaml:"install,omitempty" json:"install,omitempty"`
|
||||
ExtraInstall string `yaml:"extra_install,omitempty" json:"extra_install,omitempty"`
|
||||
PostInstall string `yaml:"post_install,omitempty" json:"post_install,omitempty"`
|
||||
Dependencies []HomebrewDependency `yaml:"dependencies,omitempty" json:"dependencies,omitempty"`
|
||||
Test string `yaml:"test,omitempty" json:"test,omitempty"`
|
||||
|
@ -144,17 +144,30 @@ brews:
|
||||
# ...
|
||||
|
||||
# So you can `brew test` your formula.
|
||||
#
|
||||
# Template: allowed
|
||||
test: |
|
||||
system "#{bin}/foo --version"
|
||||
# ...
|
||||
|
||||
# Custom install script for brew.
|
||||
#
|
||||
# Template: allowed
|
||||
# Default: 'bin.install "BinaryName"'
|
||||
install: |
|
||||
bin.install "some_other_name"
|
||||
bash_completion.install "completions/foo.bash" => "foo"
|
||||
# ...
|
||||
|
||||
# Additional install instructions so you don't need to override `install`.
|
||||
#
|
||||
# Template: allowed
|
||||
# Since: v1.20.
|
||||
extra_install: |
|
||||
bash_completion.install "completions/foo.bash" => "foo"
|
||||
man1.install "man/foo.1.gz"
|
||||
# ...
|
||||
|
||||
# Custom post_install script for brew.
|
||||
# Could be used to do any additional work after the "install" script
|
||||
post_install: |
|
||||
|
Loading…
Reference in New Issue
Block a user