mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-04-11 11:42:15 +02:00
feat(homebrew): support binary releases (#2576)
* feat(homebrew): support binary releases Signed-off-by: Carlos A Becker <caarlos0@gmail.com> * fix: improve code Signed-off-by: Carlos A Becker <caarlos0@gmail.com> * fix: improve code a bit Signed-off-by: Carlos A Becker <caarlos0@gmail.com> * test: fix archive testts Signed-off-by: Carlos A Becker <caarlos0@gmail.com>
This commit is contained in:
parent
f4cef96055
commit
c99071eb9e
@ -400,13 +400,10 @@ func TestRunPipeBinary(t *testing.T) {
|
||||
)).List()[0]
|
||||
windows := binaries.Filter(artifact.ByGoos("windows")).List()[0]
|
||||
require.Equal(t, "mybin_0.0.1_darwin_amd64", darwinThin.Name)
|
||||
require.Equal(t, []string{"mybin_0.0.1_darwin_amd64"}, darwinThin.ExtraOr(artifact.ExtraBinaries, []string{}))
|
||||
require.Equal(t, "mybin", darwinThin.ExtraOr(artifact.ExtraBinary, ""))
|
||||
require.Equal(t, "myunibin_0.0.1_darwin_all", darwinUniversal.Name)
|
||||
require.Equal(t, []string{"myunibin_0.0.1_darwin_all"}, darwinUniversal.ExtraOr(artifact.ExtraBinaries, []string{}))
|
||||
require.Equal(t, "myunibin", darwinUniversal.ExtraOr(artifact.ExtraBinary, ""))
|
||||
require.Equal(t, "mybin_0.0.1_windows_amd64.exe", windows.Name)
|
||||
require.Equal(t, []string{"mybin_0.0.1_windows_amd64.exe"}, windows.ExtraOr(artifact.ExtraBinaries, []string{}))
|
||||
require.Equal(t, "mybin.exe", windows.ExtraOr(artifact.ExtraBinary, ""))
|
||||
}
|
||||
|
||||
@ -797,7 +794,7 @@ func TestBinaryOverride(t *testing.T) {
|
||||
windows := archives.Filter(artifact.ByGoos("windows")).List()[0]
|
||||
require.Equal(t, "foobar_0.0.1_windows_amd64.exe", windows.Name)
|
||||
require.Empty(t, windows.ExtraOr(artifact.ExtraWrappedIn, ""))
|
||||
require.Equal(t, windows.ExtraOr(artifact.ExtraBinaries, []string{}), []string{"foobar_0.0.1_windows_amd64.exe"})
|
||||
require.Equal(t, "mybin.exe", windows.ExtraOr(artifact.ExtraBinary, ""))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -152,7 +152,6 @@ func doRun(ctx *context.Context, brew config.Homebrew, cl client.Client) error {
|
||||
artifact.ByGoos("darwin"),
|
||||
artifact.ByGoos("linux"),
|
||||
),
|
||||
artifact.ByFormats("zip", "tar.gz"),
|
||||
artifact.Or(
|
||||
artifact.ByGoarch("amd64"),
|
||||
artifact.ByGoarch("arm64"),
|
||||
@ -162,7 +161,13 @@ func doRun(ctx *context.Context, brew config.Homebrew, cl client.Client) error {
|
||||
artifact.ByGoarm(brew.Goarm),
|
||||
),
|
||||
),
|
||||
artifact.ByType(artifact.UploadableArchive),
|
||||
artifact.Or(
|
||||
artifact.And(
|
||||
artifact.ByFormats("zip", "tar.gz"),
|
||||
artifact.ByType(artifact.UploadableArchive),
|
||||
),
|
||||
artifact.ByType(artifact.UploadableBinary),
|
||||
),
|
||||
}
|
||||
if len(brew.IDs) > 0 {
|
||||
filters = append(filters, artifact.ByIDs(brew.IDs...))
|
||||
@ -275,18 +280,31 @@ func installs(cfg config.Homebrew, artifacts []*artifact.Artifact) []string {
|
||||
if cfg.Install != "" {
|
||||
return split(cfg.Install)
|
||||
}
|
||||
install := []string{}
|
||||
bins := map[string]bool{}
|
||||
install := map[string]bool{}
|
||||
for _, a := range artifacts {
|
||||
for _, bin := range a.ExtraOr(artifact.ExtraBinaries, []string{}).([]string) {
|
||||
if !bins[bin] {
|
||||
install = append(install, fmt.Sprintf("bin.install %q", bin))
|
||||
switch a.Type {
|
||||
case artifact.UploadableBinary:
|
||||
name := a.Name
|
||||
bin := a.ExtraOr(artifact.ExtraBinary, a.Name).(string)
|
||||
install[fmt.Sprintf("bin.install %q => %q", name, bin)] = true
|
||||
case artifact.UploadableArchive:
|
||||
for _, bin := range a.ExtraOr(artifact.ExtraBinaries, []string{}).([]string) {
|
||||
install[fmt.Sprintf("bin.install %q", bin)] = true
|
||||
}
|
||||
bins[bin] = true
|
||||
}
|
||||
}
|
||||
log.Warnf("guessing install to be `%s`", strings.Join(install, " "))
|
||||
return install
|
||||
|
||||
result := keys(install)
|
||||
log.Warnf("guessing install to be %q", strings.Join(result, ", "))
|
||||
return result
|
||||
}
|
||||
|
||||
func keys(m map[string]bool) []string {
|
||||
keys := make([]string, 0, len(m))
|
||||
for k := range m {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
return keys
|
||||
}
|
||||
|
||||
func dataFor(ctx *context.Context, cfg config.Homebrew, cl client.Client, artifacts []*artifact.Artifact) (templateData, error) {
|
||||
|
@ -768,28 +768,52 @@ func TestRunPipeMultipleArchivesSameOsBuild(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRunPipeBinaryRelease(t *testing.T) {
|
||||
ctx := context.New(
|
||||
config.Project{
|
||||
folder := t.TempDir()
|
||||
ctx := &context.Context{
|
||||
Git: context.GitInfo{
|
||||
CurrentTag: "v1.2.1",
|
||||
},
|
||||
Version: "1.2.1",
|
||||
Artifacts: artifact.New(),
|
||||
Config: config.Project{
|
||||
Dist: folder,
|
||||
ProjectName: "foo",
|
||||
Brews: []config.Homebrew{
|
||||
{
|
||||
Name: "foo",
|
||||
Tap: config.RepoRef{
|
||||
Owner: "test",
|
||||
Name: "test",
|
||||
Owner: "foo",
|
||||
Name: "bar",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
path := filepath.Join(folder, "dist/foo_darwin_all/foo")
|
||||
ctx.Artifacts.Add(&artifact.Artifact{
|
||||
Name: "bin",
|
||||
Path: "doesnt mather",
|
||||
Name: "foo_macos",
|
||||
Path: path,
|
||||
Goos: "darwin",
|
||||
Goarch: "amd64",
|
||||
Type: artifact.Binary,
|
||||
Goarch: "all",
|
||||
Type: artifact.UploadableBinary,
|
||||
Extra: map[string]interface{}{
|
||||
artifact.ExtraID: "foo",
|
||||
artifact.ExtraFormat: "binary",
|
||||
artifact.ExtraBinary: "foo",
|
||||
},
|
||||
})
|
||||
|
||||
require.NoError(t, os.MkdirAll(filepath.Dir(path), 0o755))
|
||||
f, err := os.Create(path)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.Close())
|
||||
|
||||
client := client.NewMock()
|
||||
require.Equal(t, ErrNoArchivesFound, runAll(ctx, client))
|
||||
require.False(t, client.CreatedFile)
|
||||
require.NoError(t, runAll(ctx, client))
|
||||
require.NoError(t, publishAll(ctx, client))
|
||||
require.True(t, client.CreatedFile)
|
||||
golden.RequireEqualRb(t, []byte(client.Content))
|
||||
}
|
||||
|
||||
func TestRunPipeNoUpload(t *testing.T) {
|
||||
@ -947,7 +971,7 @@ func TestInstalls(t *testing.T) {
|
||||
))
|
||||
})
|
||||
|
||||
t.Run("from artifacts", func(t *testing.T) {
|
||||
t.Run("from archives", func(t *testing.T) {
|
||||
require.Equal(t, []string{
|
||||
`bin.install "foo"`,
|
||||
`bin.install "bar"`,
|
||||
@ -955,21 +979,25 @@ func TestInstalls(t *testing.T) {
|
||||
config.Homebrew{},
|
||||
[]*artifact.Artifact{
|
||||
{
|
||||
Type: artifact.UploadableArchive,
|
||||
Extra: map[string]interface{}{
|
||||
artifact.ExtraBinaries: []string{"foo", "bar"},
|
||||
},
|
||||
},
|
||||
{
|
||||
Type: artifact.UploadableArchive,
|
||||
Extra: map[string]interface{}{
|
||||
artifact.ExtraBinaries: []string{"foo"},
|
||||
},
|
||||
},
|
||||
{
|
||||
Type: artifact.UploadableArchive,
|
||||
Extra: map[string]interface{}{
|
||||
artifact.ExtraBinaries: []string{"bar"},
|
||||
},
|
||||
},
|
||||
{
|
||||
Type: artifact.UploadableArchive,
|
||||
Extra: map[string]interface{}{
|
||||
artifact.ExtraBinaries: []string{"bar", "foo"},
|
||||
},
|
||||
@ -977,6 +1005,23 @@ func TestInstalls(t *testing.T) {
|
||||
},
|
||||
))
|
||||
})
|
||||
|
||||
t.Run("from binary", func(t *testing.T) {
|
||||
require.Equal(t, []string{
|
||||
`bin.install "foo_macos" => "foo"`,
|
||||
}, installs(
|
||||
config.Homebrew{},
|
||||
[]*artifact.Artifact{
|
||||
{
|
||||
Name: "foo_macos",
|
||||
Type: artifact.UploadableBinary,
|
||||
Extra: map[string]interface{}{
|
||||
artifact.ExtraBinary: "foo",
|
||||
},
|
||||
},
|
||||
},
|
||||
))
|
||||
})
|
||||
}
|
||||
|
||||
func TestRunPipeUniversalBinary(t *testing.T) {
|
||||
|
20
internal/pipe/brew/testdata/TestRunPipeBinaryRelease.rb.golden
vendored
Normal file
20
internal/pipe/brew/testdata/TestRunPipeBinaryRelease.rb.golden
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
# typed: false
|
||||
# frozen_string_literal: true
|
||||
|
||||
# This file was generated by GoReleaser. DO NOT EDIT.
|
||||
class Foo < Formula
|
||||
desc ""
|
||||
homepage ""
|
||||
version "1.2.1"
|
||||
bottle :unneeded
|
||||
depends_on :macos
|
||||
|
||||
on_macos do
|
||||
url "https://dummyhost/download/v1.2.1/foo_macos"
|
||||
sha256 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
|
||||
end
|
||||
|
||||
def install
|
||||
bin.install "foo_macos" => "foo"
|
||||
end
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user