github.com/goreleaser/goreleaser@v1.25.1/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/goreleaser/goreleaser/internal/deprecate" 8 "github.com/goreleaser/goreleaser/internal/pipe" 9 "github.com/goreleaser/goreleaser/internal/semerrgroup" 10 "github.com/goreleaser/goreleaser/internal/tmpl" 11 "github.com/goreleaser/goreleaser/pkg/context" 12 ) 13 14 // Pipe for blobs. 15 type Pipe struct{} 16 17 // String returns the description of the pipe. 18 func (Pipe) String() string { return "blobs" } 19 func (Pipe) Skip(ctx *context.Context) bool { return len(ctx.Config.Blobs) == 0 } 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 deprecate.Notice(ctx, "blobs.folder") 31 blob.Directory = blob.Folder 32 } 33 if blob.Directory == "" { 34 blob.Directory = "{{ .ProjectName }}/{{ .Tag }}" 35 } 36 if blob.ContentDisposition == "" { 37 blob.ContentDisposition = "attachment;filename={{.Filename}}" 38 } 39 if blob.OldDisableSSL { 40 deprecate.Notice(ctx, "blobs.disableSSL") 41 blob.DisableSSL = true 42 } 43 if blob.OldKMSKey != "" { 44 deprecate.Notice(ctx, "blobs.kmskey") 45 blob.KMSKey = blob.OldKMSKey 46 } 47 } 48 return nil 49 } 50 51 // Publish to specified blob bucket url. 52 func (Pipe) Publish(ctx *context.Context) error { 53 g := semerrgroup.New(ctx.Parallelism) 54 skips := pipe.SkipMemento{} 55 for _, conf := range ctx.Config.Blobs { 56 conf := conf 57 g.Go(func() error { 58 b, err := tmpl.New(ctx).Bool(conf.Disable) 59 if err != nil { 60 return err 61 } 62 if b { 63 skips.Remember(pipe.Skip("configuration is disabled")) 64 return nil 65 } 66 return doUpload(ctx, conf) 67 }) 68 } 69 if err := g.Wait(); err != nil { 70 return err 71 } 72 return skips.Evaluate() 73 }