github.com/goreleaser/goreleaser@v1.25.1/internal/pipe/snapshot/snapshot.go (about)

     1  // Package snapshot provides the snapshotting functionality to goreleaser.
     2  package snapshot
     3  
     4  import (
     5  	"fmt"
     6  
     7  	"github.com/caarlos0/log"
     8  	"github.com/goreleaser/goreleaser/internal/tmpl"
     9  	"github.com/goreleaser/goreleaser/pkg/context"
    10  )
    11  
    12  // Pipe for setting up the snapshot feature..
    13  type Pipe struct{}
    14  
    15  func (Pipe) String() string                 { return "snapshotting" }
    16  func (Pipe) Skip(ctx *context.Context) bool { return !ctx.Snapshot }
    17  
    18  // Default sets the pipe defaults.
    19  func (Pipe) Default(ctx *context.Context) error {
    20  	if ctx.Config.Snapshot.NameTemplate == "" {
    21  		ctx.Config.Snapshot.NameTemplate = "{{ .Version }}-SNAPSHOT-{{ .ShortCommit }}"
    22  	}
    23  	return nil
    24  }
    25  
    26  func (Pipe) Run(ctx *context.Context) error {
    27  	name, err := tmpl.New(ctx).Apply(ctx.Config.Snapshot.NameTemplate)
    28  	if err != nil {
    29  		return fmt.Errorf("failed to parse snapshot name: %w", err)
    30  	}
    31  	if name == "" {
    32  		return fmt.Errorf("empty snapshot name")
    33  	}
    34  	ctx.Version = name
    35  	log.WithField("version", ctx.Version).Infof("building snapshot...")
    36  	return nil
    37  }