1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-24 04:16:27 +02:00

41 lines
939 B
Go
Raw Normal View History

// Package snapshot provides the snapshotting functionality to goreleaser.
package snapshot
2018-12-13 10:09:36 -02:00
import (
"fmt"
"github.com/goreleaser/goreleaser/internal/pipe"
"github.com/goreleaser/goreleaser/internal/tmpl"
"github.com/goreleaser/goreleaser/pkg/context"
)
// Pipe for checksums.
type Pipe struct{}
func (Pipe) String() string {
return "snapshotting"
}
// Default sets the pipe defaults.
func (Pipe) Default(ctx *context.Context) error {
if ctx.Config.Snapshot.NameTemplate == "" {
ctx.Config.Snapshot.NameTemplate = "{{ .Tag }}-SNAPSHOT-{{ .ShortCommit }}"
}
return nil
}
2018-12-13 10:09:36 -02:00
func (Pipe) Run(ctx *context.Context) error {
if !ctx.Snapshot {
return pipe.ErrSkipDisabledPipe
2018-12-13 10:09:36 -02:00
}
name, err := tmpl.New(ctx).Apply(ctx.Config.Snapshot.NameTemplate)
if err != nil {
return fmt.Errorf("failed to generate snapshot name: %w", err)
2018-12-13 10:09:36 -02:00
}
if name == "" {
return fmt.Errorf("empty snapshot name")
}
ctx.Version = name
return nil
}