1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-10 03:47:03 +02:00
goreleaser/internal/pipe/semver/semver.go
Carlos Alexandro Becker 65ffbf1921
refactor: replace pkg/errors.Wrap with fmt.Errorf (#1812)
* refactor: remove pkg/errors

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

* refactor: remove pkg/errors

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2020-09-21 17:47:51 +00:00

43 lines
954 B
Go

package semver
import (
"fmt"
"github.com/Masterminds/semver/v3"
"github.com/apex/log"
"github.com/goreleaser/goreleaser/internal/pipe"
"github.com/goreleaser/goreleaser/pkg/context"
)
// Pipe is a global hook pipe.
type Pipe struct{}
// String is the name of this pipe.
func (Pipe) String() string {
return "parsing tag"
}
// 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 fmt.Errorf("failed to parse tag %s as semver: %w", ctx.Git.CurrentTag, err)
}
ctx.Semver = context.Semver{
Major: sv.Major(),
Minor: sv.Minor(),
Patch: sv.Patch(),
Prerelease: sv.Prerelease(),
}
return nil
}