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) +} diff --git a/goDep.redoGoMod.go b/goDep.redoGoMod.go index 6aeb298..8406fd4 100644 --- a/goDep.redoGoMod.go +++ b/goDep.redoGoMod.go @@ -83,7 +83,7 @@ func (repo *Repo) PublishedLen() int { } // returns true if the last published -func (all *Repos) GoDepsChanged(repo *Repo) (bool, error) { +func (all *Repos) GoDepsChangedOld(repo *Repo) (bool, error) { var upgrade bool = false if repo.GoDeps == nil { repo.RedoGoMod() diff --git a/isPrimitive.go b/isPrimitive.go index 6579013..3870343 100644 --- a/isPrimitive.go +++ b/isPrimitive.go @@ -1,5 +1,8 @@ package gitpb +// +// DOES NOT MODIFY FILES +// // only reads in the go.mod file. doesn't change anything import (