Skip to content

Commit

Permalink
feat: rename snapshot.name_template -> snapshot.version_template (#5019)
Browse files Browse the repository at this point in the history
close #5017

---------

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
  • Loading branch information
caarlos0 authored Jul 29, 2024
1 parent 482a489 commit 2de792c
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ before:
- ./scripts/manpages.sh

snapshot:
name_template: "{{ incpatch .Version }}-next"
version_template: "{{ incpatch .Version }}-next"

gomod:
proxy: true
Expand Down
12 changes: 6 additions & 6 deletions cmd/testdata/good.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:"
11 changes: 8 additions & 3 deletions internal/pipe/snapshot/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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)
}
Expand Down
24 changes: 17 additions & 7 deletions internal/pipe/snapshot/snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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")
Expand All @@ -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))
Expand Down
4 changes: 3 additions & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
24 changes: 21 additions & 3 deletions www/docs/deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down

0 comments on commit 2de792c

Please sign in to comment.