diff --git a/internal/pipe/blob/blob.go b/internal/pipe/blob/blob.go index 2532e68bb..2646ebef9 100644 --- a/internal/pipe/blob/blob.go +++ b/internal/pipe/blob/blob.go @@ -4,7 +4,9 @@ package blob import ( "fmt" + "github.com/goreleaser/goreleaser/internal/pipe" "github.com/goreleaser/goreleaser/internal/semerrgroup" + "github.com/goreleaser/goreleaser/internal/tmpl" "github.com/goreleaser/goreleaser/pkg/context" ) @@ -33,11 +35,23 @@ func (Pipe) Default(ctx *context.Context) error { // 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) }) } - return g.Wait() + if err := g.Wait(); err != nil { + return err + } + return skips.Evaluate() } diff --git a/internal/pipe/blob/blob_minio_test.go b/internal/pipe/blob/blob_minio_test.go index ce26e7102..c0d3e1fbb 100644 --- a/internal/pipe/blob/blob_minio_test.go +++ b/internal/pipe/blob/blob_minio_test.go @@ -263,6 +263,95 @@ func TestMinioUploadInvalidCustomBucketID(t *testing.T) { require.Error(t, Pipe{}.Publish(ctx)) } +func TestMinioUploadSkip(t *testing.T) { + name := "basic" + folder := t.TempDir() + debpath := filepath.Join(folder, "bin.deb") + tgzpath := filepath.Join(folder, "bin.tar.gz") + require.NoError(t, os.WriteFile(tgzpath, []byte("fake\ntargz"), 0o744)) + require.NoError(t, os.WriteFile(debpath, []byte("fake\ndeb"), 0o744)) + + buildCtx := func(uploadID string) *context.Context { + ctx := testctx.NewWithCfg( + config.Project{ + Dist: folder, + ProjectName: "testupload", + Blobs: []config.Blob{ + { + Provider: "s3", + Bucket: name, + Region: "us-east", + Endpoint: "http://" + listen, + IDs: []string{"foo"}, + Disable: `{{ eq .Env.UPLOAD_ID "foo" }}`, + }, + { + Provider: "s3", + Bucket: name, + Region: "us-east", + Endpoint: "http://" + listen, + Disable: `{{ eq .Env.UPLOAD_ID "bar" }}`, + IDs: []string{"bar"}, + }, + }, + }, + testctx.WithCurrentTag("v1.0.0"), + testctx.WithEnv(map[string]string{ + "UPLOAD_ID": uploadID, + }), + ) + ctx.Artifacts.Add(&artifact.Artifact{ + Type: artifact.UploadableArchive, + Name: "bin.tar.gz", + Path: tgzpath, + Extra: map[string]interface{}{ + artifact.ExtraID: "foo", + }, + }) + ctx.Artifacts.Add(&artifact.Artifact{ + Type: artifact.LinuxPackage, + Name: "bin.deb", + Path: debpath, + Extra: map[string]interface{}{ + artifact.ExtraID: "bar", + }, + }) + return ctx + } + + setupBucket(t, testlib.MustDockerPool(t), name) + + t.Run("upload only foo", func(t *testing.T) { + ctx := buildCtx("foo") + require.NoError(t, Pipe{}.Default(ctx)) + testlib.AssertSkipped(t, Pipe{}.Publish(ctx)) + require.Subset(t, getFiles(t, ctx, ctx.Config.Blobs[0]), []string{ + "testupload/v1.0.0/bin.deb", + }) + }) + + t.Run("upload only bar", func(t *testing.T) { + ctx := buildCtx("bar") + require.NoError(t, Pipe{}.Default(ctx)) + testlib.AssertSkipped(t, Pipe{}.Publish(ctx)) + require.Subset(t, getFiles(t, ctx, ctx.Config.Blobs[0]), []string{ + "testupload/v1.0.0/bin.tar.gz", + }) + }) + + t.Run("invalid tmpl", func(t *testing.T) { + ctx := buildCtx("none") + ctx.Config.Blobs = []config.Blob{{ + Provider: "s3", + Bucket: name, + Endpoint: "http://" + listen, + Disable: `{{ .Env.NOME }}`, + }} + require.NoError(t, Pipe{}.Default(ctx)) + testlib.RequireTemplateError(t, Pipe{}.Publish(ctx)) + }) +} + func prepareEnv() { os.Setenv("AWS_ACCESS_KEY_ID", minioUser) os.Setenv("AWS_SECRET_ACCESS_KEY", minioPwd) diff --git a/pkg/config/config.go b/pkg/config/config.go index 61594305a..ae496870b 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -889,6 +889,7 @@ type Blob struct { IDs []string `yaml:"ids,omitempty" json:"ids,omitempty"` Endpoint string `yaml:"endpoint,omitempty" json:"endpoint,omitempty"` // used for minio for example ExtraFiles []ExtraFile `yaml:"extra_files,omitempty" json:"extra_files,omitempty"` + Disable string `yaml:"disable,omitempty" json:"disable,omitempty" jsonschema:"oneof_type=string;boolean"` } // Upload configuration. diff --git a/www/docs/customization/blob.md b/www/docs/customization/blob.md index 355d93b82..03a73d5ba 100644 --- a/www/docs/customization/blob.md +++ b/www/docs/customization/blob.md @@ -52,6 +52,12 @@ blobs: # Default is `{{ .ProjectName }}/{{ .Tag }}` folder: "foo/bar/{{.Version}}" + # Template to disable this particular upload configuration. + # + # Since: v1.17 + # Default: false + disable: '{{ neq .BLOB_UPLOAD_ONLY "foo" }}' + # You can add extra pre-existing files to the bucket. # The filename on the release will be the last part of the path (base). # If another file with the same name exists, the last one found will be used. diff --git a/www/docs/static/schema.json b/www/docs/static/schema.json index b985aa40b..aece1cc84 100644 --- a/www/docs/static/schema.json +++ b/www/docs/static/schema.json @@ -270,6 +270,16 @@ "$ref": "#/$defs/ExtraFile" }, "type": "array" + }, + "disable": { + "oneOf": [ + { + "type": "string" + }, + { + "type": "boolean" + } + ] } }, "additionalProperties": false,