1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-10 03:47:03 +02:00
goreleaser/internal/pipe/snapshot/snapshot.go

43 lines
1.0 KiB
Go
Raw Normal View History

// Package snapshot provides the snapshotting functionality to goreleaser.
package snapshot
2018-12-13 14:09:36 +02:00
import (
"fmt"
"github.com/apex/log"
2018-12-13 14:09:36 +02:00
"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 14:09:36 +02:00
func (Pipe) Run(ctx *context.Context) error {
if !ctx.Snapshot {
return pipe.ErrSkipDisabledPipe
2018-12-13 14: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 14:09:36 +02:00
}
if name == "" {
return fmt.Errorf("empty snapshot name")
}
ctx.Version = name
log.WithField("version", ctx.Version).Infof("building snapshot...")
2018-12-13 14:09:36 +02:00
return nil
}