Skip to content

Commit

Permalink
feat: IsDraft template variable (#3888)
Browse files Browse the repository at this point in the history
allows to use `{{ .IsDraft }}` in templates.

---------

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
  • Loading branch information
caarlos0 committed Mar 24, 2023
1 parent f82a32c commit 44f8fae
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions internal/tmpl/tmpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const (
patch = "Patch"
prerelease = "Prerelease"
isSnapshot = "IsSnapshot"
isDraft = "IsDraft"
env = "Env"
date = "Date"
now = "Now"
Expand Down Expand Up @@ -106,6 +107,7 @@ func New(ctx *context.Context) *Template {
patch: ctx.Semver.Patch,
prerelease: ctx.Semver.Prerelease,
isSnapshot: ctx.Snapshot,
isDraft: ctx.Config.Release.Draft,
releaseNotes: ctx.ReleaseNotes,
releaseURL: ctx.ReleaseURL,
tagSubject: ctx.Git.TagSubject,
Expand Down
10 changes: 9 additions & 1 deletion internal/tmpl/tmpl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ import (
func TestWithArtifact(t *testing.T) {
t.Parallel()
ctx := testctx.NewWithCfg(
config.Project{ProjectName: "proj"},
config.Project{
ProjectName: "proj",
Release: config.Release{
Draft: true,
},
},
testctx.WithVersion("1.2.3"),
testctx.WithGitInfo(context.GitInfo{
PreviousTag: "v1.2.2",
Expand All @@ -36,6 +41,7 @@ func TestWithArtifact(t *testing.T) {
"MULTILINE": "something with\nmultiple lines\nremove this\nto test things",
}),
testctx.WithSemver(1, 2, 3, ""),
testctx.Snapshot,
func(ctx *context.Context) {
ctx.ModulePath = "github.com/goreleaser/goreleaser"
ctx.ReleaseNotes = "test release notes"
Expand Down Expand Up @@ -80,6 +86,8 @@ func TestWithArtifact(t *testing.T) {
"2023": `{{ .Now.Format "2006" }}`,
"2023-03-09T02:06:02Z": `{{ .Date }}`,
"1678327562": `{{ .Timestamp }}`,
"snapshot true": `snapshot {{.IsSnapshot}}`,
"draft true": `draft {{.IsDraft}}`,

"remove this": "{{ filter .Env.MULTILINE \".*remove.*\" }}",
"something with\nmultiple lines\nto test things": "{{ reverseFilter .Env.MULTILINE \".*remove.*\" }}",
Expand Down
1 change: 1 addition & 0 deletions www/docs/customization/templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Key |Description
`.Prerelease` |the prerelease part of the version, e.g. `beta`[^tag-is-semver]
`.RawVersion` |composed of `{Major}.{Minor}.{Patch}` [^tag-is-semver]
`.ReleaseNotes` |the generated release notes, available after the changelog step has been executed
`.IsDraft` |`true` if `release.draft` is set in the configuration, `false` otherwise. Since v1.17.
`.IsSnapshot` |`true` if `--snapshot` is set, `false` otherwise
`.IsNightly` |`true` if `--nightly` is set, `false` otherwise
`.Env` |a map with system's environment variables
Expand Down

0 comments on commit 44f8fae

Please sign in to comment.