Repository: goreleaser/nfpm
Pull request #498 (2022-04-22 17:50:04)

fix: deb version order in control
This should have been caught in https://github.com/goreleaser/nfpm/pull/375 but I missed it.

The version string when using `Release` is correct in the filename, but incorrect in the control file.

Here's the [debian docs on the control file's version](https://www.debian.org/doc/debian-policy/ch-controlfields.html#version)

Before:
Filename: `foo_1.2.3~pre+meta-2_amd64.deb`
control version: `1.2.3-2~pre+meta`

After:
Filename: `foo_1.2.3~pre+meta-2_amd64.deb`
control version: `1.2.3~pre+meta-2`

✅ `task ci` 🚀 

codecov[bot]: # [Codecov](https://codecov.io/gh/goreleaser/nfpm/pull/498?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser) Report
> Merging [#498](https://codecov.io/gh/goreleaser/nfpm/pull/498?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser) (5a06a5a) into [main](https://codecov.io/gh/goreleaser/nfpm/commit/0310042153331724ccf980d0472c2a1d8d5d2938?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser) (0310042) will **not change** coverage.
> The diff coverage is `n/a`.

```diff
@@           Coverage Diff           @@
##             main     #498   +/-   ##
=======================================
  Coverage   66.12%   66.12%           
=======================================
  Files          16       16           
  Lines        1916     1916           
=======================================
  Hits         1267     1267           
  Misses        510      510           
  Partials      139      139           
```


| [Impacted Files](https://codecov.io/gh/goreleaser/nfpm/pull/498?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser) | Coverage Δ | |
|---|---|---|
| [deb/deb.go](https://codecov.io/gh/goreleaser/nfpm/pull/498/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser#diff-ZGViL2RlYi5nbw==) | `70.16% <ø> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/goreleaser/nfpm/pull/498?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/goreleaser/nfpm/pull/498?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser). Last update [0310042...5a06a5a](https://codecov.io/gh/goreleaser/nfpm/pull/498?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=goreleaser).


Patch:
diff --git a/deb/deb.go b/deb/deb.go
index 1985013..6f39ebc 100644
--- a/deb/deb.go
+++ b/deb/deb.go
@@ -681,9 +681,9 @@ const controlTemplate = `
 {{- /* Mandatory fields */ -}}
 Package: {{.Info.Name}}
 Version: {{ if .Info.Epoch}}{{ .Info.Epoch }}:{{ end }}{{.Info.Version}}
-         {{- if .Info.Release}}-{{ .Info.Release }}{{- end }}
          {{- if .Info.Prerelease}}~{{ .Info.Prerelease }}{{- end }}
          {{- if .Info.VersionMetadata}}+{{ .Info.VersionMetadata }}{{- end }}
+         {{- if .Info.Release}}-{{ .Info.Release }}{{- end }}
 Section: {{.Info.Section}}
 Priority: {{.Info.Priority}}
 Architecture: {{.Info.Arch}}


Test patch:
diff --git a/deb/deb_test.go b/deb/deb_test.go
index 4b2c1b5..426218d 100644
--- a/deb/deb_test.go
+++ b/deb/deb_test.go
@@ -157,7 +157,7 @@ func TestDebVersionWithReleaseAndPrerelease(t *testing.T) {
 	err := writeControl(&buf, controlData{info, 0})
 	require.NoError(t, err)
 	v := extractDebVersion(&buf)
-	require.Equal(t, "1.0.0-2~rc1", v)
+	require.Equal(t, "1.0.0~rc1-2", v)
 }
 
 func TestDebVersionWithVersionMetadata(t *testing.T) {
@@ -260,6 +260,41 @@ func TestNoJoinsControl(t *testing.T) {
 	require.Equal(t, string(bts), w.String())
 }
 
+func TestVersionControl(t *testing.T) {
+	var w bytes.Buffer
+	require.NoError(t, writeControl(&w, controlData{
+		Info: nfpm.WithDefaults(&nfpm.Info{
+			Name:        "foo",
+			Arch:        "amd64",
+			Description: "Foo does things",
+			Priority:    "extra",
+			Maintainer:  "Carlos A Becker <pkg@carlosbecker.com>",
+			Version:     "v1.0.0-beta+meta",
+			Release:     "2",
+			Section:     "default",
+			Homepage:    "http://carlosbecker.com",
+			Vendor:      "nope",
+			Overridables: nfpm.Overridables{
+				Depends:    []string{},
+				Recommends: []string{},
+				Suggests:   []string{},
+				Replaces:   []string{},
+				Provides:   []string{},
+				Conflicts:  []string{},
+				Contents:   []*files.Content{},
+			},
+		}),
+		InstalledSize: 10,
+	}))
+	golden := "testdata/control4.golden"
+	if *update {
+		require.NoError(t, ioutil.WriteFile(golden, w.Bytes(), 0o600))
+	}
+	bts, err := ioutil.ReadFile(golden) //nolint:gosec
+	require.NoError(t, err)
+	require.Equal(t, string(bts), w.String())
+}
+
 func TestDebFileDoesNotExist(t *testing.T) {
 	abs, err := filepath.Abs("../testdata/whatever.confzzz")
 	require.NoError(t, err)
diff --git a/deb/testdata/control4.golden b/deb/testdata/control4.golden
new file mode 100644
index 0000000..8ff9a12
--- /dev/null
+++ b/deb/testdata/control4.golden
@@ -0,0 +1,9 @@
+Package: foo
+Version: 1.0.0~beta+meta-2
+Section: default
+Priority: extra
+Architecture: amd64
+Maintainer: Carlos A Becker <pkg@carlosbecker.com>
+Installed-Size: 10
+Homepage: http://carlosbecker.com
+Description: Foo does things