Skip to content
Permalink
Browse files
feat: more templateable fields for blobs (#3461)
closes #3460

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
  • Loading branch information
caarlos0 committed Oct 14, 2022
1 parent 6472626 commit 9e6fb4f55cdc7485043c7e6f1bd6c37e4f819548
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 10 deletions.
@@ -4,6 +4,7 @@ import (
"fmt"
"testing"

"github.com/goreleaser/goreleaser/internal/testlib"
"github.com/goreleaser/goreleaser/pkg/config"
"github.com/goreleaser/goreleaser/pkg/context"
"github.com/stretchr/testify/require"
@@ -169,6 +170,38 @@ func TestURL(t *testing.T) {
require.NoError(t, err)
require.Equal(t, "gs://foo", url)
})

t.Run("template errors", func(t *testing.T) {
t.Run("provider", func(t *testing.T) {
_, err := urlFor(context.New(config.Project{}), config.Blob{
Provider: "{{ .Nope }}",
})
testlib.RequireTemplateError(t, err)
})
t.Run("bucket", func(t *testing.T) {
_, err := urlFor(context.New(config.Project{}), config.Blob{
Bucket: "{{ .Nope }}",
Provider: "gs",
})
testlib.RequireTemplateError(t, err)
})
t.Run("endpoint", func(t *testing.T) {
_, err := urlFor(context.New(config.Project{}), config.Blob{
Bucket: "foobar",
Endpoint: "{{.Env.NOPE}}",
Provider: "s3",
})
testlib.RequireTemplateError(t, err)
})
t.Run("region", func(t *testing.T) {
_, err := urlFor(context.New(config.Project{}), config.Blob{
Bucket: "foobar",
Region: "{{.Env.NOPE}}",
Provider: "s3",
})
testlib.RequireTemplateError(t, err)
})
})
}

func TestSkip(t *testing.T) {
@@ -35,20 +35,35 @@ func urlFor(ctx *context.Context, conf config.Blob) (string, error) {
return "", err
}

bucketURL := fmt.Sprintf("%s://%s", conf.Provider, bucket)
provider, err := tmpl.New(ctx).Apply(conf.Provider)
if err != nil {
return "", err
}

if conf.Provider != "s3" {
bucketURL := fmt.Sprintf("%s://%s", provider, bucket)
if provider != "s3" {
return bucketURL, nil
}

query := url.Values{}
if conf.Endpoint != "" {
query.Add("endpoint", conf.Endpoint)

endpoint, err := tmpl.New(ctx).Apply(conf.Endpoint)
if err != nil {
return "", err
}
if endpoint != "" {
query.Add("endpoint", endpoint)
query.Add("s3ForcePathStyle", "true")
}
if conf.Region != "" {
query.Add("region", conf.Region)

region, err := tmpl.New(ctx).Apply(conf.Region)
if err != nil {
return "", err
}
if region != "" {
query.Add("region", region)
}

if conf.DisableSSL {
query.Add("disableSSL", "true")
}
@@ -10,20 +10,27 @@ Google GCS.
blobs:
# You can have multiple blob configs
-
# Template for the cloud provider name
# s3 for AWS S3 Storage
# azblob for Azure Blob Storage
# gs for Google Cloud Storage
# Cloud provider name:
# - s3 for AWS S3 Storage
# - azblob for Azure Blob Storage
# - gs for Google Cloud Storage
#
# Templateable.
provider: azblob
# Set a custom endpoint, useful if you're using a minio backend or
# other s3-compatible backends.
#
# Implies s3ForcePathStyle and requires provider to be `s3`
#
# Templateable.
endpoint: https://minio.foo.bar
# Sets the bucket region.
# Requires provider to be `s3`
# Defaults to empty.
#
# Templateable.
region: us-west-1
# Disables SSL
@@ -32,6 +39,8 @@ blobs:
disableSSL: true
# Template for the bucket name
#
# Templateable.
bucket: goreleaser-bucket
# IDs of the artifacts you want to upload.

0 comments on commit 9e6fb4f

Please sign in to comment.