github.com/amane3/goreleaser@v0.182.0/internal/pipe/semver/semver.go (about) 1 package semver 2 3 import ( 4 "fmt" 5 6 "github.com/Masterminds/semver/v3" 7 "github.com/amane3/goreleaser/internal/pipe" 8 "github.com/amane3/goreleaser/pkg/context" 9 "github.com/apex/log" 10 ) 11 12 // Pipe is a global hook pipe. 13 type Pipe struct{} 14 15 // String is the name of this pipe. 16 func (Pipe) String() string { 17 return "parsing tag" 18 } 19 20 // Run executes the hooks. 21 func (Pipe) Run(ctx *context.Context) error { 22 sv, err := semver.NewVersion(ctx.Git.CurrentTag) 23 if err != nil { 24 if ctx.Snapshot { 25 return pipe.ErrSnapshotEnabled 26 } 27 if ctx.SkipValidate { 28 log.WithError(err). 29 WithField("tag", ctx.Git.CurrentTag). 30 Warn("current tag is not a semantic tag") 31 return pipe.ErrSkipValidateEnabled 32 } 33 return fmt.Errorf("failed to parse tag %s as semver: %w", ctx.Git.CurrentTag, err) 34 } 35 ctx.Semver = context.Semver{ 36 Major: sv.Major(), 37 Minor: sv.Minor(), 38 Patch: sv.Patch(), 39 Prerelease: sv.Prerelease(), 40 } 41 return nil 42 }