diff --git a/.goreleaser.yaml b/.goreleaser.yaml index a1cb325c23c..f5d8b6a19a6 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -12,7 +12,7 @@ before: - ./scripts/manpages.sh snapshot: - name_template: "{{ incpatch .Version }}-next" + version_template: "{{ incpatch .Version }}-next" gomod: proxy: true diff --git a/cmd/testdata/good.yml b/cmd/testdata/good.yml index 4641e27d570..c89b704042e 100644 --- a/cmd/testdata/good.yml +++ b/cmd/testdata/good.yml @@ -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:" diff --git a/internal/pipe/snapshot/snapshot.go b/internal/pipe/snapshot/snapshot.go index 8d4287283aa..951afcc9e48 100644 --- a/internal/pipe/snapshot/snapshot.go +++ b/internal/pipe/snapshot/snapshot.go @@ -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) } diff --git a/internal/pipe/snapshot/snapshot_test.go b/internal/pipe/snapshot/snapshot_test.go index 83a98b1022f..d87a57cc1ba 100644 --- a/internal/pipe/snapshot/snapshot_test.go +++ b/internal/pipe/snapshot/snapshot_test.go @@ -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 TestDefaultSet(t *testing.T) { + ctx := testctx.NewWithCfg(config.Project{ + Snapshot: config.Snapshot{ + VersionTemplate: "snap", + }, + }) + require.NoError(t, Pipe{}.Default(ctx)) + require.Equal(t, "snap", ctx.Config.Snapshot.VersionTemplate) } -func TestSnapshotInvalidNametemplate(t *testing.T) { +func TestSnapshotInvalidVersionTemplate(t *testing.T) { ctx := testctx.NewWithCfg(config.Project{ Snapshot: config.Snapshot{ - NameTemplate: "{{.ShortCommit}{{{sss}}}", + 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)) diff --git a/pkg/config/config.go b/pkg/config/config.go index 22ba1be6cc9..09bf40c9ae3 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -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. diff --git a/www/docs/deprecations.md b/www/docs/deprecations.md index 60b4eda8529..051eb68c03d 100644 --- a/www/docs/deprecations.md +++ b/www/docs/deprecations.md @@ -15,15 +15,13 @@ goreleaser check ## Active deprecation notices -None so far! - +### 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