github.1git.de/goreleaser/goreleaser@v0.92.0/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  	docker.Pipe{},
    42  	snapcraft.Pipe{},
    43  	// This should be one of the last steps
    44  	release.Pipe{},
    45  	// brew and scoop use the release URL, so, they should be last
    46  	brew.Pipe{},
    47  	scoop.Pipe{},
    48  }
    49  
    50  var bold = color.New(color.Bold)
    51  
    52  // Run the pipe
    53  func (Pipe) Run(ctx *context.Context) error {
    54  	if ctx.SkipPublish {
    55  		return pipe.ErrSkipPublishEnabled
    56  	}
    57  	for _, publisher := range publishers {
    58  		log.Infof(bold.Sprint(publisher.String()))
    59  		if err := handle(publisher.Publish(ctx)); err != nil {
    60  			return errors.Wrapf(err, "%s: failed to publish artifacts", publisher.String())
    61  		}
    62  	}
    63  	return nil
    64  }
    65  
    66  // TODO: for now this is duplicated, we should have better error handling
    67  // eventually.
    68  func handle(err error) error {
    69  	if err == nil {
    70  		return nil
    71  	}
    72  	if pipe.IsSkip(err) {
    73  		log.WithField("reason", err.Error()).Warn("skipped")
    74  		return nil
    75  	}
    76  	return err
    77  }