2021-09-18 10:21:29 -03:00
|
|
|
// Package milestone implements Pipe and manages VCS milestones.
|
2020-07-09 16:40:37 -04:00
|
|
|
package milestone
|
|
|
|
|
|
|
|
import (
|
2022-06-21 21:11:15 -03:00
|
|
|
"github.com/caarlos0/log"
|
2020-07-09 16:40:37 -04:00
|
|
|
"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{}
|
|
|
|
|
2021-09-18 10:21:29 -03:00
|
|
|
func (Pipe) String() string { return "milestones" }
|
2023-06-20 09:33:59 -03:00
|
|
|
func (Pipe) ContinueOnError() bool { return true }
|
2021-09-18 10:21:29 -03:00
|
|
|
func (Pipe) Skip(ctx *context.Context) bool { return len(ctx.Config.Milestones) == 0 }
|
2020-07-09 16:40:37 -04:00
|
|
|
|
|
|
|
// 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 == "" {
|
2022-04-12 08:35:19 -03:00
|
|
|
repo, err := git.ExtractRepoFromConfig(ctx)
|
2020-07-09 16:40:37 -04:00
|
|
|
if err != nil && !ctx.Snapshot {
|
2022-05-09 09:32:43 -03:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := repo.CheckSCM(); err != nil && !ctx.Snapshot {
|
2020-07-09 16:40:37 -04:00
|
|
|
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 {
|
2021-09-18 10:21:29 -03:00
|
|
|
return pipe.Skip("closing not enabled")
|
2020-07-09 16:40:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|