1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-08 03:31:59 +02:00
goreleaser/internal/pipe/blob/blob.go
Carlos Alexandro Becker 7fc93995b8
feat: consistently use directory in property names (#4737)
It was a mess of "folder" x "directory", so changed it all to
"directory".

Closes #4732
2024-04-01 10:01:56 -03:00

74 lines
1.9 KiB
Go

// Package blob provides the pipe implementation that uploads files to "blob" providers, such as s3, gcs and azure.
package blob
import (
"fmt"
"github.com/goreleaser/goreleaser/internal/deprecate"
"github.com/goreleaser/goreleaser/internal/pipe"
"github.com/goreleaser/goreleaser/internal/semerrgroup"
"github.com/goreleaser/goreleaser/internal/tmpl"
"github.com/goreleaser/goreleaser/pkg/context"
)
// Pipe for blobs.
type Pipe struct{}
// String returns the description of the pipe.
func (Pipe) String() string { return "blobs" }
func (Pipe) Skip(ctx *context.Context) bool { return len(ctx.Config.Blobs) == 0 }
// Default sets the pipe defaults.
func (Pipe) Default(ctx *context.Context) error {
for i := range ctx.Config.Blobs {
blob := &ctx.Config.Blobs[i]
if blob.Bucket == "" || blob.Provider == "" {
return fmt.Errorf("bucket or provider cannot be empty")
}
if blob.Folder != "" {
deprecate.Notice(ctx, "blobs.folder")
blob.Directory = blob.Folder
}
if blob.Directory == "" {
blob.Directory = "{{ .ProjectName }}/{{ .Tag }}"
}
if blob.ContentDisposition == "" {
blob.ContentDisposition = "attachment;filename={{.Filename}}"
}
if blob.OldDisableSSL {
deprecate.Notice(ctx, "blobs.disableSSL")
blob.DisableSSL = true
}
if blob.OldKMSKey != "" {
deprecate.Notice(ctx, "blobs.kmskey")
blob.KMSKey = blob.OldKMSKey
}
}
return nil
}
// Publish to specified blob bucket url.
func (Pipe) Publish(ctx *context.Context) error {
g := semerrgroup.New(ctx.Parallelism)
skips := pipe.SkipMemento{}
for _, conf := range ctx.Config.Blobs {
conf := conf
g.Go(func() error {
b, err := tmpl.New(ctx).Bool(conf.Disable)
if err != nil {
return err
}
if b {
skips.Remember(pipe.Skip("configuration is disabled"))
return nil
}
return doUpload(ctx, conf)
})
}
if err := g.Wait(); err != nil {
return err
}
return skips.Evaluate()
}