Repository: goreleaser/nfpm
Pull request #454 (2022-02-09 22:37:10)

Expand dependencies' version
Now the version is expanded in version, but in case, when many packages are built and depend on near one with the same version it doesn't work.

Felixoid: Here's an example of a problem https://github.com/ClickHouse/ClickHouse/blob/8d475e8c135c311b5a81e059b680eeee17b3bb5c/packages/clickhouse-client.yaml#L29

The packages are built together, but VERSION is expanded only partially.
codecov[bot]: # [Codecov](https://codecov.io/gh/goreleaser/nfpm/pull/454?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser) Report
> Merging [#454](https://codecov.io/gh/goreleaser/nfpm/pull/454?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser) (1f3bf07) into [main](https://codecov.io/gh/goreleaser/nfpm/commit/aba336ad1a626683f04b50c140741fb685b3010c?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser) (aba336a) will **increase** coverage by `0.03%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/goreleaser/nfpm/pull/454/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/454?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser)

```diff
@@            Coverage Diff             @@
##             main     #454      +/-   ##
==========================================
+ Coverage   65.86%   65.89%   +0.03%     
==========================================
  Files          16       16              
  Lines        1901     1903       +2     
==========================================
+ Hits         1252     1254       +2     
  Misses        510      510              
  Partials      139      139              
```


| [Impacted Files](https://codecov.io/gh/goreleaser/nfpm/pull/454?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/454/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser#diff-bmZwbS5nbw==) | `86.43% <100.00%> (+0.13%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/goreleaser/nfpm/pull/454?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/454?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser). Last update [aba336a...1f3bf07](https://codecov.io/gh/goreleaser/nfpm/pull/454?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).

Felixoid: is `docs / htmltest` test something that I should care about?
caarlos0: > is `docs / htmltest` test something that I should care about?

no idea why it started to fail recently, will investigate eventually

Patch:
diff --git a/nfpm.go b/nfpm.go
index 89a0ccf..eac2bc1 100644
--- a/nfpm.go
+++ b/nfpm.go
@@ -153,6 +153,11 @@ func (c *Config) expandEnvVars() {
 	c.Info.Version = os.Expand(c.Info.Version, c.envMappingFunc)
 	c.Info.Prerelease = os.Expand(c.Info.Prerelease, c.envMappingFunc)
 	c.Info.Arch = os.Expand(c.Info.Arch, c.envMappingFunc)
+	for _, override := range c.Overrides {
+		for i, dep := range override.Depends {
+			override.Depends[i] = os.Expand(dep, c.envMappingFunc)
+		}
+	}
 
 	// Vendor field
 	c.Info.Vendor = os.Expand(c.Info.Vendor, c.envMappingFunc)


Test patch:
diff --git a/nfpm_test.go b/nfpm_test.go
index 1c1d74f..4970299 100644
--- a/nfpm_test.go
+++ b/nfpm_test.go
@@ -301,6 +301,25 @@ func TestOptionsFromEnvironment(t *testing.T) {
 		require.NoError(t, err)
 		require.Equal(t, packager, info.RPM.Packager)
 	})
+
+	t.Run("depends", func(t *testing.T) {
+		os.Clearenv()
+		os.Setenv("VERSION", version)
+		info, err := nfpm.Parse(strings.NewReader(`---
+name: foo
+overrides:
+  deb:
+    depends:
+    - package (= ${VERSION})
+  rpm:
+    depends:
+    - package = ${VERSION}`))
+		require.NoError(t, err)
+		require.Len(t, info.Overrides["deb"].Depends, 1)
+		require.Equal(t, "package (= 1.0.0)", info.Overrides["deb"].Depends[0])
+		require.Len(t, info.Overrides["rpm"].Depends, 1)
+		require.Equal(t, "package = 1.0.0", info.Overrides["rpm"].Depends[0])
+	})
 }
 
 func TestOverrides(t *testing.T) {