Repository: goreleaser/goreleaser
Pull request #1248 (2019-11-15 19:53:00)

feat: change default snapshot version template
both deb and rpm requires that the version is somewhat semantic, so this is a way to make that work as expected.

closes https://github.com/goreleaser/goreleaser/issues/1236

codecov-io: # [Codecov](https://codecov.io/gh/goreleaser/goreleaser/pull/1248?src=pr&el=h1) Report
> Merging [#1248](https://codecov.io/gh/goreleaser/goreleaser/pull/1248?src=pr&el=desc) into [master](https://codecov.io/gh/goreleaser/goreleaser/commit/0953c2f4f76f0267cc26bd503e0f332b7d528aa3?src=pr&el=desc) will **not change** coverage.
> The diff coverage is `100%`.

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

```diff
@@          Coverage Diff           @@
##           master   #1248   +/-   ##
======================================
  Coverage    83.7%   83.7%           
======================================
  Files          58      58           
  Lines        3321    3321           
======================================
  Hits         2780    2780           
  Misses        460     460           
  Partials       81      81
```


| [Impacted Files](https://codecov.io/gh/goreleaser/goreleaser/pull/1248?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [internal/pipe/snapshot/snapshot.go](https://codecov.io/gh/goreleaser/goreleaser/pull/1248/diff?src=pr&el=tree#diff-aW50ZXJuYWwvcGlwZS9zbmFwc2hvdC9zbmFwc2hvdC5nbw==) | `100% <100%> (ø)` | :arrow_up: |

------

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


Patch:
diff --git a/internal/pipe/snapshot/snapshot.go b/internal/pipe/snapshot/snapshot.go
index 84c135fd..5385c3ac 100644
--- a/internal/pipe/snapshot/snapshot.go
+++ b/internal/pipe/snapshot/snapshot.go
@@ -20,7 +20,7 @@ func (Pipe) String() string {
 // Default sets the pipe defaults
 func (Pipe) Default(ctx *context.Context) error {
 	if ctx.Config.Snapshot.NameTemplate == "" {
-		ctx.Config.Snapshot.NameTemplate = "SNAPSHOT-{{ .ShortCommit }}"
+		ctx.Config.Snapshot.NameTemplate = "{{ .Tag }}-SNAPSHOT-{{ .ShortCommit }}"
 	}
 	return nil
 }
diff --git a/main.go b/main.go
index e37e7dc2..03530e82 100644
--- a/main.go
+++ b/main.go
@@ -11,11 +11,11 @@ import (
 	"github.com/caarlos0/ctrlc"
 	"github.com/fatih/color"
 	"github.com/goreleaser/goreleaser/internal/middleware"
+	"github.com/goreleaser/goreleaser/internal/pipe/defaults"
 	"github.com/goreleaser/goreleaser/internal/pipeline"
 	"github.com/goreleaser/goreleaser/internal/static"
 	"github.com/goreleaser/goreleaser/pkg/config"
 	"github.com/goreleaser/goreleaser/pkg/context"
-	"github.com/goreleaser/goreleaser/pkg/defaults"
 	"gopkg.in/alecthomas/kingpin.v2"
 )
 
@@ -128,12 +128,8 @@ func checkConfig(filename string) error {
 	}
 	var ctx = context.New(cfg)
 	return ctrlc.Default.Run(ctx, func() error {
-		for _, pipe := range defaults.Defaulters {
-			if err := middleware.ErrHandler(pipe.Default)(ctx); err != nil {
-				return err
-			}
-		}
-		return nil
+		log.Info(color.New(color.Bold).Sprint("checking config:"))
+		return defaults.Pipe{}.Run(ctx)
 	})
 }
 
diff --git a/www/content/snapshots.md b/www/content/snapshots.md
index 30d9f303..96527b98 100644
--- a/www/content/snapshots.md
+++ b/www/content/snapshots.md
@@ -15,8 +15,12 @@ and also with the `snapshot` customization section:
 # .goreleaser.yml
 snapshot:
   # Allows you to change the name of the generated snapshot
-  # Default is `SNAPSHOT-{{.ShortCommit}}`.
-  name_template: SNAPSHOT-{{.Commit}}
+  #
+  # Note that some pipes require this to be semantic version compliant (nfpm,
+  # for example).
+  #
+  # Default is `{{ .Tag }}-SNAPSHOT-{{.ShortCommit}}`.
+  name_template: 1.2.3-SNAPSHOT-{{.Commit}}
 ```
 
 > Learn more about the [name template engine](/templates).


Test patch:
diff --git a/internal/pipe/snapshot/snapshot_test.go b/internal/pipe/snapshot/snapshot_test.go
index 358f1953..17286bee 100644
--- a/internal/pipe/snapshot/snapshot_test.go
+++ b/internal/pipe/snapshot/snapshot_test.go
@@ -19,7 +19,7 @@ func TestDefault(t *testing.T) {
 		},
 	}
 	assert.NoError(t, Pipe{}.Default(ctx))
-	assert.Equal(t, "SNAPSHOT-{{ .ShortCommit }}", ctx.Config.Snapshot.NameTemplate)
+	assert.Equal(t, "{{ .Tag }}-SNAPSHOT-{{ .ShortCommit }}", ctx.Config.Snapshot.NameTemplate)
 }
 
 func TestDefaultSet(t *testing.T) {