2019-01-19 16:57:58 -02:00
|
|
|
package semver
|
|
|
|
|
|
|
|
import (
|
2019-10-06 12:39:53 -03:00
|
|
|
"github.com/Masterminds/semver/v3"
|
2019-01-19 16:57:58 -02:00
|
|
|
"github.com/apex/log"
|
|
|
|
"github.com/goreleaser/goreleaser/internal/pipe"
|
|
|
|
"github.com/goreleaser/goreleaser/pkg/context"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Pipe is a global hook pipe
|
|
|
|
type Pipe struct{}
|
|
|
|
|
|
|
|
// String is the name of this pipe
|
|
|
|
func (Pipe) String() string {
|
2020-03-06 01:25:09 -03:00
|
|
|
return "parsing tag"
|
2019-01-19 16:57:58 -02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Run executes the hooks
|
|
|
|
func (Pipe) Run(ctx *context.Context) error {
|
|
|
|
sv, err := semver.NewVersion(ctx.Git.CurrentTag)
|
|
|
|
if err != nil {
|
|
|
|
if ctx.Snapshot {
|
|
|
|
return pipe.ErrSnapshotEnabled
|
|
|
|
}
|
|
|
|
if ctx.SkipValidate {
|
|
|
|
log.WithError(err).
|
|
|
|
WithField("tag", ctx.Git.CurrentTag).
|
|
|
|
Warn("current tag is not a semantic tag")
|
|
|
|
return pipe.ErrSkipValidateEnabled
|
|
|
|
}
|
|
|
|
return errors.Wrapf(err, "failed to parse tag %s as semver", ctx.Git.CurrentTag)
|
|
|
|
}
|
|
|
|
ctx.Semver = context.Semver{
|
|
|
|
Major: sv.Major(),
|
|
|
|
Minor: sv.Minor(),
|
|
|
|
Patch: sv.Patch(),
|
|
|
|
Prerelease: sv.Prerelease(),
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|