Repository: goreleaser/goreleaser (Go)

Issue:
Make `changelog.skip` template-able
### Is your feature request related to a problem? Please describe.

I have a goreleaser setup that pushes docker images and manifest lists on tag builds AND on builds of certain branches (e.g. our `main` branch).  To do this successfully for branches, I need to disable the changelog and release configurations. But I still want to publish docker images and docker manifests.

### Describe the solution you'd like

I see that as of #3710, I can now template `release.disable` to use something like `{{ eq .Tag ""}` or `{{ .Env.DISABLE }}`.

I'd like to make `changelog.skip` template-able in the exact same way that `release.disable` is so that I can use the same template to enable/disable them together.


### Describe alternatives you've considered

Right now my workaround is to set `release.disable` and `changelog.skip` to true in my goreleaser config. But then during CI, I modify the goreleaser config file just before the `goreleaser release` call to set `release.disable` and `changelog.skip` to false when its a tag build.

### Search

- [X] I did search for other open and closed issues before opening this.

### Code of Conduct

- [X] I agree to follow this project's Code of Conduct

### Additional context

_No response_


Discussion:
Seems like this discussion is related: https://github.com/goreleaser/goreleaser/discussions/1733#discussioncomment-5183166

Though it also seems that suggestion requires a much larger change.



Patch:
diff --git a/internal/pipe/changelog/changelog.go b/internal/pipe/changelog/changelog.go
index ee313f4778f..993cab01a12 100644
--- a/internal/pipe/changelog/changelog.go
+++ b/internal/pipe/changelog/changelog.go
@@ -38,8 +38,13 @@ const (
 // Pipe for checksums.
 type Pipe struct{}
 
-func (Pipe) String() string                 { return "generating changelog" }
-func (Pipe) Skip(ctx *context.Context) bool { return ctx.Config.Changelog.Skip || ctx.Snapshot }
+func (Pipe) String() string { return "generating changelog" }
+func (Pipe) Skip(ctx *context.Context) (bool, error) {
+	if ctx.Snapshot {
+		return true, nil
+	}
+	return tmpl.New(ctx).Bool(ctx.Config.Changelog.Skip)
+}
 
 // Run the pipe.
 func (Pipe) Run(ctx *context.Context) error {
diff --git a/pkg/config/config.go b/pkg/config/config.go
index 694c154347f..ed30a9c5bb3 100644
--- a/pkg/config/config.go
+++ b/pkg/config/config.go
@@ -847,7 +847,7 @@ type Filters struct {
 type Changelog struct {
 	Filters Filters          `yaml:"filters,omitempty" json:"filters,omitempty"`
 	Sort    string           `yaml:"sort,omitempty" json:"sort,omitempty" jsonschema:"enum=asc,enum=desc,enum=,default="`
-	Skip    bool             `yaml:"skip,omitempty" json:"skip,omitempty"` // TODO(caarlos0): rename to Disable to match other pipes
+	Skip    string           `yaml:"skip,omitempty" json:"skip,omitempty" jsonschema:"oneof_type=string;boolean"` // TODO(caarlos0): rename to Disable to match other pipes
 	Use     string           `yaml:"use,omitempty" json:"use,omitempty" jsonschema:"enum=git,enum=github,enum=github-native,enum=gitlab,default=git"`
 	Groups  []ChangelogGroup `yaml:"groups,omitempty" json:"groups,omitempty"`
 	Abbrev  int              `yaml:"abbrev,omitempty" json:"abbrev,omitempty"`
diff --git a/www/docs/customization/changelog.md b/www/docs/customization/changelog.md
index ceb4ec80450..c9fd9e96755 100644
--- a/www/docs/customization/changelog.md
+++ b/www/docs/customization/changelog.md
@@ -6,10 +6,17 @@ You can customize how the changelog is generated using the `changelog` section i
 # .goreleaser.yml
 changelog:
   # Set this to true if you don't want any changelog at all.
+  #
   # Warning: this will also ignore any changelog files passed via `--release-notes`,
   # and will render an empty changelog.
+  #
   # This may result in an empty release notes on GitHub/GitLab/Gitea.
-  skip: true
+  #
+  # Templateable since v1.16.0.
+  # Must evaluate to either true or false.
+  #
+  # Defaults to false.
+  skip: '{{ .Env.CREATE_CHANGELOG }}'
 
   # Changelog generation implementation to use.
   #


Test patch:
diff --git a/internal/pipe/changelog/changelog_test.go b/internal/pipe/changelog/changelog_test.go
index bb59db30bb0..270b74a5a57 100644
--- a/internal/pipe/changelog/changelog_test.go
+++ b/internal/pipe/changelog/changelog_test.go
@@ -606,23 +606,49 @@ func TestGetChangeloger(t *testing.T) {
 }
 
 func TestSkip(t *testing.T) {
-	t.Run("skip on snapshot", func(t *testing.T) {
+	t.Run("skip", func(t *testing.T) {
 		ctx := testctx.New(testctx.Snapshot)
-		require.True(t, Pipe{}.Skip(ctx))
+		b, err := Pipe{}.Skip(ctx)
+		require.NoError(t, err)
+		require.True(t, b)
 	})
 
-	t.Run("skip", func(t *testing.T) {
+	t.Run("skip on patches", func(t *testing.T) {
 		ctx := testctx.NewWithCfg(config.Project{
 			Changelog: config.Changelog{
-				Skip: true,
+				Skip: "{{gt .Patch 0}}",
 			},
-		})
-		require.True(t, Pipe{}.Skip(ctx))
+		}, testctx.WithSemver(0, 0, 1, ""))
+		b, err := Pipe{}.Skip(ctx)
+		require.NoError(t, err)
+		require.True(t, b)
+	})
+
+	t.Run("invalid template", func(t *testing.T) {
+		ctx := testctx.NewWithCfg(config.Project{
+			Changelog: config.Changelog{
+				Skip: "{{if eq .Patch 123}",
+			},
+		}, testctx.WithSemver(0, 0, 1, ""))
+		_, err := Pipe{}.Skip(ctx)
+		require.Error(t, err)
 	})
 
 	t.Run("dont skip", func(t *testing.T) {
-		ctx := testctx.New()
-		require.False(t, Pipe{}.Skip(ctx))
+		b, err := Pipe{}.Skip(testctx.New())
+		require.NoError(t, err)
+		require.False(t, b)
+	})
+
+	t.Run("dont skip based on template", func(t *testing.T) {
+		ctx := testctx.NewWithCfg(config.Project{
+			Changelog: config.Changelog{
+				Skip: "{{gt .Patch 0}}",
+			},
+		})
+		b, err := Pipe{}.Skip(ctx)
+		require.NoError(t, err)
+		require.False(t, b)
 	})
 }