Repository: goreleaser/nfpm
Pull request #406 (2021-11-19 11:11:49)

feat: expand-env support for vendor field
This PR allows to expand env for vendor field. This can be useful if another entity wants to redistribute a package.

codecov[bot]: # [Codecov](https://codecov.io/gh/goreleaser/nfpm/pull/406?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser) Report
> Merging [#406](https://codecov.io/gh/goreleaser/nfpm/pull/406?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser) (7cb1659) into [main](https://codecov.io/gh/goreleaser/nfpm/commit/344dd2a5428989f3ef0b427f1b4316f7a50a462c?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser) (344dd2a) will **increase** coverage by `0.05%`.
> The diff coverage is `100.00%`.

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

```diff
@@            Coverage Diff             @@
##             main     #406      +/-   ##
==========================================
+ Coverage   66.12%   66.18%   +0.05%     
==========================================
  Files          15       15              
  Lines        1851     1854       +3     
==========================================
+ Hits         1224     1227       +3     
  Misses        488      488              
  Partials      139      139              
```


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

------

[Continue to review full report at Codecov](https://codecov.io/gh/goreleaser/nfpm/pull/406?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/nfpm/pull/406?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser). Last update [344dd2a...7cb1659](https://codecov.io/gh/goreleaser/nfpm/pull/406?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/nfpm.go b/nfpm.go
index 13bc7fa..5c46e8c 100644
--- a/nfpm.go
+++ b/nfpm.go
@@ -154,6 +154,9 @@ func (c *Config) expandEnvVars() {
 	c.Info.Prerelease = os.Expand(c.Info.Prerelease, c.envMappingFunc)
 	c.Info.Arch = os.Expand(c.Info.Arch, c.envMappingFunc)
 
+	// Vendor field
+	c.Info.Vendor = os.Expand(c.Info.Vendor, c.envMappingFunc)
+
 	// Package signing related fields
 	c.Info.Deb.Signature.KeyFile = os.Expand(c.Deb.Signature.KeyFile, c.envMappingFunc)
 	c.Info.RPM.Signature.KeyFile = os.Expand(c.RPM.Signature.KeyFile, c.envMappingFunc)
diff --git a/www/docs/configuration.md b/www/docs/configuration.md
index 105a021..70dc350 100644
--- a/www/docs/configuration.md
+++ b/www/docs/configuration.md
@@ -64,6 +64,7 @@ maintainer: Carlos Alexandro Becker <root@carlosbecker.com>
 description: Sample package
 
 # Vendor.
+# This will expand any env var you set in the field, eg vendor: ${VENDOR}
 vendor: GoReleaser
 
 # Package's homepage.


Test patch:
diff --git a/nfpm_test.go b/nfpm_test.go
index 369cc47..55b67a2 100644
--- a/nfpm_test.go
+++ b/nfpm_test.go
@@ -243,6 +243,7 @@ func TestOptionsFromEnvironment(t *testing.T) {
 		apkPass    = "foobar"
 		release    = "3"
 		version    = "1.0.0"
+		vendor     = "GoReleaser"
 	)
 
 	t.Run("version", func(t *testing.T) {
@@ -261,6 +262,14 @@ func TestOptionsFromEnvironment(t *testing.T) {
 		require.Equal(t, release, info.Release)
 	})
 
+	t.Run("vendor", func(t *testing.T) {
+		os.Clearenv()
+		os.Setenv("VENDOR", vendor)
+		info, err := nfpm.Parse(strings.NewReader("name: foo\nvendor: $VENDOR"))
+		require.NoError(t, err)
+		require.Equal(t, vendor, info.Vendor)
+	})
+
 	t.Run("global passphrase", func(t *testing.T) {
 		os.Clearenv()
 		os.Setenv("NFPM_PASSPHRASE", globalPass)