1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-10 03:47:03 +02:00
goreleaser/internal/pipe/blob/blob.go
Carlos Alexandro Becker 69c8a502db
chore(deps): bump github.com/golangci/golangci-lint from 1.23.7 to 1.27.0 (#1563)
* chore(deps): bump github.com/golangci/golangci-lint from 1.23.7 to 1.27.0

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* fix: tests

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>
2020-05-26 00:48:10 -03:00

61 lines
1.4 KiB
Go

// Package blob provides the pipe implementation that uploads files to "blob" providers, such as s3, gcs and azure.
package blob
import (
"fmt"
"strings"
"github.com/goreleaser/goreleaser/internal/pipe"
"github.com/goreleaser/goreleaser/internal/semerrgroup"
"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"
}
// 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 == "" {
blob.Folder = "{{ .ProjectName }}/{{ .Tag }}"
}
}
return nil
}
// Publish to specified blob bucket url.
func (Pipe) Publish(ctx *context.Context) error {
if len(ctx.Config.Blobs) == 0 {
return pipe.Skip("blobs section is not configured")
}
var g = semerrgroup.New(ctx.Parallelism)
for _, conf := range ctx.Config.Blobs {
conf := conf
g.Go(func() error {
return doUpload(ctx, conf)
})
}
return g.Wait()
}
// errorContains check if error contains specific string.
func errorContains(err error, subs ...string) bool {
for _, sub := range subs {
if strings.Contains(err.Error(), sub) {
return true
}
}
return false
}