Repository: goreleaser/nfpm
Pull request #64 (2019-08-25 14:56:43)

fix: improve rpm release config
refs #46 #52 

codecov-io: # [Codecov](https://codecov.io/gh/goreleaser/nfpm/pull/64?src=pr&el=h1) Report
> Merging [#64](https://codecov.io/gh/goreleaser/nfpm/pull/64?src=pr&el=desc) into [master](https://codecov.io/gh/goreleaser/nfpm/commit/e08d696bd6478b1ae92c963e32589ace1b5ddc8d?src=pr&el=desc) will **decrease** coverage by `0.11%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/goreleaser/nfpm/pull/64/graphs/tree.svg?width=650&token=9QKGIxn7wg&height=150&src=pr)](https://codecov.io/gh/goreleaser/nfpm/pull/64?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master      #64      +/-   ##
==========================================
- Coverage    71.8%   71.68%   -0.12%     
==========================================
  Files           5        5              
  Lines         500      498       -2     
==========================================
- Hits          359      357       -2     
  Misses         87       87              
  Partials       54       54
```


| [Impacted Files](https://codecov.io/gh/goreleaser/nfpm/pull/64?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [nfpm.go](https://codecov.io/gh/goreleaser/nfpm/pull/64/diff?src=pr&el=tree#diff-bmZwbS5nbw==) | `89.65% <ø> (ø)` | :arrow_up: |
| [rpm/rpm.go](https://codecov.io/gh/goreleaser/nfpm/pull/64/diff?src=pr&el=tree#diff-cnBtL3JwbS5nbw==) | `73.41% <100%> (-0.31%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/goreleaser/nfpm/pull/64?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/goreleaser/nfpm/pull/64?src=pr&el=footer). Last update [e08d696...325be2f](https://codecov.io/gh/goreleaser/nfpm/pull/64?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/nfpm.go b/nfpm.go
index c1fb9ac..69ea508 100644
--- a/nfpm.go
+++ b/nfpm.go
@@ -108,7 +108,6 @@ type Info struct {
 	Platform     string `yaml:"platform,omitempty"`
 	Epoch        string `yaml:"epoch,omitempty"`
 	Version      string `yaml:"version,omitempty"`
-	Release      string `yaml:"release,omitempty"`
 	Section      string `yaml:"section,omitempty"`
 	Priority     string `yaml:"priority,omitempty"`
 	Maintainer   string `yaml:"maintainer,omitempty"`
@@ -138,6 +137,7 @@ type RPM struct {
 	Group       string `yaml:"group,omitempty"`
 	Prefix      string `yaml:"prefix,omitempty"`
 	Compression string `yaml:"compression,omitempty"`
+	Release     string `yaml:"release,omitempty"`
 }
 
 // Scripts contains information about maintainer scripts for packages
diff --git a/rpm/rpm.go b/rpm/rpm.go
index 133d305..681cced 100644
--- a/rpm/rpm.go
+++ b/rpm/rpm.go
@@ -56,9 +56,6 @@ func (*RPM) Package(info nfpm.Info, w io.Writer) error {
 	if err != nil {
 		return fmt.Errorf("rpmbuild not present in $PATH")
 	}
-	if s := info.Release; s == "" {
-		info.Release = "1"
-	}
 	temps, err := setupTempFiles(info)
 	if err != nil {
 		return err
@@ -232,7 +229,7 @@ func setupTempFiles(info nfpm.Info) (tempFiles, error) {
 		Folder: folder,
 		Source: filepath.Join(root, "SOURCES", folder+".tar.gz"),
 		Spec:   filepath.Join(root, "SPECS", info.Name+".spec"),
-		RPM:    filepath.Join(root, "RPMS", info.Arch, fmt.Sprintf("%s-%s.%s.rpm", folder, info.Release, info.Arch)),
+		RPM:    filepath.Join(root, "RPMS", info.Arch, fmt.Sprintf("%s-%s.%s.rpm", folder, info.RPM.Release, info.Arch)),
 	}, nil
 }
 
@@ -341,7 +338,11 @@ Summary: {{ first_line .Info.Description }}
 Epoch: {{ . }}
 {{- end }}
 Version: {{ .Info.Version }}
-Release: {{ .Info.Release }}
+{{- with .Info.RPM.Release }}
+Release: {{ . }}
+{{- else }}
+Release: 1
+{{- end }}
 {{- with .Info.License }}
 License: {{ . }}
 {{- end }}


Test patch:
diff --git a/acceptance/acceptance_test.go b/acceptance/acceptance_test.go
index 55c04e3..8876ba2 100644
--- a/acceptance/acceptance_test.go
+++ b/acceptance/acceptance_test.go
@@ -131,6 +131,15 @@ func TestRPMCompression(t *testing.T) {
 	}
 }
 
+func TestRPMRelease(t *testing.T) {
+	accept(t, acceptParms{
+		Name:       "release_rpm",
+		Conf:       "release.rpm.yaml",
+		Format:     "rpm",
+		Dockerfile: "release.rpm.dockerfile",
+	})
+}
+
 type acceptParms struct {
 	Name       string
 	Conf       string
diff --git a/acceptance/testdata/release.rpm.dockerfile b/acceptance/testdata/release.rpm.dockerfile
new file mode 100644
index 0000000..17a0ba1
--- /dev/null
+++ b/acceptance/testdata/release.rpm.dockerfile
@@ -0,0 +1,10 @@
+FROM fedora
+ARG package
+COPY ${package} /tmp/foo.rpm
+RUN rpm -ivh /tmp/foo.rpm
+RUN test -e /usr/local/bin/fake
+RUN test -f /etc/foo/whatever.conf
+RUN echo wat >> /etc/foo/whatever.conf
+RUN rpm -e foo
+RUN test -f /etc/foo/whatever.conf.rpmsave
+RUN test ! -f /usr/local/bin/fake
diff --git a/acceptance/testdata/release.rpm.yaml b/acceptance/testdata/release.rpm.yaml
new file mode 100644
index 0000000..522a181
--- /dev/null
+++ b/acceptance/testdata/release.rpm.yaml
@@ -0,0 +1,17 @@
+name: "foo"
+arch: "amd64"
+platform: "linux"
+version: "v1.2.3"
+maintainer: "Foo Bar"
+description: |
+  Foo bar
+    Multiple lines
+vendor: "foobar"
+homepage: "https://foobar.org"
+license: "MIT"
+files:
+  ../testdata/fake: "/usr/local/bin/fake"
+config_files:
+  ../testdata/whatever.conf: "/etc/foo/whatever.conf"
+rpm:
+  release: "4"
diff --git a/rpm/rpm_test.go b/rpm/rpm_test.go
index 0c7e40c..b608888 100644
--- a/rpm/rpm_test.go
+++ b/rpm/rpm_test.go
@@ -24,7 +24,6 @@ func exampleInfo() nfpm.Info {
 		Priority:    "extra",
 		Maintainer:  "Carlos A Becker <pkg@carlosbecker.com>",
 		Version:     "1.0.0",
-		Release:     "1",
 		Section:     "default",
 		Homepage:    "http://carlosbecker.com",
 		Vendor:      "nope",
@@ -98,8 +97,9 @@ func TestRPM(t *testing.T) {
 func TestWithRPMTags(t *testing.T) {
 	var info = exampleInfo()
 	info.RPM = nfpm.RPM{
-		Group:  "default",
-		Prefix: "/usr",
+		Group:   "default",
+		Prefix:  "/usr",
+		Release: "3",
 	}
 	var err = Default.Package(info, ioutil.Discard)
 	assert.NoError(t, err)
@@ -108,8 +108,9 @@ func TestWithRPMTags(t *testing.T) {
 func TestRPMTagsSpec(t *testing.T) {
 	var info = exampleInfo()
 	info.RPM = nfpm.RPM{
-		Group:  "default",
-		Prefix: "/usr",
+		Group:   "default",
+		Prefix:  "/usr",
+		Release: "5",
 	}
 
 	vs := rpmbuildVersion{Major: 4, Minor: 15, Patch: 2}
diff --git a/rpm/testdata/spec_4.15.x.golden b/rpm/testdata/spec_4.15.x.golden
index e195d62..098ca42 100644
--- a/rpm/testdata/spec_4.15.x.golden
+++ b/rpm/testdata/spec_4.15.x.golden
@@ -8,7 +8,7 @@
 Name: foo
 Summary: Foo does things
 Version: 1.0.0
-Release: 1
+Release: 5
 License: MIT
 Group: default
 SOURCE0 : %{name}-%{version}.tar.gz