summaryrefslogtreecommitdiff
path: root/currentVersions.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-12-12 02:07:25 -0600
committerJeff Carr <[email protected]>2024-12-12 02:07:25 -0600
commitadddfad2b7418dcaec4bd6c97219b72774fe0cac (patch)
tree1ca72792c1aa77374685482222c5bb7aca8e8f56 /currentVersions.go
parenta0b6a435a7c9789f0972321468c5d9a6c19444d2 (diff)
increment target version
Diffstat (limited to 'currentVersions.go')
-rw-r--r--currentVersions.go72
1 files changed, 72 insertions, 0 deletions
diff --git a/currentVersions.go b/currentVersions.go
index b9329f6..9026149 100644
--- a/currentVersions.go
+++ b/currentVersions.go
@@ -6,6 +6,8 @@ package gitpb
import (
"errors"
"path/filepath"
+ "regexp"
+ "strconv"
"strings"
"unicode"
@@ -217,3 +219,73 @@ func trimNonNumericFromStart(s string) string {
}
return ""
}
+
+func normalizeVersion(s string) string {
+ // reg, err := regexp.Compile("[^a-zA-Z0-9]+")
+ parts := strings.Split(s, "-")
+ if len(parts) == 0 {
+ return ""
+ }
+ reg, err := regexp.Compile("[^0-9.]+")
+ if err != nil {
+ log.Log(GITPBWARN, "normalizeVersion() regexp.Compile() ERROR =", err)
+ return parts[0]
+ }
+ clean := reg.ReplaceAllString(parts[0], "")
+ log.Log(GITPB, "normalizeVersion() s =", clean)
+ return clean
+}
+
+// golang doesn't seem to really support v0.1 and seems to want v0.1.0
+// todo: confirm this
+func splitVersion(version string) (a, b, c string) {
+ tmp := normalizeVersion(version)
+ parts := strings.Split(tmp, ".")
+ switch len(parts) {
+ case 1:
+ return parts[0], "", ""
+ case 2:
+ return parts[0], parts[1], ""
+ default:
+ return parts[0], parts[1], parts[2]
+ }
+}
+
+// changes the target minor. v0.1.3 becomes v0.2.0
+func (repo *Repo) IncrementTargetMinor() {
+ lasttag := repo.GetLastTag()
+ var major, minor, revision string
+ major, minor, revision = splitVersion(lasttag)
+
+ olda, _ := strconv.Atoi(major)
+ oldb, _ := strconv.Atoi(minor)
+ oldc, _ := strconv.Atoi(revision)
+
+ oldb += 1
+ oldc = 0
+
+ newa := strconv.Itoa(olda)
+ newb := strconv.Itoa(oldb)
+ newc := strconv.Itoa(oldc)
+
+ repo.SetTargetVersion("v" + newa + "." + newb + "." + newc)
+}
+
+// changes the target revision. v0.1.3 becomes v0.1.4
+func (repo *Repo) IncrementTargetRevision() {
+ lasttag := repo.GetLastTag()
+ var major, minor, revision string
+ major, minor, revision = splitVersion(lasttag)
+
+ olda, _ := strconv.Atoi(major)
+ oldb, _ := strconv.Atoi(minor)
+ oldc, _ := strconv.Atoi(revision)
+
+ oldc += 1
+
+ newa := strconv.Itoa(olda)
+ newb := strconv.Itoa(oldb)
+ newc := strconv.Itoa(oldc)
+
+ repo.SetTargetVersion("v" + newa + "." + newb + "." + newc)
+}