mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-16 17:09:28 +08:00
fix: updating from pre to release
This commit is contained in:
parent
79ac4c1d45
commit
02199bbe9d
@ -1,6 +1,8 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/masterminds/semver"
|
||||
)
|
||||
|
||||
@ -50,6 +52,30 @@ func (s *SemanticVersion) IsGreaterThan(version *SemanticVersion) (bool, error)
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// IsGreaterThanOrEqual returns true if this version is greater than or equal the given version
|
||||
func (s *SemanticVersion) IsGreaterThanOrEqual(version *SemanticVersion) (bool, error) {
|
||||
// Set up new constraint
|
||||
constraint, err := semver.NewConstraint(">= " + version.Version.String())
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
// Check if the desired one is greater than the requested on
|
||||
success, msgs := constraint.Validate(s.Version)
|
||||
if !success {
|
||||
return false, msgs[0]
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// MainVersion returns the main version of any version+prerelease+metadata
|
||||
// EG: MainVersion("1.2.3-pre") => "1.2.3"
|
||||
func (s *SemanticVersion) MainVersion() *SemanticVersion {
|
||||
mainVersion := fmt.Sprintf("%d.%d.%d", s.Version.Major(), s.Version.Minor(), s.Version.Patch())
|
||||
result, _ := NewSemanticVersion(mainVersion)
|
||||
return result
|
||||
}
|
||||
|
||||
// SemverCollection is a collection of SemanticVersion objects
|
||||
type SemverCollection []*SemanticVersion
|
||||
|
||||
|
@ -80,6 +80,8 @@ func init() {
|
||||
|
||||
func updateToVersion(targetVersion *cmd.SemanticVersion, force bool) error {
|
||||
|
||||
var targetVersionString = "v" + targetVersion.String()
|
||||
|
||||
// Early exit
|
||||
if targetVersion.String() == cmd.Version {
|
||||
logger.Green("Looks like you're up to date!")
|
||||
@ -97,16 +99,28 @@ func updateToVersion(targetVersion *cmd.SemanticVersion, force bool) error {
|
||||
return err
|
||||
}
|
||||
|
||||
var success bool
|
||||
|
||||
// Release -> Pre-Release = Massage current version to prerelease format
|
||||
if targetVersion.IsPreRelease() && currentVersion.IsRelease() {
|
||||
currentVersion, err = cmd.NewSemanticVersion(compareVersion + "-0")
|
||||
currentVersion, err = cmd.NewSemanticVersion(compareVersion)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
success, err = targetVersion.IsGreaterThan(currentVersion)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
// Pre-Release -> Release = Massage target version to prerelease format
|
||||
if targetVersion.IsRelease() && currentVersion.IsPreRelease() {
|
||||
targetVersion, err = cmd.NewSemanticVersion(targetVersion.String() + "-0")
|
||||
// We are ok with greater than or equal
|
||||
mainversion := currentVersion.MainVersion()
|
||||
targetVersion, err = cmd.NewSemanticVersion(targetVersion.String())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
success, err = targetVersion.IsGreaterThanOrEqual(mainversion)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -115,10 +129,9 @@ func updateToVersion(targetVersion *cmd.SemanticVersion, force bool) error {
|
||||
desiredVersion = "v" + targetVersion.String()
|
||||
|
||||
// Compare
|
||||
success, err := targetVersion.IsGreaterThan(currentVersion)
|
||||
if !success {
|
||||
logger.Red("The requested version is lower than the current version.")
|
||||
logger.Red("If this is what you really want to do, use `wails update -version %s`", desiredVersion)
|
||||
logger.Red("If this is what you really want to do, use `wails update -version %s`", targetVersionString)
|
||||
return nil
|
||||
}
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user