diff --git a/internal/pipeline/scoop/scoop.go b/internal/pipeline/scoop/scoop.go index 77ac7d6df..3e90849e1 100644 --- a/internal/pipeline/scoop/scoop.go +++ b/internal/pipeline/scoop/scoop.go @@ -41,6 +41,14 @@ func (Pipe) Default(ctx *context.Context) error { if ctx.Config.Scoop.CommitAuthor.Email == "" { ctx.Config.Scoop.CommitAuthor.Email = "goreleaser@carlosbecker.com" } + if ctx.Config.Scoop.URLTemplate == "" { + ctx.Config.Scoop.URLTemplate = fmt.Sprintf( + "%s/%s/%s/releases/download/{{ .Tag }}/{{ .ArtifactName }}", + ctx.Config.GitHubURLs.Download, + ctx.Config.Release.GitHub.Owner, + ctx.Config.Release.GitHub.Name, + ) + } return nil } @@ -101,8 +109,9 @@ type Resource struct { Bin string `json:"bin"` // name of binary inside the archive } -func buildManifest(ctx *context.Context, artifacts []artifact.Artifact) (result bytes.Buffer, err error) { - manifest := Manifest{ +func buildManifest(ctx *context.Context, artifacts []artifact.Artifact) (bytes.Buffer, error) { + var result bytes.Buffer + var manifest = Manifest{ Version: ctx.Version, Architecture: make(map[string]Resource), Homepage: ctx.Config.Scoop.Homepage, @@ -110,23 +119,17 @@ func buildManifest(ctx *context.Context, artifacts []artifact.Artifact) (result Description: ctx.Config.Scoop.Description, } - var url string - if ctx.Config.Scoop.URLTemplate == "" { - ctx.Config.Scoop.URLTemplate = fmt.Sprintf("%s/%s/%s/releases/download/{{ .Tag }}/{{ .ArtifactName }}", - ctx.Config.GitHubURLs.Download, - ctx.Config.Release.GitHub.Owner, - ctx.Config.Release.GitHub.Name) - } - for _, artifact := range artifacts { var arch = "64bit" if artifact.Goarch == "386" { arch = "32bit" } - url, err = tmpl.New(ctx).WithArtifact(artifact, map[string]string{}).Apply(ctx.Config.Scoop.URLTemplate) + url, err := tmpl.New(ctx). + WithArtifact(artifact, map[string]string{}). + Apply(ctx.Config.Scoop.URLTemplate) if err != nil { - return + return result, err } manifest.Architecture[arch] = Resource{ @@ -137,8 +140,8 @@ func buildManifest(ctx *context.Context, artifacts []artifact.Artifact) (result data, err := json.MarshalIndent(manifest, "", " ") if err != nil { - return + return result, err } _, err = result.Write(data) - return + return result, err } diff --git a/internal/pipeline/scoop/scoop_test.go b/internal/pipeline/scoop/scoop_test.go index 31dcca47c..ca53c29cf 100644 --- a/internal/pipeline/scoop/scoop_test.go +++ b/internal/pipeline/scoop/scoop_test.go @@ -14,6 +14,7 @@ import ( "github.com/goreleaser/goreleaser/pkg/config" "github.com/goreleaser/goreleaser/pkg/context" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) var update = flag.Bool("update", false, "update .golden files") @@ -361,10 +362,12 @@ func Test_doRun(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { + var ctx = tt.args.ctx for _, a := range tt.artifacts { - tt.args.ctx.Artifacts.Add(a) + ctx.Artifacts.Add(a) } - tt.assertError(t, doRun(tt.args.ctx, tt.args.client)) + require.NoError(t, Pipe{}.Default(ctx)) + tt.assertError(t, doRun(ctx, tt.args.client)) }) } } @@ -452,19 +455,21 @@ func Test_buildManifest(t *testing.T) { } for _, tt := range tests { - out, err := buildManifest(tt.ctx, []artifact.Artifact{ + var ctx = tt.ctx + Pipe{}.Default(ctx) + out, err := buildManifest(ctx, []artifact.Artifact{ {Name: "foo_1.0.1_windows_amd64.tar.gz", Goos: "windows", Goarch: "amd64"}, {Name: "foo_1.0.1_windows_386.tar.gz", Goos: "windows", Goarch: "386"}, }) - assert.NoError(t, err) + require.NoError(t, err) if *update { - ioutil.WriteFile(tt.filename, out.Bytes(), 0655) + require.NoError(t, ioutil.WriteFile(tt.filename, out.Bytes(), 0655)) } bts, err := ioutil.ReadFile(tt.filename) - assert.NoError(t, err) - assert.Equal(t, string(bts), out.String()) + require.NoError(t, err) + require.Equal(t, string(bts), out.String()) } }