Repository: goreleaser/goreleaser
Pull request #2872 (2022-02-02 18:30:58)

feat: template nfpms.maintainer
allows to template `nfpms[*].maintainer` field.


Patch:
diff --git a/internal/deprecate/deprecate.go b/internal/deprecate/deprecate.go
index 09479760..5f5b815a 100644
--- a/internal/deprecate/deprecate.go
+++ b/internal/deprecate/deprecate.go
@@ -43,10 +43,14 @@ func Notice(ctx *context.Context, property string) {
 // NoticeCustom warns the user about the deprecation of the given property.
 func NoticeCustom(ctx *context.Context, property, tmpl string) {
 	ctx.Deprecated = true
-	cli.Default.Padding += 3
-	defer func() {
-		cli.Default.Padding -= 3
-	}()
+	// XXX: this is very ugly!
+	w := log.Log.(*log.Logger).Handler.(*cli.Handler).Writer
+	handler := cli.New(w)
+	handler.Padding = cli.Default.Padding + 3
+	log := &log.Logger{
+		Handler: handler,
+		Level:   log.InfoLevel,
+	}
 	// replaces . and _ with -
 	url := baseURL + strings.NewReplacer(
 		".", "",
diff --git a/internal/pipe/nfpm/nfpm.go b/internal/pipe/nfpm/nfpm.go
index 6112381a..c39a50e8 100644
--- a/internal/pipe/nfpm/nfpm.go
+++ b/internal/pipe/nfpm/nfpm.go
@@ -147,6 +147,11 @@ func create(ctx *context.Context, fpm config.NFPM, format string, binaries []*ar
 		return err
 	}
 
+	maintainer, err := t.Apply(fpm.Maintainer)
+	if err != nil {
+		return err
+	}
+
 	debKeyFile, err := t.Apply(overridden.Deb.Signature.KeyFile)
 	if err != nil {
 		return err
@@ -209,7 +214,7 @@ func create(ctx *context.Context, fpm config.NFPM, format string, binaries []*ar
 		Release:         fpm.Release,
 		Prerelease:      fpm.Prerelease,
 		VersionMetadata: fpm.VersionMetadata,
-		Maintainer:      fpm.Maintainer,
+		Maintainer:      maintainer,
 		Description:     description,
 		Vendor:          fpm.Vendor,
 		Homepage:        homepage,


Test patch:
diff --git a/internal/deprecate/testdata/TestNotice.txt.golden b/internal/deprecate/testdata/TestNotice.txt.golden
index bd4a5aab..7048f686 100644
--- a/internal/deprecate/testdata/TestNotice.txt.golden
+++ b/internal/deprecate/testdata/TestNotice.txt.golden
@@ -1,3 +1,3 @@
    • first                    
-   • DEPRECATED: `foo.bar.whatever` should not be used anymore, check https://goreleaser.com/deprecations#foobarwhatever for more info
+      • DEPRECATED: `foo.bar.whatever` should not be used anymore, check https://goreleaser.com/deprecations#foobarwhatever for more info
    • last                     
diff --git a/internal/deprecate/testdata/TestNoticeCustom.txt.golden b/internal/deprecate/testdata/TestNoticeCustom.txt.golden
index dad95691..1ef2d0e5 100644
--- a/internal/deprecate/testdata/TestNoticeCustom.txt.golden
+++ b/internal/deprecate/testdata/TestNoticeCustom.txt.golden
@@ -1,3 +1,3 @@
    • first                    
-   • DEPRECATED: some custom template with a url https://goreleaser.com/deprecations#something-else
+      • DEPRECATED: some custom template with a url https://goreleaser.com/deprecations#something-else
    • last                     
diff --git a/internal/pipe/nfpm/nfpm_test.go b/internal/pipe/nfpm/nfpm_test.go
index f81d383c..6e1078a4 100644
--- a/internal/pipe/nfpm/nfpm_test.go
+++ b/internal/pipe/nfpm/nfpm_test.go
@@ -331,6 +331,12 @@ func TestInvalidTemplate(t *testing.T) {
 		require.Contains(t, Pipe{}.Run(ctx).Error(), `template: tmpl:1:3: executing "tmpl" at <.NOPE_DESC>: map has no entry for key "NOPE_DESC"`)
 	})
 
+	t.Run("maintainer", func(t *testing.T) {
+		ctx := makeCtx()
+		ctx.Config.NFPMs[0].Maintainer = "{{ .NOPE_DESC }}"
+		require.Contains(t, Pipe{}.Run(ctx).Error(), `template: tmpl:1:3: executing "tmpl" at <.NOPE_DESC>: map has no entry for key "NOPE_DESC"`)
+	})
+
 	t.Run("homepage", func(t *testing.T) {
 		ctx := makeCtx()
 		ctx.Config.NFPMs[0].Homepage = "{{ .NOPE_HOMEPAGE }}"
@@ -1148,6 +1154,7 @@ func TestBinDirTemplating(t *testing.T) {
 		Env: []string{
 			"PRO=pro",
 			"DESC=templates",
+			"MAINTAINER=me@me",
 		},
 		NFPMs: []config.NFPM{
 			{
@@ -1160,7 +1167,7 @@ func TestBinDirTemplating(t *testing.T) {
 				Priority:    "standard",
 				Description: "Some description with {{ .Env.DESC }}",
 				License:     "MIT",
-				Maintainer:  "me@me",
+				Maintainer:  "{{ .Env.MAINTAINER }}",
 				Vendor:      "asdf",
 				Homepage:    "https://goreleaser.com/{{ .Env.PRO }}",
 				NFPMOverridables: config.NFPMOverridables{