Repository: goreleaser/goreleaser
Pull request #2272 (2021-06-01 00:32:11)

feat(nfpm): template homepage and description
allow to template more fields in the nfpm pipe...

vercel[bot]: This pull request is being automatically deployed with Vercel ([learn more](https://vercel.link/github-learn-more)).  
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: [https://vercel.com/goreleaser/goreleaser/DDxt4LMSGcpxiqRBVnhAte4gnKBm](https://vercel.com/goreleaser/goreleaser/DDxt4LMSGcpxiqRBVnhAte4gnKBm)  
✅ Preview: *In Progress*


codecov[bot]: # [Codecov](https://codecov.io/gh/goreleaser/goreleaser/pull/2272?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser) Report
> Merging [#2272](https://codecov.io/gh/goreleaser/goreleaser/pull/2272?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser) (5332f19) into [master](https://codecov.io/gh/goreleaser/goreleaser/commit/2375c93359f9a6a56289564fd1fa9dfd1889b277?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser) (2375c93) will **increase** coverage by `0.02%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/goreleaser/goreleaser/pull/2272/graphs/tree.svg?width=650&height=150&src=pr&token=3bJvv6b7hN&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser)](https://codecov.io/gh/goreleaser/goreleaser/pull/2272?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser)

```diff
@@            Coverage Diff             @@
##           master    #2272      +/-   ##
==========================================
+ Coverage   82.65%   82.67%   +0.02%     
==========================================
  Files          79       79              
  Lines        4271     4277       +6     
==========================================
+ Hits         3530     3536       +6     
  Misses        601      601              
  Partials      140      140              
```


| [Impacted Files](https://codecov.io/gh/goreleaser/goreleaser/pull/2272?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser) | Coverage Δ | |
|---|---|---|
| [internal/pipe/nfpm/nfpm.go](https://codecov.io/gh/goreleaser/goreleaser/pull/2272/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser#diff-aW50ZXJuYWwvcGlwZS9uZnBtL25mcG0uZ28=) | `95.90% <100.00%> (+0.10%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/goreleaser/goreleaser/pull/2272?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/goreleaser/goreleaser/pull/2272?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser). Last update [2375c93...5332f19](https://codecov.io/gh/goreleaser/goreleaser/pull/2272?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser).


Patch:
diff --git a/internal/pipe/nfpm/nfpm.go b/internal/pipe/nfpm/nfpm.go
index 028128c3..9cd793f9 100644
--- a/internal/pipe/nfpm/nfpm.go
+++ b/internal/pipe/nfpm/nfpm.go
@@ -186,6 +186,16 @@ func create(ctx *context.Context, fpm config.NFPM, format, arch string, binaries
 		return err
 	}
 
+	homepage, err := tmpl.Apply(fpm.Homepage)
+	if err != nil {
+		return err
+	}
+
+	description, err := tmpl.Apply(fpm.Description)
+	if err != nil {
+		return err
+	}
+
 	contents := files.Contents{}
 	for _, content := range overridden.Contents {
 		src, err := tmpl.Apply(content.Source)
@@ -233,9 +243,9 @@ func create(ctx *context.Context, fpm config.NFPM, format, arch string, binaries
 		Prerelease:      fpm.Prerelease,
 		VersionMetadata: fpm.VersionMetadata,
 		Maintainer:      fpm.Maintainer,
-		Description:     fpm.Description,
+		Description:     description,
 		Vendor:          fpm.Vendor,
-		Homepage:        fpm.Homepage,
+		Homepage:        homepage,
 		License:         fpm.License,
 		Overridables: nfpm.Overridables{
 			Conflicts:    overridden.Conflicts,
diff --git a/www/docs/customization/homebrew.md b/www/docs/customization/homebrew.md
index c149a16b..36347848 100644
--- a/www/docs/customization/homebrew.md
+++ b/www/docs/customization/homebrew.md
@@ -81,7 +81,7 @@ brews:
     # Default is empty.
     homepage: "https://example.com/"
 
-    # Your app's description.
+    # Template of your app's description.
     # Default is empty.
     description: "Software to create fast and easy drum rolls."
 
diff --git a/www/docs/customization/nfpm.md b/www/docs/customization/nfpm.md
index 3a54e348..60cbcb97 100644
--- a/www/docs/customization/nfpm.md
+++ b/www/docs/customization/nfpm.md
@@ -43,7 +43,8 @@ nfpms:
     # Your app's vendor.
     # Default is empty.
     vendor: Drum Roll Inc.
-    # Your app's homepage.
+
+    # Template to your app's homepage.
     # Default is empty.
     homepage: https://example.com/
 
@@ -51,7 +52,7 @@ nfpms:
     # Default is empty.
     maintainer: Drummer <drum-roll@example.com>
 
-    # Your app's description.
+    # Template to your app's description.
     # Default is empty.
     description: Software to create fast and easy drum rolls.
 


Test patch:
diff --git a/internal/pipe/nfpm/nfpm_test.go b/internal/pipe/nfpm/nfpm_test.go
index e96893bd..21b6fe97 100644
--- a/internal/pipe/nfpm/nfpm_test.go
+++ b/internal/pipe/nfpm/nfpm_test.go
@@ -84,6 +84,10 @@ func TestRunPipe(t *testing.T) {
 	ctx := context.New(config.Project{
 		ProjectName: "mybin",
 		Dist:        dist,
+		Env: []string{
+			"PRO=pro",
+			"DESC=templates",
+		},
 		NFPMs: []config.NFPM{
 			{
 				ID:          "someid",
@@ -92,11 +96,11 @@ func TestRunPipe(t *testing.T) {
 				Formats:     []string{"deb", "rpm", "apk"},
 				Section:     "somesection",
 				Priority:    "standard",
-				Description: "Some description",
+				Description: "Some description with {{ .Env.DESC }}",
 				License:     "MIT",
 				Maintainer:  "me@me",
 				Vendor:      "asdf",
-				Homepage:    "https://goreleaser.github.io",
+				Homepage:    "https://goreleaser.com/{{ .Env.PRO }}",
 				NFPMOverridables: config.NFPMOverridables{
 					FileNameTemplate: defaultNameTemplate + "-{{ .Release }}-{{ .Epoch }}",
 					PackageName:      "foo",
@@ -215,7 +219,6 @@ func TestInvalidNameTemplate(t *testing.T) {
 	t.Run("filename_template", func(t *testing.T) {
 		ctx := makeCtx()
 		ctx.Config.NFPMs[0].NFPMOverridables = config.NFPMOverridables{
-			PackageName:      "foo",
 			FileNameTemplate: "{{.Foo}",
 		}
 		require.Contains(t, Pipe{}.Run(ctx).Error(), `template: tmpl:1: unexpected "}" in operand`)
@@ -224,8 +227,6 @@ func TestInvalidNameTemplate(t *testing.T) {
 	t.Run("source", func(t *testing.T) {
 		ctx := makeCtx()
 		ctx.Config.NFPMs[0].NFPMOverridables = config.NFPMOverridables{
-			PackageName:      "foo",
-			FileNameTemplate: "Foo",
 			Contents: files.Contents{
 				{
 					Source:      "{{ .NOPE_SOURCE }}",
@@ -239,8 +240,6 @@ func TestInvalidNameTemplate(t *testing.T) {
 	t.Run("target", func(t *testing.T) {
 		ctx := makeCtx()
 		ctx.Config.NFPMs[0].NFPMOverridables = config.NFPMOverridables{
-			PackageName:      "foo",
-			FileNameTemplate: "Foo",
 			Contents: files.Contents{
 				{
 					Source:      "./testdata/testfile.txt",
@@ -250,6 +249,18 @@ func TestInvalidNameTemplate(t *testing.T) {
 		}
 		require.Contains(t, Pipe{}.Run(ctx).Error(), `template: tmpl:1:3: executing "tmpl" at <.NOPE_TARGET>: map has no entry for key "NOPE_TARGET"`)
 	})
+
+	t.Run("description", func(t *testing.T) {
+		ctx := makeCtx()
+		ctx.Config.NFPMs[0].Description = "{{ .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 }}"
+		require.Contains(t, Pipe{}.Run(ctx).Error(), `template: tmpl:1:3: executing "tmpl" at <.NOPE_HOMEPAGE>: map has no entry for key "NOPE_HOMEPAGE"`)
+	})
 }
 
 func TestRunPipeInvalidContentsSourceTemplate(t *testing.T) {