2020-04-17 07:08:34 -07:00
|
|
|
// Package snapshot provides the snapshotting functionality to goreleaser.
|
2017-12-02 19:53:19 -02:00
|
|
|
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"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
2017-12-02 19:53:19 -02:00
|
|
|
|
2020-05-26 00:48:10 -03:00
|
|
|
// Pipe for checksums.
|
2017-12-02 19:53:19 -02:00
|
|
|
type Pipe struct{}
|
|
|
|
|
|
|
|
func (Pipe) String() string {
|
2020-04-17 07:08:34 -07:00
|
|
|
return "snapshotting"
|
2017-12-02 19:53:19 -02:00
|
|
|
}
|
|
|
|
|
2020-05-26 00:48:10 -03:00
|
|
|
// Default sets the pipe defaults.
|
2017-12-02 19:53:19 -02:00
|
|
|
func (Pipe) Default(ctx *context.Context) error {
|
|
|
|
if ctx.Config.Snapshot.NameTemplate == "" {
|
2019-11-15 18:23:25 -03:00
|
|
|
ctx.Config.Snapshot.NameTemplate = "{{ .Tag }}-SNAPSHOT-{{ .ShortCommit }}"
|
2017-12-02 19:53:19 -02:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2018-12-13 10:09:36 -02:00
|
|
|
|
|
|
|
func (Pipe) Run(ctx *context.Context) error {
|
|
|
|
if !ctx.Snapshot {
|
|
|
|
return pipe.Skip("not a snapshot")
|
|
|
|
}
|
|
|
|
name, err := tmpl.New(ctx).Apply(ctx.Config.Snapshot.NameTemplate)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "failed to generate snapshot name")
|
|
|
|
}
|
|
|
|
if name == "" {
|
|
|
|
return fmt.Errorf("empty snapshot name")
|
|
|
|
}
|
|
|
|
ctx.Version = name
|
|
|
|
return nil
|
|
|
|
}
|