1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-03-17 20:47:50 +02:00

feat: templateable changelog.skip (#3830)

closes #3828
This commit is contained in:
Carlos Alexandro Becker 2023-03-03 09:49:41 -03:00 committed by GitHub
parent be3a1b22d4
commit 2920de7cec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 50 additions and 12 deletions

View File

@ -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 {

View File

@ -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)
})
}

View File

@ -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"`

View File

@ -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.
#