github.com/joselitofilho/goreleaser@v0.155.1-0.20210123221854-e4891856c593/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/goreleaser/goreleaser/internal/pipe"
     8  	"github.com/goreleaser/goreleaser/internal/tmpl"
     9  	"github.com/goreleaser/goreleaser/pkg/context"
    10  )
    11  
    12  // Pipe for checksums.
    13  type Pipe struct{}
    14  
    15  func (Pipe) String() string {
    16  	return "snapshotting"
    17  }
    18  
    19  // Default sets the pipe defaults.
    20  func (Pipe) Default(ctx *context.Context) error {
    21  	if ctx.Config.Snapshot.NameTemplate == "" {
    22  		ctx.Config.Snapshot.NameTemplate = "{{ .Tag }}-SNAPSHOT-{{ .ShortCommit }}"
    23  	}
    24  	return nil
    25  }
    26  
    27  func (Pipe) Run(ctx *context.Context) error {
    28  	if !ctx.Snapshot {
    29  		return pipe.Skip("not a snapshot")
    30  	}
    31  	name, err := tmpl.New(ctx).Apply(ctx.Config.Snapshot.NameTemplate)
    32  	if err != nil {
    33  		return fmt.Errorf("failed to generate snapshot name: %w", err)
    34  	}
    35  	if name == "" {
    36  		return fmt.Errorf("empty snapshot name")
    37  	}
    38  	ctx.Version = name
    39  	return nil
    40  }