You've already forked goreleaser
mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-07-17 01:42:37 +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:
committed by
GitHub
parent
f4cef96055
commit
c99071eb9e
@ -400,13 +400,10 @@ func TestRunPipeBinary(t *testing.T) {
|
|||||||
)).List()[0]
|
)).List()[0]
|
||||||
windows := binaries.Filter(artifact.ByGoos("windows")).List()[0]
|
windows := binaries.Filter(artifact.ByGoos("windows")).List()[0]
|
||||||
require.Equal(t, "mybin_0.0.1_darwin_amd64", darwinThin.Name)
|
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, "mybin", darwinThin.ExtraOr(artifact.ExtraBinary, ""))
|
||||||
require.Equal(t, "myunibin_0.0.1_darwin_all", darwinUniversal.Name)
|
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, "myunibin", darwinUniversal.ExtraOr(artifact.ExtraBinary, ""))
|
||||||
require.Equal(t, "mybin_0.0.1_windows_amd64.exe", windows.Name)
|
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, ""))
|
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]
|
windows := archives.Filter(artifact.ByGoos("windows")).List()[0]
|
||||||
require.Equal(t, "foobar_0.0.1_windows_amd64.exe", windows.Name)
|
require.Equal(t, "foobar_0.0.1_windows_amd64.exe", windows.Name)
|
||||||
require.Empty(t, windows.ExtraOr(artifact.ExtraWrappedIn, ""))
|
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("darwin"),
|
||||||
artifact.ByGoos("linux"),
|
artifact.ByGoos("linux"),
|
||||||
),
|
),
|
||||||
artifact.ByFormats("zip", "tar.gz"),
|
|
||||||
artifact.Or(
|
artifact.Or(
|
||||||
artifact.ByGoarch("amd64"),
|
artifact.ByGoarch("amd64"),
|
||||||
artifact.ByGoarch("arm64"),
|
artifact.ByGoarch("arm64"),
|
||||||
@ -162,7 +161,13 @@ func doRun(ctx *context.Context, brew config.Homebrew, cl client.Client) error {
|
|||||||
artifact.ByGoarm(brew.Goarm),
|
artifact.ByGoarm(brew.Goarm),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
artifact.Or(
|
||||||
|
artifact.And(
|
||||||
|
artifact.ByFormats("zip", "tar.gz"),
|
||||||
artifact.ByType(artifact.UploadableArchive),
|
artifact.ByType(artifact.UploadableArchive),
|
||||||
|
),
|
||||||
|
artifact.ByType(artifact.UploadableBinary),
|
||||||
|
),
|
||||||
}
|
}
|
||||||
if len(brew.IDs) > 0 {
|
if len(brew.IDs) > 0 {
|
||||||
filters = append(filters, artifact.ByIDs(brew.IDs...))
|
filters = append(filters, artifact.ByIDs(brew.IDs...))
|
||||||
@ -275,18 +280,31 @@ func installs(cfg config.Homebrew, artifacts []*artifact.Artifact) []string {
|
|||||||
if cfg.Install != "" {
|
if cfg.Install != "" {
|
||||||
return split(cfg.Install)
|
return split(cfg.Install)
|
||||||
}
|
}
|
||||||
install := []string{}
|
install := map[string]bool{}
|
||||||
bins := map[string]bool{}
|
|
||||||
for _, a := range artifacts {
|
for _, a := range artifacts {
|
||||||
|
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) {
|
for _, bin := range a.ExtraOr(artifact.ExtraBinaries, []string{}).([]string) {
|
||||||
if !bins[bin] {
|
install[fmt.Sprintf("bin.install %q", bin)] = true
|
||||||
install = append(install, fmt.Sprintf("bin.install %q", bin))
|
|
||||||
}
|
|
||||||
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) {
|
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) {
|
func TestRunPipeBinaryRelease(t *testing.T) {
|
||||||
ctx := context.New(
|
folder := t.TempDir()
|
||||||
config.Project{
|
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{
|
Brews: []config.Homebrew{
|
||||||
{
|
{
|
||||||
|
Name: "foo",
|
||||||
Tap: config.RepoRef{
|
Tap: config.RepoRef{
|
||||||
Owner: "test",
|
Owner: "foo",
|
||||||
Name: "test",
|
Name: "bar",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
)
|
}
|
||||||
|
|
||||||
|
path := filepath.Join(folder, "dist/foo_darwin_all/foo")
|
||||||
ctx.Artifacts.Add(&artifact.Artifact{
|
ctx.Artifacts.Add(&artifact.Artifact{
|
||||||
Name: "bin",
|
Name: "foo_macos",
|
||||||
Path: "doesnt mather",
|
Path: path,
|
||||||
Goos: "darwin",
|
Goos: "darwin",
|
||||||
Goarch: "amd64",
|
Goarch: "all",
|
||||||
Type: artifact.Binary,
|
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()
|
client := client.NewMock()
|
||||||
require.Equal(t, ErrNoArchivesFound, runAll(ctx, client))
|
require.NoError(t, runAll(ctx, client))
|
||||||
require.False(t, client.CreatedFile)
|
require.NoError(t, publishAll(ctx, client))
|
||||||
|
require.True(t, client.CreatedFile)
|
||||||
|
golden.RequireEqualRb(t, []byte(client.Content))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRunPipeNoUpload(t *testing.T) {
|
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{
|
require.Equal(t, []string{
|
||||||
`bin.install "foo"`,
|
`bin.install "foo"`,
|
||||||
`bin.install "bar"`,
|
`bin.install "bar"`,
|
||||||
@ -955,21 +979,25 @@ func TestInstalls(t *testing.T) {
|
|||||||
config.Homebrew{},
|
config.Homebrew{},
|
||||||
[]*artifact.Artifact{
|
[]*artifact.Artifact{
|
||||||
{
|
{
|
||||||
|
Type: artifact.UploadableArchive,
|
||||||
Extra: map[string]interface{}{
|
Extra: map[string]interface{}{
|
||||||
artifact.ExtraBinaries: []string{"foo", "bar"},
|
artifact.ExtraBinaries: []string{"foo", "bar"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
Type: artifact.UploadableArchive,
|
||||||
Extra: map[string]interface{}{
|
Extra: map[string]interface{}{
|
||||||
artifact.ExtraBinaries: []string{"foo"},
|
artifact.ExtraBinaries: []string{"foo"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
Type: artifact.UploadableArchive,
|
||||||
Extra: map[string]interface{}{
|
Extra: map[string]interface{}{
|
||||||
artifact.ExtraBinaries: []string{"bar"},
|
artifact.ExtraBinaries: []string{"bar"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
Type: artifact.UploadableArchive,
|
||||||
Extra: map[string]interface{}{
|
Extra: map[string]interface{}{
|
||||||
artifact.ExtraBinaries: []string{"bar", "foo"},
|
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) {
|
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
|
Reference in New Issue
Block a user