From 754e60fffa4a8e5e2ee44a39afeb6b02df8493b2 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sun, 5 Jan 2025 17:29:07 -0600 Subject: [PATCH] try to verify the tag is greater than the past tags --- currentVersions.go | 56 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 51 insertions(+), 5 deletions(-) diff --git a/currentVersions.go b/currentVersions.go index 624762e..9ad136f 100644 --- a/currentVersions.go +++ b/currentVersions.go @@ -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 -// 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) { tmp := normalizeVersion(version) parts := strings.Split(tmp, ".") switch len(parts) { case 1: - return parts[0], "", "" + return "", "", parts[0] // converts someone using version "57" to "v0.0.57" case 2: - return parts[0], parts[1], "" + return parts[0], parts[1], "" // converts someone using version "1.2" to "v1.2.0" default: 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 -func (repo *Repo) IncrementTargetRevision() { - lasttag := repo.GetLastTag() +func (repo *Repo) IncrementTargetRevision() bool { + // 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 major, minor, revision = splitVersion(lasttag) @@ -298,3 +320,27 @@ func (repo *Repo) IncrementTargetRevision() { 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 +}