1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-02-09 13:36:56 +02:00
Oleksandr Redko 00a376cc64
refactor: remove unneeded in Go 1.22 loop var copy (#4856)
The PR cleans up unnecessary loop variable copying and enables the
[`copyloopvar`](https://golangci-lint.run/usage/linters/#copyloopvar)
linter for detecting this redundant variable copying.

#### Additional notes

After the project upgraded to Go version 1.22 in #4779, copying
variables inside a `for` loop became unnecessary. See this [blog
post](https://go.dev/blog/loopvar-preview) for a detailed explanation.

The `copyloopvar` linter is only available from `golangci-lint` v1.57
onwards, so we also need to update this tool.
2024-05-12 13:21:13 -03:00

77 lines
2.0 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}}"
} else if blob.ContentDisposition == "-" {
blob.ContentDisposition = ""
}
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 {
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()
}