Repository: goreleaser/nfpm
Pull request #89 (2019-10-22 03:03:19)

fix: empty release on rpm
refs https://github.com/goreleaser/goreleaser/issues/1213

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

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

```diff
@@            Coverage Diff             @@
##           master      #89      +/-   ##
==========================================
+ Coverage   71.51%   71.75%   +0.23%     
==========================================
  Files           5        5              
  Lines         474      478       +4     
==========================================
+ Hits          339      343       +4     
  Misses         84       84              
  Partials       51       51
```


| [Impacted Files](https://codecov.io/gh/goreleaser/nfpm/pull/89?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [rpm/rpm.go](https://codecov.io/gh/goreleaser/nfpm/pull/89/diff?src=pr&el=tree#diff-cnBtL3JwbS5nbw==) | `72.02% <100%> (+0.8%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/goreleaser/nfpm/pull/89?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/89?src=pr&el=footer). Last update [7889c9b...99f4167](https://codecov.io/gh/goreleaser/nfpm/pull/89?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/rpm/rpm.go b/rpm/rpm.go
index d0c8d71..441133d 100644
--- a/rpm/rpm.go
+++ b/rpm/rpm.go
@@ -105,7 +105,7 @@ func buildRPMMeta(info *nfpm.Info) (*rpmpack.RPMMetaData, error) {
 		Name:        info.Name,
 		Description: info.Description,
 		Version:     info.Version,
-		Release:     info.Release,
+		Release:     defaultTo(info.Release, "1"),
 		Arch:        info.Arch,
 		OS:          info.Platform,
 		Licence:     info.License,
@@ -121,6 +121,13 @@ func buildRPMMeta(info *nfpm.Info) (*rpmpack.RPMMetaData, error) {
 	}, nil
 }
 
+func defaultTo(in, def string) string {
+	if in == "" {
+		return def
+	}
+	return in
+}
+
 func toRelation(items []string) (rpmpack.Relations, error) {
 	relations := make(rpmpack.Relations, 0)
 	for idx := range items {


Test patch:
diff --git a/rpm/rpm_test.go b/rpm/rpm_test.go
index 3fc415c..927da73 100644
--- a/rpm/rpm_test.go
+++ b/rpm/rpm_test.go
@@ -13,10 +13,11 @@ import (
 )
 
 const (
-	tagPrein  = 0x03ff // 1023
-	tagPostin = 0x0400 // 1024
-	tagPreun  = 0x0401 // 1025
-	tagPostun = 0x0402 // 1026
+	tagRelease = 0x03ea // 1002
+	tagPrein   = 0x03ff // 1023
+	tagPostin  = 0x0400 // 1024
+	tagPreun   = 0x0401 // 1025
+	tagPostun  = 0x0402 // 1026
 )
 
 func exampleInfo() *nfpm.Info {
@@ -72,19 +73,47 @@ func exampleInfo() *nfpm.Info {
 }
 
 func TestRPM(t *testing.T) {
-	var err = Default.Package(exampleInfo(), ioutil.Discard)
+	f, err := ioutil.TempFile("", "test.rpm")
+	defer func() {
+		_ = f.Close()
+		err = os.Remove(f.Name())
+		assert.NoError(t, err)
+	}()
+
+	assert.NoError(t, Default.Package(exampleInfo(), f))
+
+	file, err := os.OpenFile(f.Name(), os.O_RDONLY, 0600) //nolint:gosec
+	assert.NoError(t, err)
+	rpm, err := rpmutils.ReadRpm(file)
+	assert.NoError(t, err)
+	release, err := rpm.Header.GetString(tagRelease)
 	assert.NoError(t, err)
+	assert.Equal(t, "1", release)
 }
 
 func TestWithRPMTags(t *testing.T) {
+	f, err := ioutil.TempFile("", "test.rpm")
+	defer func() {
+		_ = f.Close()
+		err = os.Remove(f.Name())
+		assert.NoError(t, err)
+	}()
+
 	var info = exampleInfo()
+	info.Release = "3"
 	info.RPM = nfpm.RPM{
-		Group:   "default",
-		Prefix:  "/usr",
-		Release: "3",
+		Group:  "default",
+		Prefix: "/usr",
 	}
-	var err = Default.Package(info, ioutil.Discard)
+	assert.NoError(t, Default.Package(info, f))
+
+	file, err := os.OpenFile(f.Name(), os.O_RDONLY, 0600) //nolint:gosec
+	assert.NoError(t, err)
+	rpm, err := rpmutils.ReadRpm(file)
+	assert.NoError(t, err)
+	release, err := rpm.Header.GetString(tagRelease)
 	assert.NoError(t, err)
+	assert.Equal(t, "3", release)
 }
 
 func TestRPMVersionWithDash(t *testing.T) {