try to verify the tag is greater than the past tags
This commit is contained in:
parent
80130ab563
commit
754e60fffa
|
@ -246,15 +246,19 @@ func normalizeVersion(s string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// golang doesn't seem to really support v0.1 and seems to want v0.1.0
|
// golang doesn't seem to really support v0.1 and seems to want v0.1.0
|
||||||
// todo: confirm this
|
// TODO: confirm this. (as of Dec 2024, this appears to be the case -- jcarr )
|
||||||
|
//
|
||||||
|
// personally I hope GO stays with the vX.X.X version scheme. it's a good system.
|
||||||
|
//
|
||||||
|
// if the version is "57", convert it to v0.0.57 for GO
|
||||||
func splitVersion(version string) (a, b, c string) {
|
func splitVersion(version string) (a, b, c string) {
|
||||||
tmp := normalizeVersion(version)
|
tmp := normalizeVersion(version)
|
||||||
parts := strings.Split(tmp, ".")
|
parts := strings.Split(tmp, ".")
|
||||||
switch len(parts) {
|
switch len(parts) {
|
||||||
case 1:
|
case 1:
|
||||||
return parts[0], "", ""
|
return "", "", parts[0] // converts someone using version "57" to "v0.0.57"
|
||||||
case 2:
|
case 2:
|
||||||
return parts[0], parts[1], ""
|
return parts[0], parts[1], "" // converts someone using version "1.2" to "v1.2.0"
|
||||||
default:
|
default:
|
||||||
return parts[0], parts[1], parts[2]
|
return parts[0], parts[1], parts[2]
|
||||||
}
|
}
|
||||||
|
@ -281,8 +285,26 @@ func (repo *Repo) IncrementTargetMinor() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// changes the target revision. v0.1.3 becomes v0.1.4
|
// changes the target revision. v0.1.3 becomes v0.1.4
|
||||||
func (repo *Repo) IncrementTargetRevision() {
|
func (repo *Repo) IncrementTargetRevision() bool {
|
||||||
lasttag := repo.GetLastTag()
|
// first try just going from the last tag
|
||||||
|
repo.incrementRevision(repo.GetLastTag())
|
||||||
|
|
||||||
|
if verifyNewerVersion(repo.GetMasterVersion(), repo.GetTargetVersion()) {
|
||||||
|
log.Info("master version() is higher than target version", repo.GetMasterVersion(), repo.GetTargetVersion())
|
||||||
|
repo.incrementRevision(repo.GetMasterVersion())
|
||||||
|
}
|
||||||
|
if verifyNewerVersion(repo.GetLastTag(), repo.GetTargetVersion()) {
|
||||||
|
log.Info("last tag versn() is higher than target version", repo.GetLastTag(), repo.GetTargetVersion())
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if verifyNewerVersion(repo.GetMasterVersion(), repo.GetTargetVersion()) {
|
||||||
|
log.Info("master version() is higher than target version", repo.GetMasterVersion(), repo.GetTargetVersion())
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (repo *Repo) incrementRevision(lasttag string) {
|
||||||
var major, minor, revision string
|
var major, minor, revision string
|
||||||
major, minor, revision = splitVersion(lasttag)
|
major, minor, revision = splitVersion(lasttag)
|
||||||
|
|
||||||
|
@ -298,3 +320,27 @@ func (repo *Repo) IncrementTargetRevision() {
|
||||||
|
|
||||||
repo.SetTargetVersion("v" + newa + "." + newb + "." + newc)
|
repo.SetTargetVersion("v" + newa + "." + newb + "." + newc)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// makes sure the new target version to be released is greater
|
||||||
|
// than the current master version
|
||||||
|
// this is just a sanity check, but this can actually fail sometimes
|
||||||
|
// if other things failed terribly in prior cases
|
||||||
|
// gitpb v.3.1.4
|
||||||
|
// A = major = 3
|
||||||
|
// B = minor = 1
|
||||||
|
// C = revision = 4
|
||||||
|
func verifyNewerVersion(oldver, newver string) bool {
|
||||||
|
olda, oldb, oldc := splitVersion(oldver)
|
||||||
|
newa, newb, newc := splitVersion(newver)
|
||||||
|
|
||||||
|
if newa < olda {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if newb < oldb {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if newc <= oldc {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue