github.com/windmeup/goreleaser@v1.21.95/internal/pipe/blob/blob.go (about)

     1  // Package blob provides the pipe implementation that uploads files to "blob" providers, such as s3, gcs and azure.
     2  package blob
     3  
     4  import (
     5  	"fmt"
     6  
     7  	"github.com/windmeup/goreleaser/internal/pipe"
     8  	"github.com/windmeup/goreleaser/internal/semerrgroup"
     9  	"github.com/windmeup/goreleaser/internal/tmpl"
    10  	"github.com/windmeup/goreleaser/pkg/context"
    11  )
    12  
    13  // Pipe for blobs.
    14  type Pipe struct{}
    15  
    16  // String returns the description of the pipe.
    17  func (Pipe) String() string                 { return "blobs" }
    18  func (Pipe) Skip(ctx *context.Context) bool { return len(ctx.Config.Blobs) == 0 }
    19  
    20  // Default sets the pipe defaults.
    21  func (Pipe) Default(ctx *context.Context) error {
    22  	for i := range ctx.Config.Blobs {
    23  		blob := &ctx.Config.Blobs[i]
    24  
    25  		if blob.Bucket == "" || blob.Provider == "" {
    26  			return fmt.Errorf("bucket or provider cannot be empty")
    27  		}
    28  		if blob.Folder == "" {
    29  			blob.Folder = "{{ .ProjectName }}/{{ .Tag }}"
    30  		}
    31  	}
    32  	return nil
    33  }
    34  
    35  // Publish to specified blob bucket url.
    36  func (Pipe) Publish(ctx *context.Context) error {
    37  	g := semerrgroup.New(ctx.Parallelism)
    38  	skips := pipe.SkipMemento{}
    39  	for _, conf := range ctx.Config.Blobs {
    40  		conf := conf
    41  		g.Go(func() error {
    42  			b, err := tmpl.New(ctx).Bool(conf.Disable)
    43  			if err != nil {
    44  				return err
    45  			}
    46  			if b {
    47  				skips.Remember(pipe.Skip("configuration is disabled"))
    48  				return nil
    49  			}
    50  			return doUpload(ctx, conf)
    51  		})
    52  	}
    53  	if err := g.Wait(); err != nil {
    54  		return err
    55  	}
    56  	return skips.Evaluate()
    57  }