mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-01-10 03:47:03 +02:00
66 lines
1.5 KiB
Go
66 lines
1.5 KiB
Go
// Package publish contains the publishing pipe.
|
|
package publish
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/apex/log"
|
|
"github.com/fatih/color"
|
|
"github.com/goreleaser/goreleaser/internal/pipe"
|
|
"github.com/goreleaser/goreleaser/internal/pipe/brew"
|
|
"github.com/goreleaser/goreleaser/internal/pipe/release"
|
|
"github.com/goreleaser/goreleaser/internal/pipe/scoop"
|
|
"github.com/goreleaser/goreleaser/pkg/context"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
// Pipe that publishes artifacts
|
|
type Pipe struct{}
|
|
|
|
func (Pipe) String() string {
|
|
return "publishing artifacts"
|
|
}
|
|
|
|
// 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
|
|
}
|
|
|
|
var publishers = []Publisher{
|
|
release.Pipe{},
|
|
brew.Pipe{},
|
|
scoop.Pipe{},
|
|
}
|
|
|
|
var bold = color.New(color.Bold)
|
|
|
|
// Run the pipe
|
|
func (Pipe) Run(ctx *context.Context) error {
|
|
if ctx.SkipPublish {
|
|
return pipe.ErrSkipPublishEnabled
|
|
}
|
|
for _, publisher := range publishers {
|
|
log.Infof(bold.Sprint(publisher.String()))
|
|
if err := handle(publisher.Publish(ctx)); err != nil {
|
|
return errors.Wrapf(err, "%s: failed to publish artifacts", publisher.String())
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// TODO: for now this is duplicated, we should have better error handling
|
|
// eventually.
|
|
func handle(err error) error {
|
|
if err == nil {
|
|
return nil
|
|
}
|
|
if pipe.IsSkip(err) {
|
|
log.WithField("reason", err.Error()).Warn("skipped")
|
|
return nil
|
|
}
|
|
return err
|
|
}
|