1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-03-11 14:39:28 +02:00

feat: rename snapshot.name_template -> snapshot.version_template (#5019)

close #5017

---------

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
Carlos Alexandro Becker 2024-07-29 08:21:00 -04:00 committed by GitHub
parent 482a48958f
commit 2de792c31d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 56 additions and 21 deletions

View File

@ -12,7 +12,7 @@ before:
- ./scripts/manpages.sh
snapshot:
name_template: "{{ incpatch .Version }}-next"
version_template: "{{ incpatch .Version }}-next"
gomod:
proxy: true

12
cmd/testdata/good.yml vendored
View File

@ -7,15 +7,15 @@ before:
# you may remove this if you don't need go generate
- go generate ./...
builds:
- env:
- CGO_ENABLED=0
- env:
- CGO_ENABLED=0
checksum:
name_template: 'checksums.txt'
name_template: "checksums.txt"
snapshot:
name_template: "{{ incpatch .Version }}-next"
version_template: "{{ incpatch .Version }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
- "^docs:"
- "^test:"

View File

@ -5,6 +5,7 @@ import (
"fmt"
"github.com/caarlos0/log"
"github.com/goreleaser/goreleaser/v2/internal/deprecate"
"github.com/goreleaser/goreleaser/v2/internal/tmpl"
"github.com/goreleaser/goreleaser/v2/pkg/context"
)
@ -17,14 +18,18 @@ func (Pipe) Skip(ctx *context.Context) bool { return !ctx.Snapshot }
// Default sets the pipe defaults.
func (Pipe) Default(ctx *context.Context) error {
if ctx.Config.Snapshot.NameTemplate == "" {
ctx.Config.Snapshot.NameTemplate = "{{ .Version }}-SNAPSHOT-{{ .ShortCommit }}"
if ctx.Config.Snapshot.VersionTemplate == "" {
ctx.Config.Snapshot.VersionTemplate = "{{ .Version }}-SNAPSHOT-{{ .ShortCommit }}"
}
if ctx.Config.Snapshot.NameTemplate != "" {
deprecate.Notice(ctx, "snapshot.name_template")
ctx.Config.Snapshot.VersionTemplate = ctx.Config.Snapshot.NameTemplate
}
return nil
}
func (Pipe) Run(ctx *context.Context) error {
name, err := tmpl.New(ctx).Apply(ctx.Config.Snapshot.NameTemplate)
name, err := tmpl.New(ctx).Apply(ctx.Config.Snapshot.VersionTemplate)
if err != nil {
return fmt.Errorf("failed to parse snapshot name: %w", err)
}

View File

@ -18,23 +18,33 @@ func TestDefault(t *testing.T) {
Snapshot: config.Snapshot{},
})
require.NoError(t, Pipe{}.Default(ctx))
require.Equal(t, "{{ .Version }}-SNAPSHOT-{{ .ShortCommit }}", ctx.Config.Snapshot.NameTemplate)
require.Equal(t, "{{ .Version }}-SNAPSHOT-{{ .ShortCommit }}", ctx.Config.Snapshot.VersionTemplate)
}
func TestDefaultSet(t *testing.T) {
func TestDefaultDeprecated(t *testing.T) {
ctx := testctx.NewWithCfg(config.Project{
Snapshot: config.Snapshot{
NameTemplate: "snap",
},
})
require.NoError(t, Pipe{}.Default(ctx))
require.Equal(t, "snap", ctx.Config.Snapshot.NameTemplate)
require.Equal(t, "snap", ctx.Config.Snapshot.VersionTemplate)
}
func TestSnapshotInvalidNametemplate(t *testing.T) {
func TestDefaultSet(t *testing.T) {
ctx := testctx.NewWithCfg(config.Project{
Snapshot: config.Snapshot{
NameTemplate: "{{.ShortCommit}{{{sss}}}",
VersionTemplate: "snap",
},
})
require.NoError(t, Pipe{}.Default(ctx))
require.Equal(t, "snap", ctx.Config.Snapshot.VersionTemplate)
}
func TestSnapshotInvalidVersionTemplate(t *testing.T) {
ctx := testctx.NewWithCfg(config.Project{
Snapshot: config.Snapshot{
VersionTemplate: "{{.ShortCommit}{{{sss}}}",
},
})
testlib.RequireTemplateError(t, Pipe{}.Run(ctx))
@ -43,7 +53,7 @@ func TestSnapshotInvalidNametemplate(t *testing.T) {
func TestSnapshotEmptyFinalName(t *testing.T) {
ctx := testctx.NewWithCfg(config.Project{
Snapshot: config.Snapshot{
NameTemplate: "{{ .Commit }}",
VersionTemplate: "{{ .Commit }}",
},
}, testctx.WithCurrentTag("v1.2.3"))
require.EqualError(t, Pipe{}.Run(ctx), "empty snapshot name")
@ -52,7 +62,7 @@ func TestSnapshotEmptyFinalName(t *testing.T) {
func TestSnapshot(t *testing.T) {
ctx := testctx.NewWithCfg(config.Project{
Snapshot: config.Snapshot{
NameTemplate: "{{ incpatch .Tag }}",
VersionTemplate: "{{ incpatch .Tag }}",
},
}, testctx.WithCurrentTag("v1.2.3"))
require.NoError(t, Pipe{}.Run(ctx))

View File

@ -1069,7 +1069,9 @@ type SnapcraftExtraFiles struct {
// Snapshot config.
type Snapshot struct {
NameTemplate string `yaml:"name_template,omitempty" json:"name_template,omitempty"`
// Deprecated: use VersionTemplate.
NameTemplate string `yaml:"name_template,omitempty" json:"name_template,omitempty"`
VersionTemplate string `yaml:"version_template,omitempty" json:"version_template,omitempty"`
}
// Checksum config.

View File

@ -15,15 +15,13 @@ goreleaser check
## Active deprecation notices
None so far!
<!--
Template for new deprecations:
### property
> since yyyy-mm-dd (v1.xx)
> since yyyy-mm-dd (v2.xx)
Description.
@ -41,6 +39,26 @@ Description.
-->
### snapshot.name_template
> since 2024-07-28 (v2.2)
Property renamed so its easier to reason about.
=== "Before"
```yaml
snapshot:
name_template: 'foo'
```
=== "After"
```yaml
snapshot:
version_template: 'foo'
```
## Removed in v2
### archives.strip_parent_binary_folder