Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: expand environment variables in maintainer #463

Merged
merged 1 commit into from
Mar 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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