Skip to content

Commit

Permalink
feat: env var substitution in description (#848)
Browse files Browse the repository at this point in the history
Co-authored-by: Slawek Figiel <[email protected]>
  • Loading branch information
fivitti and fivitti authored Aug 15, 2024
1 parent 33a5094 commit 632979a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions nfpm.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ func (c *Config) expandEnvVars() {
c.Info.Homepage = os.Expand(c.Info.Homepage, c.envMappingFunc)
c.Info.Maintainer = os.Expand(c.Info.Maintainer, c.envMappingFunc)
c.Info.Vendor = os.Expand(c.Info.Vendor, c.envMappingFunc)
c.Info.Description = os.Expand(c.Info.Description, c.envMappingFunc)

// Package signing related fields
c.Info.Deb.Signature.KeyFile = os.Expand(c.Deb.Signature.KeyFile, c.envMappingFunc)
Expand Down
10 changes: 10 additions & 0 deletions nfpm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,11 +313,13 @@ func TestParseFile(t *testing.T) {
t.Setenv("RPM_KEY_FILE", "my/rpm/key/file")
t.Setenv("TEST_RELEASE_ENV_VAR", "1234")
t.Setenv("TEST_PRERELEASE_ENV_VAR", "beta1")
t.Setenv("TEST_DESCRIPTION_ENV_VAR", "description")
config, err := parseAndValidate("./testdata/env-fields.yaml")
require.NoError(t, err)
require.Equal(t, fmt.Sprintf("v%s", os.Getenv("GOROOT")), config.Version)
require.Equal(t, "1234", config.Release)
require.Equal(t, "beta1", config.Prerelease)
require.Equal(t, "My description", config.Description)
require.Equal(t, "my/rpm/key/file", config.RPM.Signature.KeyFile)
require.Equal(t, "hard/coded/file", config.Deb.Signature.KeyFile)
require.Equal(t, "", config.APK.Signature.KeyFile)
Expand Down Expand Up @@ -381,6 +383,7 @@ func TestOptionsFromEnvironment(t *testing.T) {
maintainerEmail = "[email protected]"
homepage = "https://nfpm.goreleaser.com"
vcsBrowser = "https://github.com/goreleaser/nfpm"
description = "barfoo"
)

t.Run("platform", func(t *testing.T) {
Expand Down Expand Up @@ -440,6 +443,13 @@ maintainer: '"$GIT_COMMITTER_NAME" <$GIT_COMMITTER_EMAIL>'
require.Equal(t, homepage, info.Homepage)
})

t.Run("description", func(t *testing.T) {
t.Setenv("DESCRIPTION", description)
info, err := nfpm.Parse(strings.NewReader("name: foo\ndescription: $DESCRIPTION"))
require.NoError(t, err)
require.Equal(t, description, info.Description)
})

t.Run("global passphrase", func(t *testing.T) {
t.Setenv("NFPM_PASSPHRASE", globalPass)
info, err := nfpm.Parse(strings.NewReader("name: foo"))
Expand Down
1 change: 1 addition & 0 deletions testdata/env-fields.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ arch: "amd64"
version: "v$GOROOT"
release: ${TEST_RELEASE_ENV_VAR}
prerelease: ${TEST_PRERELEASE_ENV_VAR}
description: My ${TEST_DESCRIPTION_ENV_VAR}
contents:
- src: ./testdata/whatever.conf
dst: /etc/foo/regular.conf
Expand Down
1 change: 1 addition & 0 deletions www/docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ priority: extra
maintainer: Carlos Alexandro Becker <[email protected]>

# Description.
# This will expand any env var you set in the field, e.g. description: ${DESCRIPTION}
# Defaults to `no description given`.
# Most packagers call for a one-line synopsis of the package. Some (like deb)
# also call for a multi-line description starting on the second line.
Expand Down

0 comments on commit 632979a

Please sign in to comment.