mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-01-10 03:47:03 +02:00
fe7e2123bd
* feat: replacing logs Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com> * fix: tests et al Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com> * feat: update termenv/lipgloss Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com> * wip: output Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com> * fix: pin dep Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com> * fix: update Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com> * fix: tests Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com> * fix: tests Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com> * fix: deps Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com> * fix: dep Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
92 lines
2.0 KiB
Go
92 lines
2.0 KiB
Go
// Package milestone implements Pipe and manages VCS milestones.
|
|
package milestone
|
|
|
|
import (
|
|
"github.com/caarlos0/log"
|
|
"github.com/goreleaser/goreleaser/internal/client"
|
|
"github.com/goreleaser/goreleaser/internal/git"
|
|
"github.com/goreleaser/goreleaser/internal/pipe"
|
|
"github.com/goreleaser/goreleaser/internal/tmpl"
|
|
"github.com/goreleaser/goreleaser/pkg/context"
|
|
)
|
|
|
|
const defaultNameTemplate = "{{ .Tag }}"
|
|
|
|
// Pipe for milestone.
|
|
type Pipe struct{}
|
|
|
|
func (Pipe) String() string { return "milestones" }
|
|
func (Pipe) Skip(ctx *context.Context) bool { return len(ctx.Config.Milestones) == 0 }
|
|
|
|
// Default sets the pipe defaults.
|
|
func (Pipe) Default(ctx *context.Context) error {
|
|
for i := range ctx.Config.Milestones {
|
|
milestone := &ctx.Config.Milestones[i]
|
|
|
|
if milestone.NameTemplate == "" {
|
|
milestone.NameTemplate = defaultNameTemplate
|
|
}
|
|
|
|
if milestone.Repo.Name == "" {
|
|
repo, err := git.ExtractRepoFromConfig(ctx)
|
|
if err != nil && !ctx.Snapshot {
|
|
return err
|
|
}
|
|
if err := repo.CheckSCM(); err != nil && !ctx.Snapshot {
|
|
return err
|
|
}
|
|
|
|
milestone.Repo = repo
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// Publish the release.
|
|
func (Pipe) Publish(ctx *context.Context) error {
|
|
c, err := client.New(ctx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return doPublish(ctx, c)
|
|
}
|
|
|
|
func doPublish(ctx *context.Context, vcsClient client.Client) error {
|
|
for i := range ctx.Config.Milestones {
|
|
milestone := &ctx.Config.Milestones[i]
|
|
|
|
if !milestone.Close {
|
|
return pipe.Skip("closing not enabled")
|
|
}
|
|
|
|
name, err := tmpl.New(ctx).Apply(milestone.NameTemplate)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
repo := client.Repo{
|
|
Name: milestone.Repo.Name,
|
|
Owner: milestone.Repo.Owner,
|
|
}
|
|
|
|
log.WithField("milestone", name).
|
|
WithField("repo", repo.String()).
|
|
Info("closing milestone")
|
|
|
|
err = vcsClient.CloseMilestone(ctx, repo, name)
|
|
|
|
if err != nil {
|
|
if milestone.FailOnError {
|
|
return err
|
|
}
|
|
|
|
log.WithField("milestone", name).
|
|
WithField("repo", repo.String()).
|
|
Warnf("error closing milestone: %s", err)
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|