Repository: goreleaser/goreleaser
Pull request #2249 (2021-05-25 03:35:46)

feat: --skip-announce
adds --skip-announce flag and also skips announcing on --skip-publish and --snapshot

refs #2248


vercel[bot]: This pull request is being automatically deployed with Vercel ([learn more](https://vercel.link/github-learn-more)).  
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: [https://vercel.com/goreleaser/goreleaser/Ctd39shEztGKDPT9BsoFDKVJGKtk](https://vercel.com/goreleaser/goreleaser/Ctd39shEztGKDPT9BsoFDKVJGKtk)  
✅ Preview: [https://goreleaser-git-skip-announce-goreleaser.vercel.app](https://goreleaser-git-skip-announce-goreleaser.vercel.app)


codecov[bot]: # [Codecov](https://codecov.io/gh/goreleaser/goreleaser/pull/2249?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser) Report
> Merging [#2249](https://codecov.io/gh/goreleaser/goreleaser/pull/2249?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser) (cdcae15) into [master](https://codecov.io/gh/goreleaser/goreleaser/commit/a5ae82ae9541704ed2903050bc565d109b27d300?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser) (a5ae82a) will **increase** coverage by `0.01%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/goreleaser/goreleaser/pull/2249/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/2249?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser)

```diff
@@            Coverage Diff             @@
##           master    #2249      +/-   ##
==========================================
+ Coverage   82.63%   82.64%   +0.01%     
==========================================
  Files          78       78              
  Lines        4226     4230       +4     
==========================================
+ Hits         3492     3496       +4     
  Misses        596      596              
  Partials      138      138              
```


| [Impacted Files](https://codecov.io/gh/goreleaser/goreleaser/pull/2249?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser) | Coverage Δ | |
|---|---|---|
| [internal/pipe/pipe.go](https://codecov.io/gh/goreleaser/goreleaser/pull/2249/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser#diff-aW50ZXJuYWwvcGlwZS9waXBlLmdv) | `100.00% <ø> (ø)` | |
| [pkg/context/context.go](https://codecov.io/gh/goreleaser/goreleaser/pull/2249/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser#diff-cGtnL2NvbnRleHQvY29udGV4dC5nbw==) | `100.00% <ø> (ø)` | |
| [cmd/release.go](https://codecov.io/gh/goreleaser/goreleaser/pull/2249/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser#diff-Y21kL3JlbGVhc2UuZ28=) | `100.00% <100.00%> (ø)` | |
| [internal/pipe/twitter/twitter.go](https://codecov.io/gh/goreleaser/goreleaser/pull/2249/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser#diff-aW50ZXJuYWwvcGlwZS90d2l0dGVyL3R3aXR0ZXIuZ28=) | `66.66% <100.00%> (+3.50%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/goreleaser/goreleaser/pull/2249?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/2249?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser). Last update [a5ae82a...cdcae15](https://codecov.io/gh/goreleaser/goreleaser/pull/2249?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/cmd/release.go b/cmd/release.go
index 34ddbc41..ea2576d0 100644
--- a/cmd/release.go
+++ b/cmd/release.go
@@ -30,6 +30,7 @@ type releaseOpts struct {
 	skipPublish       bool
 	skipSign          bool
 	skipValidate      bool
+	skipAnnounce      bool
 	rmDist            bool
 	deprecated        bool
 	parallelism       int
@@ -72,8 +73,9 @@ func newReleaseCmd() *releaseCmd {
 	cmd.Flags().StringVar(&root.opts.releaseNotesTmpl, "release-notes-tmpl", "", "Load custom release notes from a templated markdown file (overrides --release-notes)")
 	cmd.Flags().StringVar(&root.opts.releaseHeaderTmpl, "release-header-tmpl", "", "Load custom release notes header from a templated markdown file (overrides --release-header)")
 	cmd.Flags().StringVar(&root.opts.releaseFooterTmpl, "release-footer-tmpl", "", "Load custom release notes footer from a templated markdown file (overrides --release-footer)")
-	cmd.Flags().BoolVar(&root.opts.snapshot, "snapshot", false, "Generate an unversioned snapshot release, skipping all validations and without publishing any artifacts")
+	cmd.Flags().BoolVar(&root.opts.snapshot, "snapshot", false, "Generate an unversioned snapshot release, skipping all validations and without publishing any artifacts (implies --skip-publish, --skip-announce and --skip-validate)")
 	cmd.Flags().BoolVar(&root.opts.skipPublish, "skip-publish", false, "Skips publishing artifacts")
+	cmd.Flags().BoolVar(&root.opts.skipAnnounce, "skip-announce", false, "Skips announcing releases (implies --skip-validate)")
 	cmd.Flags().BoolVar(&root.opts.skipSign, "skip-sign", false, "Skips signing the artifacts")
 	cmd.Flags().BoolVar(&root.opts.skipValidate, "skip-validate", false, "Skips several sanity checks")
 	cmd.Flags().BoolVar(&root.opts.rmDist, "rm-dist", false, "Remove the dist folder before building")
@@ -122,6 +124,7 @@ func setupReleaseContext(ctx *context.Context, options releaseOpts) *context.Con
 	ctx.ReleaseFooterTmpl = options.releaseFooterTmpl
 	ctx.Snapshot = options.snapshot
 	ctx.SkipPublish = ctx.Snapshot || options.skipPublish
+	ctx.SkipAnnounce = ctx.Snapshot || options.skipPublish || options.skipAnnounce
 	ctx.SkipValidate = ctx.Snapshot || options.skipValidate
 	ctx.SkipSign = options.skipSign
 	ctx.RmDist = options.rmDist
diff --git a/internal/pipe/pipe.go b/internal/pipe/pipe.go
index 9ec1180e..4001a0e2 100644
--- a/internal/pipe/pipe.go
+++ b/internal/pipe/pipe.go
@@ -14,6 +14,9 @@ var ErrSnapshotEnabled = Skip("disabled during snapshot mode")
 // It means that the part of a Piper that publishes its artifacts was not run.
 var ErrSkipPublishEnabled = Skip("publishing is disabled")
 
+// ErrSkipAnnounceEnabled happens if --skip-announce is set.
+var ErrSkipAnnounceEnabled = Skip("announcing is disabled")
+
 // ErrSkipSignEnabled happens if --skip-sign is set.
 // It means that the part of a Piper that signs some things was not run.
 var ErrSkipSignEnabled = Skip("artifact signing is disabled")
diff --git a/internal/pipe/twitter/twitter.go b/internal/pipe/twitter/twitter.go
index 575683f7..523dcf29 100644
--- a/internal/pipe/twitter/twitter.go
+++ b/internal/pipe/twitter/twitter.go
@@ -33,6 +33,9 @@ func (Pipe) Default(ctx *context.Context) error {
 }
 
 func (Pipe) Announce(ctx *context.Context) error {
+	if ctx.SkipAnnounce {
+		return pipe.ErrSkipAnnounceEnabled
+	}
 	if !ctx.Config.Announce.Twitter.Enabled {
 		return pipe.ErrSkipDisabledPipe
 	}
diff --git a/pkg/context/context.go b/pkg/context/context.go
index 29f34f94..aeb0799a 100644
--- a/pkg/context/context.go
+++ b/pkg/context/context.go
@@ -84,6 +84,7 @@ type Context struct {
 	Snapshot           bool
 	SkipPostBuildHooks bool
 	SkipPublish        bool
+	SkipAnnounce       bool
 	SkipSign           bool
 	SkipValidate       bool
 	RmDist             bool
diff --git a/www/docs/cmd/goreleaser_release.md b/www/docs/cmd/goreleaser_release.md
index 38faec81..5692df6c 100644
--- a/www/docs/cmd/goreleaser_release.md
+++ b/www/docs/cmd/goreleaser_release.md
@@ -19,10 +19,11 @@ goreleaser release [flags]
       --release-notes string         Load custom release notes from a markdown file
       --release-notes-tmpl string    Load custom release notes from a templated markdown file (overrides --release-notes)
       --rm-dist                      Remove the dist folder before building
+      --skip-announce                Skips announcing releases (implies --skip-validate)
       --skip-publish                 Skips publishing artifacts
       --skip-sign                    Skips signing the artifacts
       --skip-validate                Skips several sanity checks
-      --snapshot                     Generate an unversioned snapshot release, skipping all validations and without publishing any artifacts
+      --snapshot                     Generate an unversioned snapshot release, skipping all validations and without publishing any artifacts (implies --skip-publish, --skip-announce and --skip-validate)
       --timeout duration             Timeout to the entire release process (default 30m0s)
 ```
 


Test patch:
diff --git a/cmd/release_test.go b/cmd/release_test.go
index bcf19ec1..c8e3cfb2 100644
--- a/cmd/release_test.go
+++ b/cmd/release_test.go
@@ -42,7 +42,8 @@ func TestReleaseFlags(t *testing.T) {
 		})
 		require.True(t, ctx.Snapshot)
 		require.True(t, ctx.SkipPublish)
-		require.True(t, ctx.SkipPublish)
+		require.True(t, ctx.SkipValidate)
+		require.True(t, ctx.SkipAnnounce)
 	})
 
 	t.Run("skips", func(t *testing.T) {
@@ -53,7 +54,8 @@ func TestReleaseFlags(t *testing.T) {
 		})
 		require.True(t, ctx.SkipSign)
 		require.True(t, ctx.SkipPublish)
-		require.True(t, ctx.SkipPublish)
+		require.True(t, ctx.SkipValidate)
+		require.True(t, ctx.SkipAnnounce)
 	})
 
 	t.Run("parallelism", func(t *testing.T) {
diff --git a/internal/pipe/twitter/twitter_test.go b/internal/pipe/twitter/twitter_test.go
index 903577a5..f1db1ec8 100644
--- a/internal/pipe/twitter/twitter_test.go
+++ b/internal/pipe/twitter/twitter_test.go
@@ -48,3 +48,15 @@ func TestAnnounceMissingEnv(t *testing.T) {
 	require.NoError(t, Pipe{}.Default(ctx))
 	require.EqualError(t, Pipe{}.Announce(ctx), `announce: failed to announce to twitter: env: environment variable "TWITTER_CONSUMER_KEY" should not be empty`)
 }
+
+func TestAnnounceSkipAnnounce(t *testing.T) {
+	ctx := context.New(config.Project{
+		Announce: config.Announce{
+			Twitter: config.Twitter{
+				Enabled: true,
+			},
+		},
+	})
+	ctx.SkipAnnounce = true
+	testlib.AssertSkipped(t, Pipe{}.Announce(ctx))
+}