Skip to content

Commit

Permalink
feat: custom packager configuration for rpm pkg (#409)
Browse files Browse the repository at this point in the history
Co-authored-by: CrazyMax <crazy-max@users.noreply.github.com>
  • Loading branch information
crazy-max and crazy-max authored Nov 30, 2021
1 parent 1de9194 commit 9570f52
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 1 deletion.
4 changes: 4 additions & 0 deletions nfpm.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ func (c *Config) expandEnvVars() {
if apkPassphrase != "" {
c.Info.APK.Signature.KeyPassphrase = apkPassphrase
}

// RPM specific
c.Info.RPM.Packager = os.Expand(c.RPM.Packager, c.envMappingFunc)
}

// Info contains information about a single package.
Expand Down Expand Up @@ -273,6 +276,7 @@ type RPM struct {
Summary string `yaml:"summary,omitempty" jsonschema:"title=package summary"`
Compression string `yaml:"compression,omitempty" jsonschema:"title=compression algorithm to be used,enum=gzip,enum=lzma,enum=xz,default=gzip"`
Signature RPMSignature `yaml:"signature,omitempty" jsonschema:"title=rpm signature"`
Packager string `yaml:"packager,omitempty" jsonschema:"title=organization that actually packaged the software"`
}

// RPMScripts represents scripts only available on RPM packages.
Expand Down
9 changes: 9 additions & 0 deletions nfpm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ func TestOptionsFromEnvironment(t *testing.T) {
release = "3"
version = "1.0.0"
vendor = "GoReleaser"
packager = "nope"
)

t.Run("version", func(t *testing.T) {
Expand Down Expand Up @@ -292,6 +293,14 @@ func TestOptionsFromEnvironment(t *testing.T) {
require.Equal(t, rpmPass, info.RPM.Signature.KeyPassphrase)
require.Equal(t, apkPass, info.APK.Signature.KeyPassphrase)
})

t.Run("packager", func(t *testing.T) {
os.Clearenv()
os.Setenv("PACKAGER", packager)
info, err := nfpm.Parse(strings.NewReader("name: foo\nrpm:\n packager: $PACKAGER"))
require.NoError(t, err)
require.Equal(t, packager, info.RPM.Packager)
})
}

func TestOverrides(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion rpm/rpm.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ func buildRPMMeta(info *nfpm.Info) (*rpmpack.RPMMetaData, error) {
Licence: info.License,
URL: info.Homepage,
Vendor: info.Vendor,
Packager: info.Maintainer,
Packager: defaultTo(info.RPM.Packager, info.Maintainer),
Group: info.RPM.Group,
Provides: provides,
Recommends: recommends,
Expand Down
27 changes: 27 additions & 0 deletions rpm/rpm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,33 @@ func TestRPMSummary(t *testing.T) {
require.Equal(t, customSummary, summary)
}

func TestRPMPackager(t *testing.T) {
f, err := ioutil.TempFile("", "test.rpm")
require.NoError(t, err)

customPackager := "GoReleaser <staff@goreleaser.com>"
info := exampleInfo()
info.RPM.Group = "Unspecified"
info.RPM.Packager = customPackager

require.NoError(t, Default.Package(info, f))

file, err := os.OpenFile(f.Name(), os.O_RDONLY, 0o600) //nolint:gosec
require.NoError(t, err)
defer func() {
f.Close()
file.Close()
err = os.Remove(file.Name())
require.NoError(t, err)
}()
rpm, err := rpmutils.ReadRpm(file)
require.NoError(t, err)

packager, err := rpm.Header.GetString(rpmutils.PACKAGER)
require.NoError(t, err)
require.Equal(t, customPackager, packager)
}

func TestWithRPMTags(t *testing.T) {
f, err := ioutil.TempFile("", "test.rpm")
require.NoError(t, err)
Expand Down
6 changes: 6 additions & 0 deletions www/docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,12 @@ rpm:
# description, but can be explicitly provided here.
summary: Explicit Summary for Sample Package

# The packager is used to identify the organization that actually packaged
# the software, as opposed to the author of the software.
# `maintainer` will be used as fallback if not specified.
# This will expand any env var you set in the field, eg packager: ${PACKAGER}
packager: GoReleaser <staff@goreleaser.com>

# Compression algorithm (gzip (default), lzma or xz).
compression: lzma

Expand Down

0 comments on commit 9570f52

Please sign in to comment.