mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-02-07 13:31:37 +02:00
feat: changelog.include (#4122)
closes https://github.com/goreleaser/goreleaser/issues/4111 refs https://github.com/orgs/goreleaser/discussions/4110 recreated #4115 --------- Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
parent
5f908bd121
commit
e5c9338efd
@ -269,7 +269,19 @@ func buildChangelog(ctx *context.Context) ([]string, error) {
|
||||
}
|
||||
|
||||
func filterEntries(ctx *context.Context, entries []string) ([]string, error) {
|
||||
for _, filter := range ctx.Config.Changelog.Filters.Exclude {
|
||||
filters := ctx.Config.Changelog.Filters
|
||||
if len(filters.Include) > 0 {
|
||||
var newEntries []string
|
||||
for _, filter := range filters.Include {
|
||||
r, err := regexp.Compile(filter)
|
||||
if err != nil {
|
||||
return entries, err
|
||||
}
|
||||
newEntries = append(newEntries, keep(r, entries)...)
|
||||
}
|
||||
return newEntries, nil
|
||||
}
|
||||
for _, filter := range filters.Exclude {
|
||||
r, err := regexp.Compile(filter)
|
||||
if err != nil {
|
||||
return entries, err
|
||||
@ -297,6 +309,15 @@ func sortEntries(ctx *context.Context, entries []string) []string {
|
||||
return result
|
||||
}
|
||||
|
||||
func keep(filter *regexp.Regexp, entries []string) (result []string) {
|
||||
for _, entry := range entries {
|
||||
if filter.MatchString(extractCommitInfo(entry)) {
|
||||
result = append(result, entry)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func remove(filter *regexp.Regexp, entries []string) (result []string) {
|
||||
for _, entry := range entries {
|
||||
if !filter.MatchString(extractCommitInfo(entry)) {
|
||||
|
@ -131,6 +131,56 @@ func TestChangelog(t *testing.T) {
|
||||
require.NotEmpty(t, string(bts))
|
||||
}
|
||||
|
||||
func TestChangelogInclude(t *testing.T) {
|
||||
folder := testlib.Mktmp(t)
|
||||
testlib.GitInit(t)
|
||||
testlib.GitCommit(t, "first")
|
||||
testlib.GitTag(t, "v0.0.1")
|
||||
testlib.GitCommit(t, "added feature 1")
|
||||
testlib.GitCommit(t, "fixed bug 2")
|
||||
testlib.GitCommit(t, "ignored: whatever")
|
||||
testlib.GitCommit(t, "docs: whatever")
|
||||
testlib.GitCommit(t, "something about cArs we dont need")
|
||||
testlib.GitCommit(t, "feat: added that thing")
|
||||
testlib.GitCommit(t, "Merge pull request #999 from goreleaser/some-branch")
|
||||
testlib.GitCommit(t, "this is not a Merge pull request")
|
||||
testlib.GitTag(t, "v0.0.2")
|
||||
ctx := testctx.NewWithCfg(config.Project{
|
||||
Dist: folder,
|
||||
Changelog: config.Changelog{
|
||||
Use: "git",
|
||||
Filters: config.Filters{
|
||||
Include: []string{
|
||||
"docs:",
|
||||
"ignored:",
|
||||
"(?i)cars",
|
||||
"^Merge pull request",
|
||||
},
|
||||
},
|
||||
},
|
||||
}, testctx.WithCurrentTag("v0.0.2"), testctx.WithPreviousTag("v0.0.1"))
|
||||
require.NoError(t, Pipe{}.Run(ctx))
|
||||
require.Contains(t, ctx.ReleaseNotes, "## Changelog")
|
||||
require.NotContains(t, ctx.ReleaseNotes, "first")
|
||||
require.NotContains(t, ctx.ReleaseNotes, "added feature 1")
|
||||
require.NotContains(t, ctx.ReleaseNotes, "fixed bug 2")
|
||||
require.Contains(t, ctx.ReleaseNotes, "docs")
|
||||
require.Contains(t, ctx.ReleaseNotes, "ignored")
|
||||
require.Contains(t, ctx.ReleaseNotes, "cArs")
|
||||
require.Contains(t, ctx.ReleaseNotes, "from goreleaser/some-branch")
|
||||
|
||||
for _, line := range strings.Split(ctx.ReleaseNotes, "\n")[1:] {
|
||||
if line == "" {
|
||||
continue
|
||||
}
|
||||
require.Truef(t, strings.HasPrefix(line, "* "), "%q: changelog commit must be a list item", line)
|
||||
}
|
||||
|
||||
bts, err := os.ReadFile(filepath.Join(folder, "CHANGELOG.md"))
|
||||
require.NoError(t, err)
|
||||
require.NotEmpty(t, string(bts))
|
||||
}
|
||||
|
||||
func TestChangelogForGitlab(t *testing.T) {
|
||||
folder := testlib.Mktmp(t)
|
||||
testlib.GitInit(t)
|
||||
@ -285,6 +335,25 @@ func TestChangelogFilterInvalidRegex(t *testing.T) {
|
||||
require.EqualError(t, Pipe{}.Run(ctx), "error parsing regexp: invalid or unsupported Perl syntax: `(?ia`")
|
||||
}
|
||||
|
||||
func TestChangelogFilterIncludeInvalidRegex(t *testing.T) {
|
||||
testlib.Mktmp(t)
|
||||
testlib.GitInit(t)
|
||||
testlib.GitCommit(t, "commitssss")
|
||||
testlib.GitTag(t, "v0.0.3")
|
||||
testlib.GitCommit(t, "commitzzz")
|
||||
testlib.GitTag(t, "v0.0.4")
|
||||
ctx := testctx.NewWithCfg(config.Project{
|
||||
Changelog: config.Changelog{
|
||||
Filters: config.Filters{
|
||||
Include: []string{
|
||||
"(?iasdr4qasd)not a valid regex i guess",
|
||||
},
|
||||
},
|
||||
},
|
||||
}, testctx.WithCurrentTag("v0.0.4"), testctx.WithPreviousTag("v0.0.3"))
|
||||
require.EqualError(t, Pipe{}.Run(ctx), "error parsing regexp: invalid or unsupported Perl syntax: `(?ia`")
|
||||
}
|
||||
|
||||
func TestChangelogNoTags(t *testing.T) {
|
||||
testlib.Mktmp(t)
|
||||
testlib.GitInit(t)
|
||||
|
@ -963,6 +963,7 @@ type DockerManifest struct {
|
||||
|
||||
// Filters config.
|
||||
type Filters struct {
|
||||
Include []string `yaml:"include,omitempty" json:"include,omitempty"`
|
||||
Exclude []string `yaml:"exclude,omitempty" json:"exclude,omitempty"`
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@ changelog:
|
||||
# This may result in an empty release notes on GitHub/GitLab/Gitea.
|
||||
#
|
||||
# Templates: allowed
|
||||
skip: '{{ .Env.CREATE_CHANGELOG }}'
|
||||
skip: "{{ .Env.CREATE_CHANGELOG }}"
|
||||
|
||||
# Changelog generation implementation to use.
|
||||
#
|
||||
@ -47,8 +47,8 @@ changelog:
|
||||
# Since: v1.12 (pro)
|
||||
# This feature is only available in GoReleaser Pro.
|
||||
paths:
|
||||
- foo/
|
||||
- bar/
|
||||
- foo/
|
||||
- bar/
|
||||
|
||||
# Group commits messages by given regex and title.
|
||||
# Order value defines the order of the groups.
|
||||
@ -60,7 +60,7 @@ changelog:
|
||||
- title: Features
|
||||
regexp: '^.*?feat(\([[:word:]]+\))??!?:.+$'
|
||||
order: 0
|
||||
- title: 'Bug fixes'
|
||||
- title: "Bug fixes"
|
||||
regexp: '^.*?bug(\([[:word:]]+\))??!?:.+$'
|
||||
order: 1
|
||||
- title: Others
|
||||
@ -81,29 +81,38 @@ changelog:
|
||||
# Since: v1.15 (pro)
|
||||
# This feature is only available in GoReleaser Pro.
|
||||
subgroups:
|
||||
- title: 'Docs'
|
||||
regex: '.*docs.*'
|
||||
- title: "Docs"
|
||||
regex: ".*docs.*"
|
||||
order: 1
|
||||
- title: 'CI'
|
||||
regex: '.*build.*'
|
||||
- title: "CI"
|
||||
regex: ".*build.*"
|
||||
order: 2
|
||||
|
||||
# Divider to use between groups.
|
||||
#
|
||||
# Since: v1.16 (pro)
|
||||
# This feature is only available in GoReleaser Pro.
|
||||
divider: '---'
|
||||
divider: "---"
|
||||
|
||||
filters:
|
||||
# Commit messages matching the regexp listed here will be removed from
|
||||
# the changelog
|
||||
exclude:
|
||||
- '^docs:'
|
||||
- "^docs:"
|
||||
- typo
|
||||
- (?i)foo
|
||||
# Commit messages matching the regexp listed here will be the only ones
|
||||
# added to the changelog
|
||||
#
|
||||
# If include is not-empty, exclude will be ignored.
|
||||
#
|
||||
# Since: v1.19
|
||||
include:
|
||||
- "^feat:"
|
||||
```
|
||||
|
||||
!!! warning
|
||||
|
||||
Some things to keep an eye on:
|
||||
|
||||
* The `github-native` changelog does not support `sort` and `filter`.
|
||||
|
Loading…
x
Reference in New Issue
Block a user