From e64b2cd8dab265fbf880988e54de2ed8afa8ea88 Mon Sep 17 00:00:00 2001 From: Patrick Hahn Date: Thu, 7 Oct 2021 19:19:19 +0200 Subject: [PATCH] feat: Allow release notes to be used in template strings (#2566) When using the announce feature, you might want to inform your users about the features and changes that this release brings. This change allows you to use {{ .ReleaseNotes }} in any template string, after the changelog pipeline step has been executed. --- internal/tmpl/tmpl.go | 2 ++ internal/tmpl/tmpl_test.go | 2 ++ www/docs/customization/templates.md | 1 + 3 files changed, 5 insertions(+) diff --git a/internal/tmpl/tmpl.go b/internal/tmpl/tmpl.go index b51cab506..d29eaa243 100644 --- a/internal/tmpl/tmpl.go +++ b/internal/tmpl/tmpl.go @@ -46,6 +46,7 @@ const ( date = "Date" timestamp = "Timestamp" modulePath = "ModulePath" + releaseNotes = "ReleaseNotes" // artifact-only keys. osKey = "Os" @@ -90,6 +91,7 @@ func New(ctx *context.Context) *Template { patch: ctx.Semver.Patch, prerelease: ctx.Semver.Prerelease, isSnapshot: ctx.Snapshot, + releaseNotes: ctx.ReleaseNotes, }, } } diff --git a/internal/tmpl/tmpl_test.go b/internal/tmpl/tmpl_test.go index 954cc21cc..21c48f6dd 100644 --- a/internal/tmpl/tmpl_test.go +++ b/internal/tmpl/tmpl_test.go @@ -32,6 +32,7 @@ func TestWithArtifact(t *testing.T) { ctx.Git.Commit = "commit" ctx.Git.FullCommit = "fullcommit" ctx.Git.ShortCommit = "shortcommit" + ctx.ReleaseNotes = "test release notes" for expect, tmpl := range map[string]string{ "bar": "{{.Env.FOO}}", "Linux": "{{.Os}}", @@ -54,6 +55,7 @@ func TestWithArtifact(t *testing.T) { "1.3.0": "{{.Version | incminor }}", "v1.2.4": "{{.Tag | incpatch }}", "1.2.4": "{{.Version | incpatch }}", + "test release notes": "{{ .ReleaseNotes }}", } { tmpl := tmpl expect := expect diff --git a/www/docs/customization/templates.md b/www/docs/customization/templates.md index 1c1a58cc5..1b8a735ac 100644 --- a/www/docs/customization/templates.md +++ b/www/docs/customization/templates.md @@ -28,6 +28,7 @@ On fields that support templating, these fields are always available: | `.Patch` | the patch part of the version (assuming `Tag` is a valid semver, else `0`) | | `.Prerelease` | the prerelease part of the version, e.g. `beta` (assuming `Tag` is a valid semver) | | `.RawVersion` | Major.Minor.Patch (assuming `Tag` is a valid semver, else `0.0.0`) | +| `.ReleaseNotes` | the generated release notes, available after the changelog step has been executed | | `.IsSnapshot` | `true` if `--snapshot` is set, `false` otherwise | | `.IsNightly` | `true` if `--nightly` is set, `false` otherwise | | `.Env` | a map with system's environment variables |