From 16fe0ea3bf87060259e08ca77e790aee789425e2 Mon Sep 17 00:00:00 2001 From: Nate Smith Date: Wed, 5 Feb 2020 19:05:43 -0600 Subject: [PATCH] feat: add ability to skip prereleases for scoop pipeline (#1332) --- internal/pipe/scoop/scoop.go | 9 +++ internal/pipe/scoop/scoop_test.go | 94 +++++++++++++++++++++++++++++++ pkg/config/config.go | 1 + 3 files changed, 104 insertions(+) diff --git a/internal/pipe/scoop/scoop.go b/internal/pipe/scoop/scoop.go index a512627e8..51209a64d 100644 --- a/internal/pipe/scoop/scoop.go +++ b/internal/pipe/scoop/scoop.go @@ -6,6 +6,7 @@ import ( "encoding/json" "errors" "fmt" + "strings" "github.com/goreleaser/goreleaser/internal/artifact" "github.com/goreleaser/goreleaser/internal/client" @@ -85,6 +86,14 @@ func doRun(ctx *context.Context, client client.Client) error { if ctx.SkipPublish { return pipe.ErrSkipPublishEnabled + + } + if strings.TrimSpace(ctx.Config.Scoop.SkipUpload) == "true" { + return pipe.Skip("scoop.skip_upload is true") + } else if strings.TrimSpace(ctx.Config.Scoop.SkipUpload) == "auto" { + if ctx.Semver.Prerelease != "" { + return pipe.Skip("release is prerelease") + } } if ctx.Config.Release.Draft { return pipe.Skip("release is marked as draft") diff --git a/internal/pipe/scoop/scoop_test.go b/internal/pipe/scoop/scoop_test.go index f6b31f6f7..e6e93f9bd 100644 --- a/internal/pipe/scoop/scoop_test.go +++ b/internal/pipe/scoop/scoop_test.go @@ -495,6 +495,100 @@ func Test_doRun(t *testing.T) { }, shouldErr("release is marked as draft"), }, + { + "is prerelease and skip upload set to auto", + args{ + &context.Context{ + TokenType: context.TokenTypeGitHub, + Git: context.GitInfo{ + CurrentTag: "v1.0.1-pre.1", + }, + Semver: context.Semver{ + Major: 1, + Minor: 0, + Patch: 1, + Prerelease: "-pre.1", + }, + Version: "1.0.1-pre.1", + Artifacts: artifact.New(), + Config: config.Project{ + Builds: []config.Build{ + {Binary: "test", Goarch: []string{"amd64"}, Goos: []string{"windows"}}, + }, + Dist: ".", + ProjectName: "run-pipe", + Archives: []config.Archive{ + {Format: "tar.gz"}, + }, + Release: config.Release{ + GitHub: config.Repo{ + Owner: "test", + Name: "test", + }, + }, + Scoop: config.Scoop{ + SkipUpload: "auto", + Bucket: config.Repo{ + Owner: "test", + Name: "test", + }, + Description: "A run pipe test formula", + Homepage: "https://github.com/goreleaser", + }, + }, + }, + &DummyClient{}, + }, + []*artifact.Artifact{ + {Name: "foo_1.0.1-pre.1_windows_amd64.tar.gz", Goos: "windows", Goarch: "amd64", Path: file}, + {Name: "foo_1.0.1-pre.1_windows_386.tar.gz", Goos: "windows", Goarch: "386", Path: file}, + }, + shouldErr("release is prerelease"), + }, + { + "skip upload set to true", + args{ + &context.Context{ + TokenType: context.TokenTypeGitHub, + Git: context.GitInfo{ + CurrentTag: "v1.0.1", + }, + Version: "1.0.1", + Artifacts: artifact.New(), + Config: config.Project{ + Builds: []config.Build{ + {Binary: "test", Goarch: []string{"amd64"}, Goos: []string{"windows"}}, + }, + Dist: ".", + ProjectName: "run-pipe", + Archives: []config.Archive{ + {Format: "tar.gz"}, + }, + Release: config.Release{ + GitHub: config.Repo{ + Owner: "test", + Name: "test", + }, + }, + Scoop: config.Scoop{ + SkipUpload: "true", + Bucket: config.Repo{ + Owner: "test", + Name: "test", + }, + Description: "A run pipe test formula", + Homepage: "https://github.com/goreleaser", + }, + }, + }, + &DummyClient{}, + }, + []*artifact.Artifact{ + {Name: "foo_1.0.1-pre.1_windows_amd64.tar.gz", Goos: "windows", Goarch: "amd64", Path: file}, + {Name: "foo_1.0.1-pre.1_windows_386.tar.gz", Goos: "windows", Goarch: "386", Path: file}, + }, + shouldErr("scoop.skip_upload is true"), + }, { "release is disabled", args{ diff --git a/pkg/config/config.go b/pkg/config/config.go index 658d8f2e4..e714c5ffc 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -81,6 +81,7 @@ type Scoop struct { License string `yaml:",omitempty"` URLTemplate string `yaml:"url_template,omitempty"` Persist []string `yaml:"persist,omitempty"` + SkipUpload string `yaml:"skip_upload,omitempty"` } // CommitAuthor is the author of a Git commit