mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-03-17 20:47:50 +02:00
feat: blobs.disable (#3884)
Allows to template-disable specific blob configurations. Closes #3883
This commit is contained in:
parent
7229a0dab0
commit
f82a32cd3a
@ -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()
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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.
|
||||
|
@ -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.
|
||||
|
10
www/docs/static/schema.json
generated
vendored
10
www/docs/static/schema.json
generated
vendored
@ -270,6 +270,16 @@
|
||||
"$ref": "#/$defs/ExtraFile"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
"disable": {
|
||||
"oneOf": [
|
||||
{
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"type": "boolean"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
|
Loading…
x
Reference in New Issue
Block a user