Repository: goreleaser/goreleaser
Pull request #2241 (2021-05-21 20:50:17)

feat: Scoop pipe - Write the manifest before skips, like Brew pipe.
<!-- If applied, this commit will... -->

This change makes the scoop pipe write out the manifest before the skip conditions.

<!-- Why is this change being made? -->

By writing the manifest before the skip section of the pipe, you can do dry runs of the scoop pipeline. This is how the brew pipe does it.

Example behavior before change:
```
    ...
      • homebrew tap formula
         • writing                   formula=dist/app.rb
         • pipe skipped              error=brew.skip_upload is set
      • scoop manifests  
         • pipe skipped              error=scoop.skip_upload is true
    ...
```
After
``` 
    ...
      • homebrew tap formula
         • writing                   formula=dist/app.rb
         • pipe skipped              error=brew.skip_upload is set
      • scoop manifests  
         • writing                   manifest=app.json
         • pipe skipped              error=scoop.skip_upload is true
    ...
```


vercel[bot]: Someone is attempting to deploy a commit to the **Goreleaser** Team on [Vercel](https://vercel.com).

A member of the Team first needs to [authorize it](https://vercel.com/git/authorize?team=Goreleaser&type=github&job=%7B%22headInfo%22%3A%7B%22sha%22%3A%227ea5f6b4c6ea57e03a4c28e7c0517c0a134ee959%22%7D%2C%22id%22%3A%22QmU9saZyFpJqsRiWm9aZGaysMZV1bbMxAy7ctmRVxkoJKa%22%2C%22org%22%3A%22goreleaser%22%2C%22prId%22%3A2241%2C%22repo%22%3A%22goreleaser%22%7D).


caarlos0: nice! thanks for the pr!

can you add a test for it as well?
eolder: In `e5456fa` I added a test for the modification as well as a small change - the manifest is now written to dist instead of the base dir.
codecov[bot]: # [Codecov](https://codecov.io/gh/goreleaser/goreleaser/pull/2241?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser) Report
> Merging [#2241](https://codecov.io/gh/goreleaser/goreleaser/pull/2241?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser) (c295feb) into [master](https://codecov.io/gh/goreleaser/goreleaser/commit/9913fe7db6eaeb1b6649849b6e633d9e04953a9e?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser) (9913fe7) will **decrease** coverage by `0.03%`.
> The diff coverage is `66.66%`.

> :exclamation: Current head c295feb differs from pull request most recent head 7578a05. Consider uploading reports for the commit 7578a05 to get more accurate results
[![Impacted file tree graph](https://codecov.io/gh/goreleaser/goreleaser/pull/2241/graphs/tree.svg?width=650&height=150&src=pr&token=3bJvv6b7hN&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser)](https://codecov.io/gh/goreleaser/goreleaser/pull/2241?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser)

```diff
@@            Coverage Diff             @@
##           master    #2241      +/-   ##
==========================================
- Coverage   82.74%   82.71%   -0.04%     
==========================================
  Files          76       76              
  Lines        4190     4194       +4     
==========================================
+ Hits         3467     3469       +2     
- Misses        587      588       +1     
- Partials      136      137       +1     
```


| [Impacted Files](https://codecov.io/gh/goreleaser/goreleaser/pull/2241?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser) | Coverage Δ | |
|---|---|---|
| [internal/pipe/scoop/scoop.go](https://codecov.io/gh/goreleaser/goreleaser/pull/2241/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser#diff-aW50ZXJuYWwvcGlwZS9zY29vcC9zY29vcC5nbw==) | `79.52% <66.66%> (-0.97%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/goreleaser/goreleaser/pull/2241?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/goreleaser/goreleaser/pull/2241?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser). Last update [9913fe7...7578a05](https://codecov.io/gh/goreleaser/goreleaser/pull/2241?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser).


Patch:
diff --git a/internal/pipe/scoop/scoop.go b/internal/pipe/scoop/scoop.go
index 689bf383..921db7c5 100644
--- a/internal/pipe/scoop/scoop.go
+++ b/internal/pipe/scoop/scoop.go
@@ -5,6 +5,8 @@ import (
 	"bytes"
 	"encoding/json"
 	"errors"
+	"fmt"
+	"os"
 	"path/filepath"
 	"strings"
 
@@ -106,12 +108,18 @@ func doRun(ctx *context.Context, cl client.Client) error {
 		return err
 	}
 
-	if ctx.SkipPublish {
-		return pipe.ErrSkipPublishEnabled
+	filename := filepath.Join(ctx.Config.Dist, path)
+	log.WithField("manifest", filename).Info("writing")
+	if err := os.WriteFile(filename, content.Bytes(), 0o644); err != nil {
+		return fmt.Errorf("failed to write scoop manifest: %w", err)
 	}
+
 	if strings.TrimSpace(scoop.SkipUpload) == "true" {
 		return pipe.Skip("scoop.skip_upload is true")
 	}
+	if ctx.SkipPublish {
+		return pipe.ErrSkipPublishEnabled
+	}
 	if strings.TrimSpace(scoop.SkipUpload) == "auto" && ctx.Semver.Prerelease != "" {
 		return pipe.Skip("release is prerelease")
 	}


Test patch:
diff --git a/internal/pipe/scoop/scoop_test.go b/internal/pipe/scoop/scoop_test.go
index 3300b4b8..15540c0e 100644
--- a/internal/pipe/scoop/scoop_test.go
+++ b/internal/pipe/scoop/scoop_test.go
@@ -975,6 +975,60 @@ func Test_buildManifest(t *testing.T) {
 	}
 }
 
+func TestRunPipeScoopWithSkip(t *testing.T) {
+	folder := t.TempDir()
+	ctx := &context.Context{
+		Git: context.GitInfo{
+			CurrentTag: "v1.0.1",
+		},
+		Version:   "1.0.1",
+		Artifacts: artifact.New(),
+		Config: config.Project{
+			Archives: []config.Archive{
+				{Format: "tar.gz"},
+			},
+			Builds: []config.Build{
+				{Binary: "test"},
+			},
+			Dist: folder,
+			ProjectName: "run-pipe",
+			Scoop: config.Scoop{
+				Bucket: config.RepoRef{
+					Owner: "test",
+					Name:  "test",
+				},
+				Description: "A run pipe test formula",
+				Homepage:    "https://github.com/goreleaser",
+				Name: "run-pipe",
+				SkipUpload: "true",
+			},
+		},
+	}
+	path := filepath.Join(folder, "bin.tar.gz")
+	ctx.Artifacts.Add(&artifact.Artifact{
+		Name:   "bin.tar.gz",
+		Path:   path,
+		Goos:   "windows",
+		Goarch: "amd64",
+		Type:   artifact.UploadableArchive,
+		Extra: map[string]interface{}{
+			"ID":     "foo",
+			"Format": "tar.gz",
+		},
+	})
+
+	f, err := os.Create(path)
+	require.NoError(t, err)
+	require.NoError(t, f.Close())
+
+	cli := &DummyClient{}
+	require.EqualError(t, doRun(ctx, cli), `scoop.skip_upload is true`)
+
+	distFile := filepath.Join(folder, ctx.Config.Scoop.Name+".json")
+	_, err = os.Stat(distFile)
+	require.NoError(t, err, "file should exist: "+distFile)
+}
+
 func TestWrapInDirectory(t *testing.T) {
 	folder := t.TempDir()
 	file := filepath.Join(folder, "archive")