diff --git a/internal/pipe/changelog/changelog.go b/internal/pipe/changelog/changelog.go index ee313f477..993cab01a 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/internal/pipe/changelog/changelog_test.go b/internal/pipe/changelog/changelog_test.go index bb59db30b..270b74a5a 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) }) } diff --git a/pkg/config/config.go b/pkg/config/config.go index 694c15434..ed30a9c5b 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 ceb4ec804..c9fd9e967 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. #