2020-05-26 00:48:10 -03:00
|
|
|
// Package blob provides the pipe implementation that uploads files to "blob" providers, such as s3, gcs and azure.
|
2019-06-05 15:51:01 +02:00
|
|
|
package blob
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2023-03-23 08:59:04 -03:00
|
|
|
"github.com/goreleaser/goreleaser/internal/pipe"
|
2019-06-05 15:51:01 +02:00
|
|
|
"github.com/goreleaser/goreleaser/internal/semerrgroup"
|
2023-03-23 08:59:04 -03:00
|
|
|
"github.com/goreleaser/goreleaser/internal/tmpl"
|
2019-06-05 15:51:01 +02:00
|
|
|
"github.com/goreleaser/goreleaser/pkg/context"
|
|
|
|
)
|
|
|
|
|
2020-05-26 00:48:10 -03:00
|
|
|
// Pipe for blobs.
|
2019-06-05 15:51:01 +02:00
|
|
|
type Pipe struct{}
|
|
|
|
|
2020-05-26 00:48:10 -03:00
|
|
|
// String returns the description of the pipe.
|
2021-09-18 10:21:29 -03:00
|
|
|
func (Pipe) String() string { return "blobs" }
|
|
|
|
func (Pipe) Skip(ctx *context.Context) bool { return len(ctx.Config.Blobs) == 0 }
|
2019-06-05 15:51:01 +02:00
|
|
|
|
2020-05-26 00:48:10 -03:00
|
|
|
// Default sets the pipe defaults.
|
2019-06-05 15:51:01 +02:00
|
|
|
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 == "" {
|
|
|
|
blob.Folder = "{{ .ProjectName }}/{{ .Tag }}"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-05-26 00:48:10 -03:00
|
|
|
// Publish to specified blob bucket url.
|
2019-06-05 15:51:01 +02:00
|
|
|
func (Pipe) Publish(ctx *context.Context) error {
|
2021-04-19 09:31:57 -03:00
|
|
|
g := semerrgroup.New(ctx.Parallelism)
|
2023-03-23 08:59:04 -03:00
|
|
|
skips := pipe.SkipMemento{}
|
2019-06-05 15:51:01 +02:00
|
|
|
for _, conf := range ctx.Config.Blobs {
|
|
|
|
conf := conf
|
|
|
|
g.Go(func() error {
|
2023-03-23 08:59:04 -03:00
|
|
|
b, err := tmpl.New(ctx).Bool(conf.Disable)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if b {
|
|
|
|
skips.Remember(pipe.Skip("configuration is disabled"))
|
|
|
|
return nil
|
|
|
|
}
|
2020-04-29 22:35:48 -03:00
|
|
|
return doUpload(ctx, conf)
|
2019-06-05 15:51:01 +02:00
|
|
|
})
|
|
|
|
}
|
2023-03-23 08:59:04 -03:00
|
|
|
if err := g.Wait(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return skips.Evaluate()
|
2019-06-05 15:51:01 +02:00
|
|
|
}
|