Repository: goreleaser/nfpm
Pull request #246 (2020-11-07 21:05:18)

feat: Allow explicit summary from RPM packages
The previous behaviour was to use only the first line of the
description as the summary. In some cases, it is desirable to have a
separate summary. Since only RPM packages have a summary field, I've
put this inside the RPM configuration.

    description: This is my description
    rpm:
      summary: This is my summary

By default, just use the first line of the description.

vercel[bot]: This pull request is being automatically deployed with Vercel ([learn more](https://vercel.link/github-learn-more)).  
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: [https://vercel.com/goreleaser/nfpm/d8wog83te](https://vercel.com/goreleaser/nfpm/d8wog83te)  
✅ Preview: *In Progress*


codecov[bot]: # [Codecov](https://codecov.io/gh/goreleaser/nfpm/pull/246?src=pr&el=h1) Report
> Merging [#246](https://codecov.io/gh/goreleaser/nfpm/pull/246?src=pr&el=desc) (18695b4) into [master](https://codecov.io/gh/goreleaser/nfpm/commit/a2ffae7a5dd9ad38ee4ed6fcb13bbf96fd9fd56d?el=desc) (a2ffae7) will **not change** coverage.
> The diff coverage is `100.00%`.

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

```diff
@@           Coverage Diff           @@
##           master     #246   +/-   ##
=======================================
  Coverage   66.86%   66.86%           
=======================================
  Files           9        9           
  Lines        1023     1023           
=======================================
  Hits          684      684           
  Misses        204      204           
  Partials      135      135           
```


| [Impacted Files](https://codecov.io/gh/goreleaser/nfpm/pull/246?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [nfpm.go](https://codecov.io/gh/goreleaser/nfpm/pull/246/diff?src=pr&el=tree#diff-bmZwbS5nbw==) | `78.04% <ø> (ø)` | |
| [rpm/rpm.go](https://codecov.io/gh/goreleaser/nfpm/pull/246/diff?src=pr&el=tree#diff-cnBtL3JwbS5nbw==) | `71.85% <100.00%> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/goreleaser/nfpm/pull/246?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/246?src=pr&el=footer). Last update [a2ffae7...18695b4](https://codecov.io/gh/goreleaser/nfpm/pull/246?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 9f0e3bc..3dc3557 100644
--- a/nfpm.go
+++ b/nfpm.go
@@ -177,6 +177,7 @@ type Overridables struct {
 // RPM is custom configs that are only available on RPM packages.
 type RPM struct {
 	Group       string `yaml:"group,omitempty"`
+	Summary     string `yaml:"summary,omitempty"`
 	Compression string `yaml:"compression,omitempty"`
 	// https://www.cl.cam.ac.uk/~jw35/docs/rpm_config.html
 	ConfigNoReplaceFiles map[string]string `yaml:"config_noreplace_files,omitempty"`
diff --git a/rpm/rpm.go b/rpm/rpm.go
index 7ff0400..a56d8f4 100644
--- a/rpm/rpm.go
+++ b/rpm/rpm.go
@@ -207,7 +207,7 @@ func buildRPMMeta(info *nfpm.Info) (*rpmpack.RPMMetaData, error) {
 
 	return &rpmpack.RPMMetaData{
 		Name:        info.Name,
-		Summary:     strings.Split(info.Description, "\n")[0],
+		Summary:     defaultTo(info.RPM.Summary, strings.Split(info.Description, "\n")[0]),
 		Description: info.Description,
 		Version:     formatVersion(info),
 		Release:     defaultTo(info.Release, "1"),
diff --git a/www/docs/configuration.md b/www/docs/configuration.md
index 97cbc2b..3590656 100644
--- a/www/docs/configuration.md
+++ b/www/docs/configuration.md
@@ -137,6 +137,10 @@ rpm:
   # but required by old distros like CentOS 5 / EL 5 and earlier.
   group: Unspecified
 
+  # The package summary. This is, by default, the first line of the
+  # description, but can be explicitly provided here.
+  summary: Explicit Summary for Sample Package
+
   # Compression algorithm.
   compression: lzma
 


Test patch:
diff --git a/rpm/rpm_test.go b/rpm/rpm_test.go
index 911368f..94a17d8 100644
--- a/rpm/rpm_test.go
+++ b/rpm/rpm_test.go
@@ -141,6 +141,31 @@ func TestRPMGroup(t *testing.T) {
 	assert.Equal(t, "Unspecified", group)
 }
 
+func TestRPMSummary(t *testing.T) {
+	f, err := ioutil.TempFile("", "test.rpm")
+	defer func() {
+		_ = f.Close()
+		err = os.Remove(f.Name())
+		assert.NoError(t, err)
+	}()
+
+	var customSummary = "This is my custom summary"
+	info := exampleInfo()
+	info.RPM.Group = "Unspecified"
+	info.RPM.Summary = customSummary
+
+	require.NoError(t, Default.Package(info, f))
+
+	file, err := os.OpenFile(f.Name(), os.O_RDONLY, 0600) //nolint:gosec
+	require.NoError(t, err)
+	rpm, err := rpmutils.ReadRpm(file)
+	require.NoError(t, err)
+
+	summary, err := rpm.Header.GetString(rpmutils.SUMMARY)
+	require.NoError(t, err)
+	assert.Equal(t, customSummary, summary)
+}
+
 func TestWithRPMTags(t *testing.T) {
 	f, err := ioutil.TempFile("", "test.rpm")
 	defer func() {