mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-03-17 20:47:50 +02:00
fix(brew) create file if skip is set (#1757)
* test: multiple brews with skip upload Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix(brew) create file if skip is set Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * refactor: improve code a bit Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: duplicated errors Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>
This commit is contained in:
parent
da22bf8eb8
commit
acfd0024fa
@ -53,16 +53,28 @@ func (Pipe) Publish(ctx *context.Context) error {
|
||||
ctx.TokenType = context.TokenTypeGitHub
|
||||
}
|
||||
|
||||
client, err := client.New(ctx)
|
||||
cli, err := client.New(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return publishAll(ctx, cli)
|
||||
}
|
||||
|
||||
func publishAll(ctx *context.Context, cli client.Client) error {
|
||||
// even if one of them skips, we run them all, and then show return the skips all at once.
|
||||
// this is needed so we actually create the `dist/foo.rb` file, which is useful for debugging.
|
||||
var skips = pipe.SkipMemento{}
|
||||
for _, brew := range ctx.Config.Brews {
|
||||
if err := doRun(ctx, brew, client); err != nil {
|
||||
var err = doRun(ctx, brew, cli)
|
||||
if err != nil && pipe.IsSkip(err) {
|
||||
skips.Remember(err)
|
||||
continue
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
return skips.Evaluate()
|
||||
}
|
||||
|
||||
// Default sets the pipe defaults.
|
||||
|
@ -14,6 +14,7 @@ import (
|
||||
"github.com/goreleaser/goreleaser/pkg/config"
|
||||
"github.com/goreleaser/goreleaser/pkg/context"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
var update = flag.Bool("update", false, "update .golden files")
|
||||
@ -296,6 +297,86 @@ func TestRunPipeNameTemplate(t *testing.T) {
|
||||
assert.Equal(t, string(bts), string(distBts))
|
||||
}
|
||||
|
||||
func TestRunPipeMultipleBrewsWithSkip(t *testing.T) {
|
||||
folder, err := ioutil.TempDir("", "goreleasertest")
|
||||
assert.NoError(t, err)
|
||||
var ctx = &context.Context{
|
||||
Git: context.GitInfo{
|
||||
CurrentTag: "v1.0.1",
|
||||
},
|
||||
Version: "1.0.1",
|
||||
Artifacts: artifact.New(),
|
||||
Env: map[string]string{
|
||||
"FOO_BAR": "is_bar",
|
||||
},
|
||||
Config: config.Project{
|
||||
Dist: folder,
|
||||
ProjectName: "foo",
|
||||
Brews: []config.Homebrew{
|
||||
{
|
||||
Name: "foo",
|
||||
Tap: config.RepoRef{
|
||||
Owner: "foo",
|
||||
Name: "bar",
|
||||
},
|
||||
IDs: []string{
|
||||
"foo",
|
||||
},
|
||||
SkipUpload: "true",
|
||||
},
|
||||
{
|
||||
Name: "bar",
|
||||
Tap: config.RepoRef{
|
||||
Owner: "foo",
|
||||
Name: "bar",
|
||||
},
|
||||
IDs: []string{
|
||||
"foo",
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "foobar",
|
||||
Tap: config.RepoRef{
|
||||
Owner: "foo",
|
||||
Name: "bar",
|
||||
},
|
||||
IDs: []string{
|
||||
"foo",
|
||||
},
|
||||
SkipUpload: "true",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
var path = filepath.Join(folder, "bin.tar.gz")
|
||||
ctx.Artifacts.Add(&artifact.Artifact{
|
||||
Name: "bin.tar.gz",
|
||||
Path: path,
|
||||
Goos: "darwin",
|
||||
Goarch: "amd64",
|
||||
Type: artifact.UploadableArchive,
|
||||
Extra: map[string]interface{}{
|
||||
"ID": "foo",
|
||||
"Format": "tar.gz",
|
||||
"ArtifactUploadHash": "820ead5d9d2266c728dce6d4d55b6460",
|
||||
},
|
||||
})
|
||||
|
||||
_, err = os.Create(path)
|
||||
assert.NoError(t, err)
|
||||
|
||||
var cli = &DummyClient{}
|
||||
assert.EqualError(t, publishAll(ctx, cli), `brew.skip_upload is set`)
|
||||
assert.True(t, cli.CreatedFile)
|
||||
|
||||
for _, brew := range ctx.Config.Brews {
|
||||
var distFile = filepath.Join(folder, brew.Name+".rb")
|
||||
_, err := os.Stat(distFile)
|
||||
require.NoError(t, err, "file should exist: "+distFile)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestRunPipeForMultipleArmVersions(t *testing.T) {
|
||||
for name, fn := range map[string]func(ctx *context.Context){
|
||||
"multiple_armv5": func(ctx *context.Context) {
|
||||
|
@ -1,6 +1,8 @@
|
||||
// Package pipe provides generic erros for pipes to use.
|
||||
package pipe
|
||||
|
||||
import "strings"
|
||||
|
||||
// ErrSnapshotEnabled happens when goreleaser is running in snapshot mode.
|
||||
// It usually means that publishing and maybe some validations were skipped.
|
||||
var ErrSnapshotEnabled = Skip("disabled during snapshot mode")
|
||||
@ -37,3 +39,26 @@ func (e ErrSkip) Error() string {
|
||||
func Skip(reason string) ErrSkip {
|
||||
return ErrSkip{reason: reason}
|
||||
}
|
||||
|
||||
// SkipMemento remembers previous skip errors so you can return them all at once later.
|
||||
type SkipMemento struct {
|
||||
skips []string
|
||||
}
|
||||
|
||||
// Remember a skip.
|
||||
func (e *SkipMemento) Remember(err error) {
|
||||
for _, skip := range e.skips {
|
||||
if skip == err.Error() {
|
||||
return
|
||||
}
|
||||
}
|
||||
e.skips = append(e.skips, err.Error())
|
||||
}
|
||||
|
||||
// Evaluate return a skip error with all previous skips, or nil if none happened.
|
||||
func (e *SkipMemento) Evaluate() error {
|
||||
if len(e.skips) == 0 {
|
||||
return nil
|
||||
}
|
||||
return Skip(strings.Join(e.skips, ", "))
|
||||
}
|
||||
|
@ -18,3 +18,18 @@ func TestIsSkip(t *testing.T) {
|
||||
assert.True(t, IsSkip(Skip("whatever")))
|
||||
assert.False(t, IsSkip(errors.New("nope")))
|
||||
}
|
||||
|
||||
func TestSkipMemento(t *testing.T) {
|
||||
var m = SkipMemento{}
|
||||
m.Remember(Skip("foo"))
|
||||
m.Remember(Skip("bar"))
|
||||
// test duplicated errors
|
||||
m.Remember(Skip("dupe"))
|
||||
m.Remember(Skip("dupe"))
|
||||
assert.EqualError(t, m.Evaluate(), `foo, bar, dupe`)
|
||||
assert.True(t, IsSkip(m.Evaluate()))
|
||||
}
|
||||
|
||||
func TestSkipMementoNoErrors(t *testing.T) {
|
||||
assert.NoError(t, (&SkipMemento{}).Evaluate())
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user