1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-24 04:16:27 +02:00

74 lines
1.7 KiB
Go
Raw Normal View History

2018-10-05 09:22:53 -03:00
// Package publish contains the publishing pipe.
package publish
import (
"fmt"
2018-10-12 00:14:06 -03:00
"github.com/apex/log"
2018-10-12 00:26:54 -03:00
"github.com/fatih/color"
2018-10-05 09:22:53 -03:00
"github.com/goreleaser/goreleaser/internal/pipe"
"github.com/goreleaser/goreleaser/internal/pipe/artifactory"
2018-10-10 12:47:31 -03:00
"github.com/goreleaser/goreleaser/internal/pipe/brew"
2018-10-20 13:45:31 -03:00
"github.com/goreleaser/goreleaser/internal/pipe/docker"
2018-10-16 20:50:49 -03:00
"github.com/goreleaser/goreleaser/internal/pipe/put"
2018-10-16 20:39:10 -03:00
"github.com/goreleaser/goreleaser/internal/pipe/release"
2018-10-16 20:50:49 -03:00
"github.com/goreleaser/goreleaser/internal/pipe/s3"
2018-10-10 12:47:31 -03:00
"github.com/goreleaser/goreleaser/internal/pipe/scoop"
2018-10-05 09:22:53 -03:00
"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
}
2018-10-10 12:47:31 -03:00
var publishers = []Publisher{
2018-10-16 20:50:49 -03:00
s3.Pipe{},
put.Pipe{},
artifactory.Pipe{},
2018-10-16 20:39:10 -03:00
release.Pipe{},
2018-10-10 12:47:31 -03:00
brew.Pipe{},
scoop.Pipe{},
2018-10-20 13:45:31 -03:00
docker.Pipe{},
2018-10-10 12:47:31 -03:00
}
2018-10-05 09:22:53 -03:00
2018-10-12 00:26:54 -03:00
var bold = color.New(color.Bold)
2018-10-05 09:22:53 -03:00
// Run the pipe
func (Pipe) Run(ctx *context.Context) error {
if ctx.SkipPublish {
return pipe.ErrSkipPublishEnabled
}
for _, publisher := range publishers {
2018-10-12 00:26:54 -03:00
log.Infof(bold.Sprint(publisher.String()))
if err := handle(publisher.Publish(ctx)); err != nil {
2018-10-12 00:14:06 -03:00
return errors.Wrapf(err, "%s: failed to publish artifacts", publisher.String())
2018-10-05 09:22:53 -03:00
}
}
return nil
}
2018-10-12 00:26:54 -03:00
// 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
}