From 82493e2928dabcb4abd7d86acfbf6e7ca2543d39 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Fri, 27 Jul 2018 17:17:15 -0300 Subject: [PATCH] fix: s3: honor skip upload (#738) refs https://github.com/goreleaser/goreleaser/issues/737 --- pipeline/s3/s3.go | 4 ++++ pipeline/s3/s3_test.go | 30 ++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/pipeline/s3/s3.go b/pipeline/s3/s3.go index 1e94a271a..0d532e084 100644 --- a/pipeline/s3/s3.go +++ b/pipeline/s3/s3.go @@ -15,6 +15,7 @@ import ( "github.com/goreleaser/goreleaser/internal/artifact" "github.com/goreleaser/goreleaser/internal/semerrgroup" "github.com/goreleaser/goreleaser/internal/tmpl" + "github.com/goreleaser/goreleaser/pipeline" ) // Pipe for Artifactory @@ -47,6 +48,9 @@ func (Pipe) Default(ctx *context.Context) error { // Run the pipe func (Pipe) Run(ctx *context.Context) error { + if ctx.SkipPublish { + return pipeline.ErrSkipPublishEnabled + } var g = semerrgroup.New(ctx.Parallelism) for _, conf := range ctx.Config.S3 { conf := conf diff --git a/pipeline/s3/s3_test.go b/pipeline/s3/s3_test.go index fadb40fdf..13473ccdf 100644 --- a/pipeline/s3/s3_test.go +++ b/pipeline/s3/s3_test.go @@ -13,7 +13,9 @@ import ( "github.com/goreleaser/goreleaser/config" "github.com/goreleaser/goreleaser/context" "github.com/goreleaser/goreleaser/internal/artifact" + "github.com/goreleaser/goreleaser/pipeline" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestDescription(t *testing.T) { @@ -53,6 +55,34 @@ func TestDefaults(t *testing.T) { }}, ctx.Config.S3) } +func TestSkipPublish(t *testing.T) { + folder, err := ioutil.TempDir("", "goreleasertest") + require.NoError(t, err) + artifactPath := filepath.Join(folder, "foo.tar.gz") + require.NoError(t, ioutil.WriteFile(artifactPath, []byte("fake\ntargz"), 0744)) + var ctx = context.New(config.Project{ + Dist: folder, + ProjectName: "testupload", + S3: []config.S3{ + { + Bucket: "test", + Endpoint: "http://fake.s3.example", + }, + }, + }) + ctx.Git = context.GitInfo{CurrentTag: "v1.0.0"} + ctx.Artifacts.Add(artifact.Artifact{ + Type: artifact.UploadableArchive, + Name: "foo.tar.gz", + Path: artifactPath, + }) + ctx.SkipPublish = true + require.NoError(t, Pipe{}.Default(ctx)) + err = Pipe{}.Run(ctx) + assert.True(t, pipeline.IsSkip(err)) + assert.EqualError(t, err, pipeline.ErrSkipPublishEnabled.Error()) +} + func TestUpload(t *testing.T) { folder, err := ioutil.TempDir("", "goreleasertest") assert.NoError(t, err)