2020-04-17 16:08:34 +02:00
|
|
|
// Package snapshot provides the snapshotting functionality to goreleaser.
|
2017-12-02 23:53:19 +02:00
|
|
|
package snapshot
|
|
|
|
|
2018-12-13 14:09:36 +02:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2022-06-22 02:11:15 +02:00
|
|
|
"github.com/caarlos0/log"
|
2018-12-13 14:09:36 +02:00
|
|
|
"github.com/goreleaser/goreleaser/internal/tmpl"
|
|
|
|
"github.com/goreleaser/goreleaser/pkg/context"
|
|
|
|
)
|
2017-12-02 23:53:19 +02:00
|
|
|
|
2020-05-26 05:48:10 +02:00
|
|
|
// Pipe for checksums.
|
2017-12-02 23:53:19 +02:00
|
|
|
type Pipe struct{}
|
|
|
|
|
2021-09-18 15:21:29 +02:00
|
|
|
func (Pipe) String() string { return "snapshotting" }
|
|
|
|
func (Pipe) Skip(ctx *context.Context) bool { return !ctx.Snapshot }
|
2017-12-02 23:53:19 +02:00
|
|
|
|
2020-05-26 05:48:10 +02:00
|
|
|
// Default sets the pipe defaults.
|
2017-12-02 23:53:19 +02:00
|
|
|
func (Pipe) Default(ctx *context.Context) error {
|
|
|
|
if ctx.Config.Snapshot.NameTemplate == "" {
|
2021-08-21 15:59:15 +02:00
|
|
|
ctx.Config.Snapshot.NameTemplate = "{{ .Version }}-SNAPSHOT-{{ .ShortCommit }}"
|
2017-12-02 23:53:19 +02:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2018-12-13 14:09:36 +02:00
|
|
|
|
|
|
|
func (Pipe) Run(ctx *context.Context) error {
|
|
|
|
name, err := tmpl.New(ctx).Apply(ctx.Config.Snapshot.NameTemplate)
|
|
|
|
if err != nil {
|
2020-09-21 19:47:51 +02:00
|
|
|
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
|
2021-07-24 15:13:05 +02:00
|
|
|
log.WithField("version", ctx.Version).Infof("building snapshot...")
|
2018-12-13 14:09:36 +02:00
|
|
|
return nil
|
|
|
|
}
|