summaryrefslogtreecommitdiff
path: root/currentVersions.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-01-05 17:29:07 -0600
committerJeff Carr <[email protected]>2025-01-05 17:29:07 -0600
commit754e60fffa4a8e5e2ee44a39afeb6b02df8493b2 (patch)
treedc766f4b6579c95cb9b9096f84df12c2b28682a7 /currentVersions.go
parent80130ab563179561d453fe4e5c00671bab6bc72d (diff)
try to verify the tag is greater than the past tags
Diffstat (limited to 'currentVersions.go')
-rw-r--r--currentVersions.go56
1 files 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
+}