1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-22 04:08:49 +02:00
Carlos Alexandro Becker 72cf8404c1
feat: continue on error (#4127)
closes #3989

Basically, when some of these pipes fail, the error will be memorized,
and all errors will be thrown in the end.

Meaning: the exit code will still be 1, but it'll not have stopped in
the first error.

Thinking of maybe adding a `--fail-fast` flag to disable this behavior
as well 🤔

---------

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
2023-06-20 09:33:59 -03:00

97 lines
2.8 KiB
Go

// Package publish contains the publishing pipe.
package publish
import (
"fmt"
"github.com/goreleaser/goreleaser/internal/middleware/errhandler"
"github.com/goreleaser/goreleaser/internal/middleware/logging"
"github.com/goreleaser/goreleaser/internal/middleware/skip"
"github.com/goreleaser/goreleaser/internal/pipe/artifactory"
"github.com/goreleaser/goreleaser/internal/pipe/aur"
"github.com/goreleaser/goreleaser/internal/pipe/blob"
"github.com/goreleaser/goreleaser/internal/pipe/brew"
"github.com/goreleaser/goreleaser/internal/pipe/chocolatey"
"github.com/goreleaser/goreleaser/internal/pipe/custompublishers"
"github.com/goreleaser/goreleaser/internal/pipe/docker"
"github.com/goreleaser/goreleaser/internal/pipe/ko"
"github.com/goreleaser/goreleaser/internal/pipe/krew"
"github.com/goreleaser/goreleaser/internal/pipe/milestone"
"github.com/goreleaser/goreleaser/internal/pipe/nix"
"github.com/goreleaser/goreleaser/internal/pipe/release"
"github.com/goreleaser/goreleaser/internal/pipe/scoop"
"github.com/goreleaser/goreleaser/internal/pipe/sign"
"github.com/goreleaser/goreleaser/internal/pipe/snapcraft"
"github.com/goreleaser/goreleaser/internal/pipe/upload"
"github.com/goreleaser/goreleaser/internal/pipe/winget"
"github.com/goreleaser/goreleaser/pkg/context"
)
// Publisher should be implemented by pipes that want to publish artifacts.
type Publisher interface {
fmt.Stringer
// Default sets the configuration defaults
Publish(ctx *context.Context) error
}
// New publish pipeline.
func New() Pipe {
return Pipe{
pipeline: []Publisher{
blob.Pipe{},
upload.Pipe{},
artifactory.Pipe{},
custompublishers.Pipe{},
docker.Pipe{},
docker.ManifestPipe{},
ko.Pipe{},
sign.DockerPipe{},
snapcraft.Pipe{},
// This should be one of the last steps
release.Pipe{},
// brew et al use the release URL, so, they should be last
nix.NewPublish(),
winget.Pipe{},
brew.Pipe{},
aur.Pipe{},
krew.Pipe{},
scoop.Pipe{},
chocolatey.Pipe{},
milestone.Pipe{},
},
}
}
// Pipe that publishes artifacts.
type Pipe struct {
pipeline []Publisher
}
func (Pipe) String() string { return "publishing" }
func (Pipe) Skip(ctx *context.Context) bool { return ctx.SkipPublish }
func (p Pipe) Run(ctx *context.Context) error {
memo := errhandler.Memo{}
for _, publisher := range p.pipeline {
if err := skip.Maybe(
publisher,
logging.PadLog(
publisher.String(),
errhandler.Handle(publisher.Publish),
),
)(ctx); err != nil {
if ig, ok := publisher.(Continuable); ok && ig.ContinueOnError() && !ctx.FailFast {
memo.Memorize(fmt.Errorf("%s: %w", publisher.String(), err))
continue
}
return fmt.Errorf("%s: failed to publish artifacts: %w", publisher.String(), err)
}
}
return memo.Error()
}
type Continuable interface {
ContinueOnError() bool
}