1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-03-19 20:57:53 +02:00
Carlos Alexandro Becker 2de792c31d
feat: rename snapshot.name_template -> snapshot.version_template (#5019)
close #5017

---------

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
2024-07-29 09:21:00 -03:00

43 lines
1.3 KiB
Go

// Package snapshot provides the snapshotting functionality to goreleaser.
package snapshot
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"
)
// Pipe for setting up the snapshot feature..
type Pipe struct{}
func (Pipe) String() string { return "snapshotting" }
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.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.VersionTemplate)
if err != nil {
return fmt.Errorf("failed to parse snapshot name: %w", err)
}
if name == "" {
return fmt.Errorf("empty snapshot name")
}
ctx.Version = name
log.WithField("version", ctx.Version).Infof("building snapshot...")
return nil
}