You've already forked goreleaser
mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-09-16 09:26:52 +02:00
feat: improve brew.install guessing (#2541)
Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>
This commit is contained in:
committed by
GitHub
parent
c8db72cef0
commit
1890e67fda
@@ -171,6 +171,7 @@ func create(ctx *context.Context, arch config.Archive, binaries []*artifact.Arti
|
||||
return fmt.Errorf("failed to add: '%s' -> '%s': %w", f.Source, f.Destination, err)
|
||||
}
|
||||
}
|
||||
bins := []string{}
|
||||
for _, binary := range binaries {
|
||||
if err := a.Add(config.File{
|
||||
Source: binary.Path,
|
||||
@@ -178,6 +179,7 @@ func create(ctx *context.Context, arch config.Archive, binaries []*artifact.Arti
|
||||
}); err != nil {
|
||||
return fmt.Errorf("failed to add: '%s' -> '%s': %w", binary.Path, binary.Name, err)
|
||||
}
|
||||
bins = append(bins, binary.Name)
|
||||
}
|
||||
ctx.Artifacts.Add(&artifact.Artifact{
|
||||
Type: artifact.UploadableArchive,
|
||||
@@ -192,6 +194,7 @@ func create(ctx *context.Context, arch config.Archive, binaries []*artifact.Arti
|
||||
"ID": arch.ID,
|
||||
"Format": arch.Format,
|
||||
"WrappedIn": wrap,
|
||||
"Binaries": bins,
|
||||
},
|
||||
})
|
||||
return nil
|
||||
@@ -226,9 +229,10 @@ func skip(ctx *context.Context, archive config.Archive, binaries []*artifact.Art
|
||||
Goarm: binary.Goarm,
|
||||
Gomips: binary.Gomips,
|
||||
Extra: map[string]interface{}{
|
||||
"Builds": []*artifact.Artifact{binary},
|
||||
"ID": archive.ID,
|
||||
"Format": archive.Format,
|
||||
"Builds": []*artifact.Artifact{binary},
|
||||
"ID": archive.ID,
|
||||
"Format": archive.Format,
|
||||
"Binaries": []string{binary.Name},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
@@ -145,7 +145,8 @@ func TestRunPipe(t *testing.T) {
|
||||
require.NoError(t, Pipe{}.Run(ctx))
|
||||
archives := ctx.Artifacts.Filter(artifact.ByType(artifact.UploadableArchive)).List()
|
||||
for _, arch := range archives {
|
||||
require.Equal(t, "myid", arch.Extra["ID"].(string), "all archives should have the archive ID set")
|
||||
require.Equal(t, "myid", arch.Extra["ID"].(string), "all archives must have the archive ID set")
|
||||
require.NotEmpty(t, arch.ExtraOr("Binaries", []string{}).([]string), "all archives must have the binary names they contain set")
|
||||
}
|
||||
require.Len(t, archives, 5)
|
||||
// TODO: should verify the artifact fields here too
|
||||
|
@@ -40,10 +40,6 @@ func (Pipe) Default(ctx *context.Context) error {
|
||||
for i := range ctx.Config.Brews {
|
||||
brew := &ctx.Config.Brews[i]
|
||||
|
||||
if brew.Install == "" {
|
||||
brew.Install = fmt.Sprintf(`bin.install "%s"`, ctx.Config.ProjectName)
|
||||
log.Warnf("optimistically guessing `brew[%d].install` to be `%s`", i, brew.Install)
|
||||
}
|
||||
if brew.CommitAuthor.Name == "" {
|
||||
brew.CommitAuthor.Name = "goreleaserbot"
|
||||
}
|
||||
@@ -268,6 +264,24 @@ func doBuildFormula(ctx *context.Context, data templateData) (string, error) {
|
||||
return out.String(), nil
|
||||
}
|
||||
|
||||
func installs(cfg config.Homebrew, artifacts []*artifact.Artifact) []string {
|
||||
if cfg.Install != "" {
|
||||
return split(cfg.Install)
|
||||
}
|
||||
install := []string{}
|
||||
bins := map[string]bool{}
|
||||
for _, a := range artifacts {
|
||||
for _, bin := range a.ExtraOr("Binaries", []string{}).([]string) {
|
||||
if !bins[bin] {
|
||||
install = append(install, fmt.Sprintf("bin.install %q", bin))
|
||||
}
|
||||
bins[bin] = true
|
||||
}
|
||||
}
|
||||
log.Warnf("guessing install to be `%s`", strings.Join(install, " "))
|
||||
return install
|
||||
}
|
||||
|
||||
func dataFor(ctx *context.Context, cfg config.Homebrew, cl client.Client, artifacts []*artifact.Artifact) (templateData, error) {
|
||||
result := templateData{
|
||||
Name: formulaNameFor(cfg.Name),
|
||||
@@ -279,7 +293,7 @@ func dataFor(ctx *context.Context, cfg config.Homebrew, cl client.Client, artifa
|
||||
Dependencies: cfg.Dependencies,
|
||||
Conflicts: cfg.Conflicts,
|
||||
Plist: cfg.Plist,
|
||||
Install: split(cfg.Install),
|
||||
Install: installs(cfg, artifacts),
|
||||
PostInstall: cfg.PostInstall,
|
||||
Tests: split(cfg.Test),
|
||||
CustomRequire: cfg.CustomRequire,
|
||||
|
@@ -870,26 +870,6 @@ func TestDefault(t *testing.T) {
|
||||
Brews: []config.Homebrew{
|
||||
{},
|
||||
},
|
||||
Builds: []config.Build{
|
||||
{
|
||||
Binary: "foo",
|
||||
Goos: []string{"linux", "darwin"},
|
||||
Goarch: []string{"386", "amd64"},
|
||||
},
|
||||
{
|
||||
Binary: "bar",
|
||||
Goos: []string{"linux", "darwin"},
|
||||
Goarch: []string{"386", "amd64"},
|
||||
Ignore: []config.IgnoredBuild{
|
||||
{Goos: "darwin", Goarch: "amd64"},
|
||||
},
|
||||
},
|
||||
{
|
||||
Binary: "foobar",
|
||||
Goos: []string{"linux"},
|
||||
Goarch: []string{"amd64"},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
require.NoError(t, Pipe{}.Default(ctx))
|
||||
@@ -897,7 +877,6 @@ func TestDefault(t *testing.T) {
|
||||
require.NotEmpty(t, ctx.Config.Brews[0].CommitAuthor.Name)
|
||||
require.NotEmpty(t, ctx.Config.Brews[0].CommitAuthor.Email)
|
||||
require.NotEmpty(t, ctx.Config.Brews[0].CommitMessageTemplate)
|
||||
require.Equal(t, `bin.install "myproject"`, ctx.Config.Brews[0].Install)
|
||||
}
|
||||
|
||||
func TestGHFolder(t *testing.T) {
|
||||
@@ -928,3 +907,46 @@ func TestRunSkipNoName(t *testing.T) {
|
||||
client := client.NewMock()
|
||||
testlib.AssertSkipped(t, runAll(ctx, client))
|
||||
}
|
||||
|
||||
func TestInstalls(t *testing.T) {
|
||||
t.Run("provided", func(t *testing.T) {
|
||||
require.Equal(t, []string{
|
||||
`bin.install "foo"`,
|
||||
`bin.install "bar"`,
|
||||
}, installs(
|
||||
config.Homebrew{Install: "bin.install \"foo\"\nbin.install \"bar\""},
|
||||
[]*artifact.Artifact{},
|
||||
))
|
||||
})
|
||||
|
||||
t.Run("from artifacts", func(t *testing.T) {
|
||||
require.Equal(t, []string{
|
||||
`bin.install "foo"`,
|
||||
`bin.install "bar"`,
|
||||
}, installs(
|
||||
config.Homebrew{},
|
||||
[]*artifact.Artifact{
|
||||
{
|
||||
Extra: map[string]interface{}{
|
||||
"Binaries": []string{"foo", "bar"},
|
||||
},
|
||||
},
|
||||
{
|
||||
Extra: map[string]interface{}{
|
||||
"Binaries": []string{"foo"},
|
||||
},
|
||||
},
|
||||
{
|
||||
Extra: map[string]interface{}{
|
||||
"Binaries": []string{"bar"},
|
||||
},
|
||||
},
|
||||
{
|
||||
Extra: map[string]interface{}{
|
||||
"Binaries": []string{"bar", "foo"},
|
||||
},
|
||||
},
|
||||
},
|
||||
))
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user