Skip to content

Commit

Permalink
feat: expand environment variables in maintainer
Browse files Browse the repository at this point in the history
  • Loading branch information
scop committed Feb 21, 2022
1 parent b684867 commit 285912c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
3 changes: 2 additions & 1 deletion nfpm.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ func (c *Config) expandEnvVars() {
}
}

// Vendor field
// Maintainer and vendor fields
c.Info.Maintainer = os.Expand(c.Info.Maintainer, c.envMappingFunc)
c.Info.Vendor = os.Expand(c.Info.Vendor, c.envMappingFunc)

// Package signing related fields
Expand Down
26 changes: 18 additions & 8 deletions nfpm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,14 +237,15 @@ func TestParseEnhancedNestedNoGlob(t *testing.T) {

func TestOptionsFromEnvironment(t *testing.T) {
const (
globalPass = "hunter2"
debPass = "password123"
rpmPass = "secret"
apkPass = "foobar"
release = "3"
version = "1.0.0"
vendor = "GoReleaser"
packager = "nope"
globalPass = "hunter2"
debPass = "password123"
rpmPass = "secret"
apkPass = "foobar"
release = "3"
version = "1.0.0"
vendor = "GoReleaser"
packager = "nope"
maintainerEmail = "nope@example.com"
)

t.Run("version", func(t *testing.T) {
Expand All @@ -263,6 +264,15 @@ func TestOptionsFromEnvironment(t *testing.T) {
require.Equal(t, release, info.Release)
})

t.Run("maintainer", func(t *testing.T) {
os.Clearenv()
os.Setenv("GIT_COMMITTER_NAME", packager)
os.Setenv("GIT_COMMITTER_EMAIL", maintainerEmail)
info, err := nfpm.Parse(strings.NewReader("name: foo\nmaintainer: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>"))
require.NoError(t, err)
require.Equal(t, fmt.Sprintf("%s <%s>", packager, maintainerEmail), info.Maintainer)
})

t.Run("vendor", func(t *testing.T) {
os.Clearenv()
os.Setenv("VENDOR", vendor)
Expand Down
1 change: 1 addition & 0 deletions www/docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ section: default
priority: extra

# Maintainer.
# This will expand any env var you set in the field, eg maintainer: ${GIT_COMMITTER_NAME} <${GIT_COMMITTER_EMAIL}>
# Defaults to empty on rpm and apk
# Leaving the 'maintainer' field unset will not be allowed in a future version
maintainer: Carlos Alexandro Becker <root@carlosbecker.com>
Expand Down

0 comments on commit 285912c

Please sign in to comment.