github.com/goreleaser/goreleaser@v1.25.1/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/linkedin"
    12  	"github.com/goreleaser/goreleaser/internal/pipe/mastodon"
    13  	"github.com/goreleaser/goreleaser/internal/pipe/mattermost"
    14  	"github.com/goreleaser/goreleaser/internal/pipe/opencollective"
    15  	"github.com/goreleaser/goreleaser/internal/pipe/reddit"
    16  	"github.com/goreleaser/goreleaser/internal/pipe/slack"
    17  	"github.com/goreleaser/goreleaser/internal/pipe/smtp"
    18  	"github.com/goreleaser/goreleaser/internal/pipe/teams"
    19  	"github.com/goreleaser/goreleaser/internal/pipe/telegram"
    20  	"github.com/goreleaser/goreleaser/internal/pipe/twitter"
    21  	"github.com/goreleaser/goreleaser/internal/pipe/webhook"
    22  	"github.com/goreleaser/goreleaser/internal/skips"
    23  	"github.com/goreleaser/goreleaser/internal/tmpl"
    24  	"github.com/goreleaser/goreleaser/pkg/context"
    25  )
    26  
    27  // Announcer should be implemented by pipes that want to announce releases.
    28  type Announcer interface {
    29  	fmt.Stringer
    30  	Announce(ctx *context.Context) error
    31  }
    32  
    33  // nolint: gochecknoglobals
    34  var announcers = []Announcer{
    35  	// XXX: keep asc sorting
    36  	discord.Pipe{},
    37  	linkedin.Pipe{},
    38  	mastodon.Pipe{},
    39  	mattermost.Pipe{},
    40  	opencollective.Pipe{},
    41  	reddit.Pipe{},
    42  	slack.Pipe{},
    43  	smtp.Pipe{},
    44  	teams.Pipe{},
    45  	telegram.Pipe{},
    46  	twitter.Pipe{},
    47  	webhook.Pipe{},
    48  }
    49  
    50  // Pipe that announces releases.
    51  type Pipe struct{}
    52  
    53  func (Pipe) String() string { return "announcing" }
    54  
    55  func (Pipe) Skip(ctx *context.Context) (bool, error) {
    56  	if skips.Any(ctx, skips.Announce) {
    57  		return true, nil
    58  	}
    59  	return tmpl.New(ctx).Bool(ctx.Config.Announce.Skip)
    60  }
    61  
    62  // Run the pipe.
    63  func (Pipe) Run(ctx *context.Context) error {
    64  	memo := errhandler.Memo{}
    65  	for _, announcer := range announcers {
    66  		_ = skip.Maybe(
    67  			announcer,
    68  			logging.PadLog(announcer.String(), memo.Wrap(announcer.Announce)),
    69  		)(ctx)
    70  	}
    71  	if memo.Error() != nil {
    72  		return fmt.Errorf("failed to announce release: %w", memo.Error())
    73  	}
    74  	return nil
    75  }