From 1f3bf07ff67b2b26ecf15e0a6510bc7526b35634 Mon Sep 17 00:00:00 2001 From: "Mikhail f. Shiryaev" Date: Wed, 9 Feb 2022 23:34:46 +0100 Subject: [PATCH] feat: expand ENV for dependencies versions --- nfpm.go | 5 +++++ nfpm_test.go | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/nfpm.go b/nfpm.go index 89a0ccf3..eac2bc10 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) diff --git a/nfpm_test.go b/nfpm_test.go index 1c1d74ff..49702995 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) {