1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-02-03 13:11:48 +02:00

feat: IsDraft template variable (#3888)

allows to use `{{ .IsDraft }}` in templates.

---------

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
Carlos Alexandro Becker 2023-03-24 00:01:48 -03:00 committed by GitHub
parent f82a32cd3a
commit 44f8fae305
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 1 deletions

View File

@ -50,6 +50,7 @@ const (
patch = "Patch"
prerelease = "Prerelease"
isSnapshot = "IsSnapshot"
isDraft = "IsDraft"
env = "Env"
date = "Date"
now = "Now"
@ -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,

View File

@ -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",
@ -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"
@ -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.*\" }}",

View File

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