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