Repository: goreleaser/nfpm
Pull request #102 (2019-11-05 07:32:32)

chore(deps): bump gopkg.in/yaml.v2 from 2.2.4 to 2.2.5
Bumps [gopkg.in/yaml.v2](https://github.com/go-yaml/yaml) from 2.2.4 to 2.2.5.
<details>
<summary>Commits</summary>

- [`f90ceb4`](https://github.com/go-yaml/yaml/commit/f90ceb4f409096b60e2e9076b38b304b8246e5fa) Fix check for non-map alias merging in v2 ([#529](https://github-redirect.dependabot.com/go-yaml/yaml/issues/529))
- [`970885f`](https://github.com/go-yaml/yaml/commit/970885f01c8bc1fecb7ab1c8ce8e7609bda45530) Trivial style tuning on last change.
- See full diff in [compare view](https://github.com/go-yaml/yaml/compare/v2.2.4...v2.2.5)
</details>
<br />

[![Dependabot compatibility score](https://api.dependabot.com/badges/compatibility_score?dependency-name=gopkg.in/yaml.v2&package-manager=go_modules&previous-version=2.2.4&new-version=2.2.5)](https://dependabot.com/compatibility-score.html?dependency-name=gopkg.in/yaml.v2&package-manager=go_modules&previous-version=2.2.4&new-version=2.2.5)

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

**Note:** This repo was added to Dependabot recently, so you'll receive a maximum of 5 PRs for your first few update runs. Once an update run creates fewer than 5 PRs we'll remove that limit.

You can always request more updates by clicking `Bump now` in your [Dependabot dashboard](https://app.dependabot.com).

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
- `@dependabot use these labels` will set the current labels as the default for future PRs for this repo and language
- `@dependabot use these reviewers` will set the current reviewers as the default for future PRs for this repo and language
- `@dependabot use these assignees` will set the current assignees as the default for future PRs for this repo and language
- `@dependabot use this milestone` will set the current milestone as the default for future PRs for this repo and language
- `@dependabot badge me` will comment on this PR with code to add a "Dependabot enabled" badge to your readme

Additionally, you can set the following in your Dependabot [dashboard](https://app.dependabot.com):
- Update frequency (including time of day and day of week)
- Pull request limits (per update run and/or open at any time)
- Out-of-range updates (receive only lockfile updates, if desired)
- Security updates (receive only security updates, if desired)



</details>

codecov-io: # [Codecov](https://codecov.io/gh/goreleaser/nfpm/pull/102?src=pr&el=h1) Report
> Merging [#102](https://codecov.io/gh/goreleaser/nfpm/pull/102?src=pr&el=desc) into [master](https://codecov.io/gh/goreleaser/nfpm/commit/2dea0cedb8dd55f1a342c38e4ec87b15398e0439?src=pr&el=desc) will **not change** coverage.
> The diff coverage is `n/a`.

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

```diff
@@           Coverage Diff           @@
##           master     #102   +/-   ##
=======================================
  Coverage   71.93%   71.93%           
=======================================
  Files           5        5           
  Lines         481      481           
=======================================
  Hits          346      346           
  Misses         84       84           
  Partials       51       51
```



------

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


Patch:
diff --git a/cmd/nfpm/main.go b/cmd/nfpm/main.go
index 672b082..0341398 100644
--- a/cmd/nfpm/main.go
+++ b/cmd/nfpm/main.go
@@ -66,9 +66,13 @@ func doPackage(path, target string) error {
 	if err != nil {
 		return err
 	}
+
+	info = nfpm.WithDefaults(info)
+
 	if err = nfpm.Validate(info); err != nil {
 		return err
 	}
+
 	fmt.Printf("using %s packager...\n", format)
 	pkg, err := nfpm.Get(format)
 	if err != nil {
@@ -79,7 +83,7 @@ func doPackage(path, target string) error {
 	if err != nil {
 		return err
 	}
-	return pkg.Package(nfpm.WithDefaults(info), f)
+	return pkg.Package(info, f)
 }
 
 const example = `# nfpm example config file
diff --git a/go.mod b/go.mod
index 32bae38..67fe6e5 100644
--- a/go.mod
+++ b/go.mod
@@ -20,7 +20,7 @@ require (
 	github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect
 	golang.org/x/crypto v0.0.0-20191002192127-34f69633bfdc // indirect
 	gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
-	gopkg.in/yaml.v2 v2.2.4
+	gopkg.in/yaml.v2 v2.2.5
 )
 
 // TODO: remove this when https://github.com/google/rpmpack/pull/33 gets merged in.
diff --git a/go.sum b/go.sum
index 0746eaf..2c305d0 100644
--- a/go.sum
+++ b/go.sum
@@ -35,6 +35,7 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
 github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
 github.com/sassoftware/go-rpmutils v0.0.0-20190420191620-a8f1baeba37b h1:+gCnWOZV8Z/8jehJ2CdqB47Z3S+SREmQcuXkRFLNsiI=
 github.com/sassoftware/go-rpmutils v0.0.0-20190420191620-a8f1baeba37b/go.mod h1:am+Fp8Bt506lA3Rk3QCmSqmYmLMnPDhdDUcosQCAx+I=
+github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
 github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
 github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
 github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
@@ -57,3 +58,5 @@ gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
 gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
 gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I=
 gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
+gopkg.in/yaml.v2 v2.2.5 h1:ymVxjfMaHvXD8RqPRmzHHsB3VvucivSkIAvJFDI5O3c=
+gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
diff --git a/nfpm.go b/nfpm.go
index 20c8588..33adaae 100644
--- a/nfpm.go
+++ b/nfpm.go
@@ -6,7 +6,6 @@ import (
 	"fmt"
 	"io"
 	"os"
-	"strings"
 	"sync"
 
 	"github.com/Masterminds/semver/v3"
@@ -49,17 +48,7 @@ func Parse(in io.Reader) (config Config, err error) {
 	config.Info.Release = os.ExpandEnv(config.Info.Release)
 	config.Info.Version = os.ExpandEnv(config.Info.Version)
 
-	// parse the version as a semver so we can properly split the parts and support proper ordering for both rpm and deb
-	var v *semver.Version
-	if v, err = semver.NewVersion(config.Info.Version); err == nil {
-		config.Info.Version = fmt.Sprintf("%d.%d.%d", v.Major(), v.Minor(), v.Patch())
-		if config.Info.Release == "" {
-			config.Info.Release = v.Prerelease()
-		}
-		config.Info.Deb.VersionMetadata = v.Metadata()
-	}
-	err = config.Validate()
-	return config, err
+	return config, config.Validate()
 }
 
 // ParseFile decodes YAML data from a file path into a configuration struct
@@ -201,6 +190,16 @@ func WithDefaults(info *Info) *Info {
 	if info.Description == "" {
 		info.Description = "no description given"
 	}
-	info.Version = strings.TrimPrefix(info.Version, "v")
+
+	// parse the version as a semver so we can properly split the parts
+	// and support proper ordering for both rpm and deb
+	if v, err := semver.NewVersion(info.Version); err == nil {
+		info.Version = fmt.Sprintf("%d.%d.%d", v.Major(), v.Minor(), v.Patch())
+		if info.Release == "" {
+			// maybe we should concat the previous info.Release with v.Prerelease?
+			info.Release = v.Prerelease()
+		}
+		info.Deb.VersionMetadata = v.Metadata()
+	}
 	return info
 }


Test patch:
diff --git a/nfpm_test.go b/nfpm_test.go
index 1e3f790..f04604a 100644
--- a/nfpm_test.go
+++ b/nfpm_test.go
@@ -33,14 +33,27 @@ func TestGet(t *testing.T) {
 	assert.Equal(t, pkgr, got)
 }
 
-func TestDefaultsOnEmptyInfo(t *testing.T) {
+func TestDefaultsVersion(t *testing.T) {
 	info := &Info{
-		Version: "2.4.1",
+		Version: "v2.4.1-beta3",
 	}
 	info = WithDefaults(info)
 	assert.NotEmpty(t, info.Bindir)
 	assert.NotEmpty(t, info.Platform)
 	assert.Equal(t, "2.4.1", info.Version)
+	assert.Equal(t, "beta3", info.Release)
+}
+
+func TestDefaultsVersionWithRelease(t *testing.T) {
+	info := &Info{
+		Version: "v2.4.1-beta3",
+		Release: "4",
+	}
+	info = WithDefaults(info)
+	assert.NotEmpty(t, info.Bindir)
+	assert.NotEmpty(t, info.Platform)
+	assert.Equal(t, "2.4.1", info.Version)
+	assert.Equal(t, "4", info.Release)
 }
 
 func TestDefaults(t *testing.T) {
diff --git a/rpm/rpm_test.go b/rpm/rpm_test.go
index ac8ea73..fb07744 100644
--- a/rpm/rpm_test.go
+++ b/rpm/rpm_test.go
@@ -13,6 +13,7 @@ import (
 )
 
 const (
+	tagVersion     = 0x03e9 // 1001
 	tagRelease     = 0x03ea // 1002
 	tagSummary     = 0x03ec // 1004
 	tagDescription = 0x03ed // 1005
@@ -90,6 +91,10 @@ func TestRPM(t *testing.T) {
 	rpm, err := rpmutils.ReadRpm(file)
 	assert.NoError(t, err)
 
+	version, err := rpm.Header.GetString(tagVersion)
+	assert.NoError(t, err)
+	assert.Equal(t, "1.0.0", version)
+
 	release, err := rpm.Header.GetString(tagRelease)
 	assert.NoError(t, err)
 	assert.Equal(t, "1", release)
@@ -129,6 +134,10 @@ func TestWithRPMTags(t *testing.T) {
 	rpm, err := rpmutils.ReadRpm(file)
 	assert.NoError(t, err)
 
+	version, err := rpm.Header.GetString(tagVersion)
+	assert.NoError(t, err)
+	assert.Equal(t, "1.0.0", version)
+
 	release, err := rpm.Header.GetString(tagRelease)
 	assert.NoError(t, err)
 	assert.Equal(t, "3", release)
@@ -146,13 +155,6 @@ func TestWithRPMTags(t *testing.T) {
 	assert.Equal(t, info.Description, description)
 }
 
-func TestRPMVersionWithDash(t *testing.T) {
-	info := exampleInfo()
-	info.Version = "1.0.0-beta"
-	var err = Default.Package(info, ioutil.Discard)
-	assert.NoError(t, err)
-}
-
 func TestRPMScripts(t *testing.T) {
 	info := exampleInfo()
 	f, err := ioutil.TempFile(".", fmt.Sprintf("%s-%s-*.rpm", info.Name, info.Version))