Skip to content

Commit

Permalink
feat: expand env variables in homepage field (#675)
Browse files Browse the repository at this point in the history
For example, GitLab CI has `CI_PROJECT_URL` which can be useful here.
  • Loading branch information
scop authored Jul 13, 2023
1 parent 182fb41 commit 562bc43
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion nfpm.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,9 @@ func (c *Config) expandEnvVars() {
c.Info.Provides = c.expandEnvVarsStringSlice(c.Info.Provides)
c.Info.Suggests = c.expandEnvVarsStringSlice(c.Info.Suggests)

// Maintainer and vendor fields
// Basic metadata fields
c.Info.Name = os.Expand(c.Info.Name, c.envMappingFunc)
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)

Expand Down
8 changes: 8 additions & 0 deletions nfpm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ func TestOptionsFromEnvironment(t *testing.T) {
vendor = "GoReleaser"
packager = "nope"
maintainerEmail = "[email protected]"
homepage = "https://nfpm.goreleaser.com"
vcsURL = "https://github.com/goreleaser/nfpm.git"
)

Expand Down Expand Up @@ -419,6 +420,13 @@ maintainer: '"$GIT_COMMITTER_NAME" <$GIT_COMMITTER_EMAIL>'
require.Equal(t, vendor, info.Vendor)
})

t.Run("homepage", func(t *testing.T) {
t.Setenv("CI_PROJECT_URL", homepage)
info, err := nfpm.Parse(strings.NewReader("name: foo\nhomepage: $CI_PROJECT_URL"))
require.NoError(t, err)
require.Equal(t, homepage, info.Homepage)
})

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 www/docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ description: Sample package
vendor: GoReleaser

# Package's homepage.
# This will expand any env var you set in the field, e.g. homepage: ${CI_PROJECT_URL}
homepage: https://nfpm.goreleaser.com

# License.
Expand Down

0 comments on commit 562bc43

Please sign in to comment.