github.com/ahmet2mir/goreleaser@v0.180.3-0.20210927151101-8e5ee5a9b8c5/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  	"strings"
     7  
     8  	"github.com/goreleaser/goreleaser/internal/semerrgroup"
     9  	"github.com/goreleaser/goreleaser/pkg/context"
    10  )
    11  
    12  // Pipe for blobs.
    13  type Pipe struct{}
    14  
    15  // String returns the description of the pipe.
    16  func (Pipe) String() string                 { return "blobs" }
    17  func (Pipe) Skip(ctx *context.Context) bool { return len(ctx.Config.Blobs) == 0 }
    18  
    19  // Default sets the pipe defaults.
    20  func (Pipe) Default(ctx *context.Context) error {
    21  	for i := range ctx.Config.Blobs {
    22  		blob := &ctx.Config.Blobs[i]
    23  
    24  		if blob.Bucket == "" || blob.Provider == "" {
    25  			return fmt.Errorf("bucket or provider cannot be empty")
    26  		}
    27  		if blob.Folder == "" {
    28  			blob.Folder = "{{ .ProjectName }}/{{ .Tag }}"
    29  		}
    30  	}
    31  	return nil
    32  }
    33  
    34  // Publish to specified blob bucket url.
    35  func (Pipe) Publish(ctx *context.Context) error {
    36  	g := semerrgroup.New(ctx.Parallelism)
    37  	for _, conf := range ctx.Config.Blobs {
    38  		conf := conf
    39  		g.Go(func() error {
    40  			return doUpload(ctx, conf)
    41  		})
    42  	}
    43  	return g.Wait()
    44  }
    45  
    46  // errorContains check if error contains specific string.
    47  func errorContains(err error, subs ...string) bool {
    48  	for _, sub := range subs {
    49  		if strings.Contains(err.Error(), sub) {
    50  			return true
    51  		}
    52  	}
    53  	return false
    54  }