github.com/jonathanlloyd/goreleaser@v0.91.1/internal/pipe/publish/publish.go (about) 1 // Package publish contains the publishing pipe. 2 package publish 3 4 import ( 5 "fmt" 6 7 "github.com/apex/log" 8 "github.com/fatih/color" 9 "github.com/goreleaser/goreleaser/internal/pipe" 10 "github.com/goreleaser/goreleaser/internal/pipe/artifactory" 11 "github.com/goreleaser/goreleaser/internal/pipe/brew" 12 "github.com/goreleaser/goreleaser/internal/pipe/docker" 13 "github.com/goreleaser/goreleaser/internal/pipe/put" 14 "github.com/goreleaser/goreleaser/internal/pipe/release" 15 "github.com/goreleaser/goreleaser/internal/pipe/s3" 16 "github.com/goreleaser/goreleaser/internal/pipe/scoop" 17 "github.com/goreleaser/goreleaser/internal/pipe/snapcraft" 18 "github.com/goreleaser/goreleaser/pkg/context" 19 "github.com/pkg/errors" 20 ) 21 22 // Pipe that publishes artifacts 23 type Pipe struct{} 24 25 func (Pipe) String() string { 26 return "publishing artifacts" 27 } 28 29 // Publisher should be implemented by pipes that want to publish artifacts 30 type Publisher interface { 31 fmt.Stringer 32 33 // Default sets the configuration defaults 34 Publish(ctx *context.Context) error 35 } 36 37 var publishers = []Publisher{ 38 s3.Pipe{}, 39 put.Pipe{}, 40 artifactory.Pipe{}, 41 release.Pipe{}, 42 brew.Pipe{}, 43 scoop.Pipe{}, 44 docker.Pipe{}, 45 snapcraft.Pipe{}, 46 } 47 48 var bold = color.New(color.Bold) 49 50 // Run the pipe 51 func (Pipe) Run(ctx *context.Context) error { 52 if ctx.SkipPublish { 53 return pipe.ErrSkipPublishEnabled 54 } 55 for _, publisher := range publishers { 56 log.Infof(bold.Sprint(publisher.String())) 57 if err := handle(publisher.Publish(ctx)); err != nil { 58 return errors.Wrapf(err, "%s: failed to publish artifacts", publisher.String()) 59 } 60 } 61 return nil 62 } 63 64 // TODO: for now this is duplicated, we should have better error handling 65 // eventually. 66 func handle(err error) error { 67 if err == nil { 68 return nil 69 } 70 if pipe.IsSkip(err) { 71 log.WithField("reason", err.Error()).Warn("skipped") 72 return nil 73 } 74 return err 75 }