Skip to content

Commit

Permalink
fix: improve brew no archive error (#3895)
Browse files Browse the repository at this point in the history
similar to #3894, but for homebrew

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
  • Loading branch information
caarlos0 committed Mar 29, 2023
1 parent 37e92ce commit 9a97aaa
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
26 changes: 18 additions & 8 deletions internal/pipe/brew/brew.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,20 @@ import (

const brewConfigExtra = "BrewConfig"

var (
// ErrNoArchivesFound happens when 0 archives are found.
ErrNoArchivesFound = errors.New("no linux/macos archives found")
// ErrMultipleArchivesSameOS happens when the config yields multiple archives
// for linux or windows.
var ErrMultipleArchivesSameOS = errors.New("one tap can handle only archive of an OS/Arch combination. Consider using ids in the brew section")

// ErrNoArchivesFound happens when 0 archives are found.
type ErrNoArchivesFound struct {
goarm string
goamd64 string
ids []string
}

// ErrMultipleArchivesSameOS happens when the config yields multiple archives
// for linux or windows.
ErrMultipleArchivesSameOS = errors.New("one tap can handle only archive of an OS/Arch combination. Consider using ids in the brew section")
)
func (e ErrNoArchivesFound) Error() string {
return fmt.Sprintf("no linux/macos archives found matching goos=[darwin linux] goarch=[amd64 arm64 arm] goamd64=%s goarm=%s ids=%v", e.goamd64, e.goarm, e.ids)
}

// Pipe for brew deployment.
type Pipe struct{}
Expand Down Expand Up @@ -187,7 +193,11 @@ func doRun(ctx *context.Context, brew config.Homebrew, cl client.Client) error {

archives := ctx.Artifacts.Filter(artifact.And(filters...)).List()
if len(archives) == 0 {
return ErrNoArchivesFound
return ErrNoArchivesFound{
goamd64: brew.Goamd64,
goarm: brew.Goarm,
ids: brew.IDs,
}
}

name, err := tmpl.New(ctx).Apply(brew.Name)
Expand Down
8 changes: 7 additions & 1 deletion internal/pipe/brew/brew_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -767,11 +767,17 @@ func TestRunPipeNoBuilds(t *testing.T) {
Owner: "test",
Name: "test",
},
IDs: []string{"foo"},
},
},
}, testctx.GitHubTokenType)
client := client.NewMock()
require.Equal(t, ErrNoArchivesFound, runAll(ctx, client))
require.NoError(t, Pipe{}.Default(ctx))
require.EqualError(t, runAll(ctx, client), ErrNoArchivesFound{
ids: []string{"foo"},
goarm: "6",
goamd64: "v1",
}.Error())
require.False(t, client.CreatedFile)
}

Expand Down

0 comments on commit 9a97aaa

Please sign in to comment.