You've already forked goreleaser
mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-07-17 01:42:37 +02:00
feat: allow to customize release notes update behavior (#2702)
* feat: allow to customize release notes update behavior closes #1384 Signed-off-by: Carlos A Becker <caarlos0@gmail.com> * fix: make it a bit better Signed-off-by: Carlos A Becker <caarlos0@gmail.com> * fix: jsonschema Signed-off-by: Carlos A Becker <caarlos0@gmail.com>
This commit is contained in:
committed by
GitHub
parent
f659701fef
commit
b8f61718f3
@ -252,9 +252,7 @@ func (c *giteaClient) CreateRelease(ctx *context.Context, body string) (string,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if release != nil {
|
if release != nil {
|
||||||
if release.Note != "" {
|
body = getReleaseNotes(release.Note, body, ctx.Config.Release.ReleaseNotesMode)
|
||||||
body = release.Note
|
|
||||||
}
|
|
||||||
release, err = c.updateRelease(ctx, title, body, release.ID)
|
release, err = c.updateRelease(ctx, title, body, release.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -235,10 +235,7 @@ func (c *githubClient) CreateRelease(ctx *context.Context, body string) (string,
|
|||||||
data,
|
data,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
// keep the pre-existing release notes
|
data.Body = github.String(getReleaseNotes(release.GetBody(), body, ctx.Config.Release.ReleaseNotesMode))
|
||||||
if release.GetBody() != "" {
|
|
||||||
data.Body = release.Body
|
|
||||||
}
|
|
||||||
release, _, err = c.client.Repositories.EditRelease(
|
release, _, err = c.client.Repositories.EditRelease(
|
||||||
ctx,
|
ctx,
|
||||||
ctx.Config.Release.GitHub.Owner,
|
ctx.Config.Release.GitHub.Owner,
|
||||||
|
@ -310,8 +310,8 @@ func (c *gitlabClient) CreateRelease(ctx *context.Context, body string) (release
|
|||||||
log.WithField("name", release.Name).Info("release created")
|
log.WithField("name", release.Name).Info("release created")
|
||||||
} else {
|
} else {
|
||||||
desc := body
|
desc := body
|
||||||
if release != nil && release.DescriptionHTML != "" {
|
if release != nil {
|
||||||
desc = release.DescriptionHTML
|
desc = getReleaseNotes(release.DescriptionHTML, body, ctx.Config.Release.ReleaseNotesMode)
|
||||||
}
|
}
|
||||||
|
|
||||||
release, _, err = c.client.Releases.UpdateRelease(projectID, tagName, &gitlab.UpdateReleaseOptions{
|
release, _, err = c.client.Releases.UpdateRelease(projectID, tagName, &gitlab.UpdateReleaseOptions{
|
||||||
|
19
internal/client/release_notes.go
Normal file
19
internal/client/release_notes.go
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
package client
|
||||||
|
|
||||||
|
import "github.com/goreleaser/goreleaser/pkg/config"
|
||||||
|
|
||||||
|
func getReleaseNotes(existing, current string, mode config.ReleaseNotesMode) string {
|
||||||
|
switch mode {
|
||||||
|
case config.ReleaseNotesModeAppend:
|
||||||
|
return existing + "\n\n" + current
|
||||||
|
case config.ReleaseNotesModeReplace:
|
||||||
|
return current
|
||||||
|
case config.ReleaseNotesModePrepend:
|
||||||
|
return current + "\n\n" + existing
|
||||||
|
default:
|
||||||
|
if existing != "" {
|
||||||
|
return existing
|
||||||
|
}
|
||||||
|
return current
|
||||||
|
}
|
||||||
|
}
|
37
internal/client/release_notes_test.go
Normal file
37
internal/client/release_notes_test.go
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
package client
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/goreleaser/goreleaser/pkg/config"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestGetReleaseNotes(t *testing.T) {
|
||||||
|
const existing = "existing rel notes"
|
||||||
|
const current = "current rel notes"
|
||||||
|
|
||||||
|
t.Run("keep and existing empty", func(t *testing.T) {
|
||||||
|
require.Equal(t, current, getReleaseNotes("", current, config.ReleaseNotesModeKeepExisting))
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("keep", func(t *testing.T) {
|
||||||
|
require.Equal(t, existing, getReleaseNotes(existing, current, config.ReleaseNotesModeKeepExisting))
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("replace", func(t *testing.T) {
|
||||||
|
require.Equal(t, current, getReleaseNotes(existing, current, config.ReleaseNotesModeReplace))
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("append", func(t *testing.T) {
|
||||||
|
require.Equal(t, "existing rel notes\n\ncurrent rel notes", getReleaseNotes(existing, current, config.ReleaseNotesModeAppend))
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("prepend", func(t *testing.T) {
|
||||||
|
require.Equal(t, "current rel notes\n\nexisting rel notes", getReleaseNotes(existing, current, config.ReleaseNotesModePrepend))
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("invalid", func(t *testing.T) {
|
||||||
|
require.Equal(t, existing, getReleaseNotes(existing, current, config.ReleaseNotesMode("invalid")))
|
||||||
|
})
|
||||||
|
}
|
@ -450,6 +450,15 @@ type Archive struct {
|
|||||||
AllowDifferentBinaryCount bool `yaml:"allow_different_binary_count,omitempty"`
|
AllowDifferentBinaryCount bool `yaml:"allow_different_binary_count,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ReleaseNotesMode string
|
||||||
|
|
||||||
|
const (
|
||||||
|
ReleaseNotesModeKeepExisting ReleaseNotesMode = "keep-existing"
|
||||||
|
ReleaseNotesModeAppend ReleaseNotesMode = "append"
|
||||||
|
ReleaseNotesModeReplace ReleaseNotesMode = "replace"
|
||||||
|
ReleaseNotesModePrepend ReleaseNotesMode = "prepend"
|
||||||
|
)
|
||||||
|
|
||||||
// Release config used for the GitHub/GitLab release.
|
// Release config used for the GitHub/GitLab release.
|
||||||
type Release struct {
|
type Release struct {
|
||||||
GitHub Repo `yaml:"github,omitempty"`
|
GitHub Repo `yaml:"github,omitempty"`
|
||||||
@ -464,6 +473,8 @@ type Release struct {
|
|||||||
DiscussionCategoryName string `yaml:"discussion_category_name,omitempty"`
|
DiscussionCategoryName string `yaml:"discussion_category_name,omitempty"`
|
||||||
Header string `yaml:"header,omitempty"`
|
Header string `yaml:"header,omitempty"`
|
||||||
Footer string `yaml:"footer,omitempty"`
|
Footer string `yaml:"footer,omitempty"`
|
||||||
|
|
||||||
|
ReleaseNotesMode ReleaseNotesMode `yaml:"mode,omitempty" jsonschema:"title=enum=keep-existing,enum=append,enum=prepend,enum=replace,default=keep-existing"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Milestone config used for VCS milestone.
|
// Milestone config used for VCS milestone.
|
||||||
|
@ -41,6 +41,17 @@ release:
|
|||||||
# Default is false.
|
# Default is false.
|
||||||
prerelease: auto
|
prerelease: auto
|
||||||
|
|
||||||
|
# What to do with the release notes in case there the release already exists.
|
||||||
|
#
|
||||||
|
# Valid options are:
|
||||||
|
# - `keep-existing`: keep the existing notes
|
||||||
|
# - `append`: append the current release notes to the existing notes
|
||||||
|
# - `prepend`: prepend the current release notes to the existing notes
|
||||||
|
# - `replace`: replace existing notes
|
||||||
|
#
|
||||||
|
# Default is `keep-existing`.
|
||||||
|
mode: append
|
||||||
|
|
||||||
# Header template for the release body.
|
# Header template for the release body.
|
||||||
# Defaults to empty.
|
# Defaults to empty.
|
||||||
header: |
|
header: |
|
||||||
@ -82,7 +93,7 @@ release:
|
|||||||
|
|
||||||
## GitLab
|
## GitLab
|
||||||
|
|
||||||
Second, let's see what can be customized in the `release` section for GitLab.
|
Let's see what can be customized in the `release` section for GitLab.
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
# .goreleaser.yml
|
# .goreleaser.yml
|
||||||
@ -108,6 +119,17 @@ release:
|
|||||||
# Defaults to false.
|
# Defaults to false.
|
||||||
disable: true
|
disable: true
|
||||||
|
|
||||||
|
# What to do with the release notes in case there the release already exists.
|
||||||
|
#
|
||||||
|
# Valid options are:
|
||||||
|
# - `keep-existing`: keep the existing notes
|
||||||
|
# - `append`: append the current release notes to the existing notes
|
||||||
|
# - `prepend`: prepend the current release notes to the existing notes
|
||||||
|
# - `replace`: replace existing notes
|
||||||
|
#
|
||||||
|
# Default is `keep-existing`.
|
||||||
|
mode: append
|
||||||
|
|
||||||
# You can add extra pre-existing files to the release.
|
# You can add extra pre-existing files to the release.
|
||||||
# The filename on the release will be the last part of the path (base).
|
# The filename on the release will be the last part of the path (base).
|
||||||
# If another file with the same name exists, the last one found will be used.
|
# If another file with the same name exists, the last one found will be used.
|
||||||
@ -157,6 +179,17 @@ release:
|
|||||||
# Defaults to false.
|
# Defaults to false.
|
||||||
disable: true
|
disable: true
|
||||||
|
|
||||||
|
# What to do with the release notes in case there the release already exists.
|
||||||
|
#
|
||||||
|
# Valid options are:
|
||||||
|
# - `keep-existing`: keep the existing notes
|
||||||
|
# - `append`: append the current release notes to the existing notes
|
||||||
|
# - `prepend`: prepend the current release notes to the existing notes
|
||||||
|
# - `replace`: replace existing notes
|
||||||
|
#
|
||||||
|
# Default is `keep-existing`.
|
||||||
|
mode: append
|
||||||
|
|
||||||
# You can add extra pre-existing files to the release.
|
# You can add extra pre-existing files to the release.
|
||||||
# The filename on the release will be the last part of the path (base).
|
# The filename on the release will be the last part of the path (base).
|
||||||
# If another file with the same name exists, the last one found will be used.
|
# If another file with the same name exists, the last one found will be used.
|
||||||
|
9
www/docs/static/schema.json
generated
vendored
9
www/docs/static/schema.json
generated
vendored
@ -1718,6 +1718,15 @@
|
|||||||
},
|
},
|
||||||
"footer": {
|
"footer": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
|
},
|
||||||
|
"mode": {
|
||||||
|
"enum": [
|
||||||
|
"append",
|
||||||
|
"prepend",
|
||||||
|
"replace"
|
||||||
|
],
|
||||||
|
"type": "string",
|
||||||
|
"default": "keep-existing"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"additionalProperties": false,
|
"additionalProperties": false,
|
||||||
|
Reference in New Issue
Block a user