github.com/ahmet2mir/goreleaser@v0.180.3-0.20210927151101-8e5ee5a9b8c5/internal/pipe/announce/announce.go (about)

     1  // Package announce contains the announcing pipe.
     2  package announce
     3  
     4  import (
     5  	"fmt"
     6  
     7  	"github.com/goreleaser/goreleaser/internal/middleware/errhandler"
     8  	"github.com/goreleaser/goreleaser/internal/middleware/logging"
     9  	"github.com/goreleaser/goreleaser/internal/middleware/skip"
    10  	"github.com/goreleaser/goreleaser/internal/pipe/discord"
    11  	"github.com/goreleaser/goreleaser/internal/pipe/reddit"
    12  	"github.com/goreleaser/goreleaser/internal/pipe/slack"
    13  	"github.com/goreleaser/goreleaser/internal/pipe/smtp"
    14  	"github.com/goreleaser/goreleaser/internal/pipe/teams"
    15  	"github.com/goreleaser/goreleaser/internal/pipe/twitter"
    16  	"github.com/goreleaser/goreleaser/pkg/context"
    17  )
    18  
    19  // Announcer should be implemented by pipes that want to announce releases.
    20  type Announcer interface {
    21  	fmt.Stringer
    22  
    23  	Announce(ctx *context.Context) error
    24  }
    25  
    26  // nolint: gochecknoglobals
    27  var announcers = []Announcer{
    28  	// XXX: keep asc sorting
    29  	discord.Pipe{},
    30  	reddit.Pipe{},
    31  	slack.Pipe{},
    32  	smtp.Pipe{},
    33  	teams.Pipe{},
    34  	twitter.Pipe{},
    35  }
    36  
    37  // Pipe that announces releases.
    38  type Pipe struct{}
    39  
    40  func (Pipe) String() string                 { return "announcing" }
    41  func (Pipe) Skip(ctx *context.Context) bool { return ctx.SkipAnnounce }
    42  
    43  // Run the pipe.
    44  func (Pipe) Run(ctx *context.Context) error {
    45  	for _, announcer := range announcers {
    46  		if err := skip.Maybe(
    47  			announcer,
    48  			logging.Log(
    49  				announcer.String(),
    50  				errhandler.Handle(announcer.Announce),
    51  				logging.ExtraPadding,
    52  			),
    53  		)(ctx); err != nil {
    54  			return fmt.Errorf("%s: failed to announce release: %w", announcer.String(), err)
    55  		}
    56  	}
    57  	return nil
    58  }