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 (
|
2024-11-18 19:07:22 +02:00
|
|
|
"errors"
|
2018-12-13 10:09:36 -02:00
|
|
|
"fmt"
|
|
|
|
|
2022-06-21 21:11:15 -03:00
|
|
|
"github.com/caarlos0/log"
|
2024-07-29 08:21:00 -04:00
|
|
|
"github.com/goreleaser/goreleaser/v2/internal/deprecate"
|
2024-05-26 15:02:57 -03:00
|
|
|
"github.com/goreleaser/goreleaser/v2/internal/tmpl"
|
|
|
|
"github.com/goreleaser/goreleaser/v2/pkg/context"
|
2018-12-13 10:09:36 -02:00
|
|
|
)
|
2017-12-02 19:53:19 -02:00
|
|
|
|
2023-08-15 12:29:37 +00:00
|
|
|
// Pipe for setting up the snapshot feature..
|
2017-12-02 19:53:19 -02:00
|
|
|
type Pipe struct{}
|
|
|
|
|
2021-09-18 10:21:29 -03:00
|
|
|
func (Pipe) String() string { return "snapshotting" }
|
|
|
|
func (Pipe) Skip(ctx *context.Context) bool { return !ctx.Snapshot }
|
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 {
|
2024-07-29 08:21:00 -04:00
|
|
|
if ctx.Config.Snapshot.VersionTemplate == "" {
|
|
|
|
ctx.Config.Snapshot.VersionTemplate = "{{ .Version }}-SNAPSHOT-{{ .ShortCommit }}"
|
|
|
|
}
|
|
|
|
if ctx.Config.Snapshot.NameTemplate != "" {
|
|
|
|
deprecate.Notice(ctx, "snapshot.name_template")
|
|
|
|
ctx.Config.Snapshot.VersionTemplate = ctx.Config.Snapshot.NameTemplate
|
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 {
|
2024-07-29 08:21:00 -04:00
|
|
|
name, err := tmpl.New(ctx).Apply(ctx.Config.Snapshot.VersionTemplate)
|
2018-12-13 10:09:36 -02:00
|
|
|
if err != nil {
|
2023-08-15 12:29:37 +00:00
|
|
|
return fmt.Errorf("failed to parse snapshot name: %w", err)
|
2018-12-13 10:09:36 -02:00
|
|
|
}
|
|
|
|
if name == "" {
|
2024-11-18 19:07:22 +02:00
|
|
|
return errors.New("empty snapshot name")
|
2018-12-13 10:09:36 -02:00
|
|
|
}
|
|
|
|
ctx.Version = name
|
2021-07-24 10:13:05 -03:00
|
|
|
log.WithField("version", ctx.Version).Infof("building snapshot...")
|
2018-12-13 10:09:36 -02:00
|
|
|
return nil
|
|
|
|
}
|