diff --git a/api-server b/api-server index e17ed64..e7b52ad 100755 Binary files a/api-server and b/api-server differ diff --git a/main.go b/main.go index 4efdb3c..a2026bd 100644 --- a/main.go +++ b/main.go @@ -14,12 +14,10 @@ import ( func updateVersion(repoPath string, serviceName string) error { versionPath := fmt.Sprintf("%s/version.txt", repoPath) - //versionFile := "version.txt" newVersion := getVersion(serviceName) if serviceName == "alaskartv" { versionPath = fmt.Sprintf("%s/release.txt", repoPath) - //versionFile = "release.txt" bumpVersionTv(repoPath) } @@ -54,7 +52,7 @@ func bumpVersionTv(repoPath string) { case strings.HasPrefix(line, "VERSION_NAME="): parts := strings.Split(line, "=") currentPatch := parts[1] - newVersion, _ := Bump(currentPatch, "patch") + newVersion, _ := BumpWithRollover(currentPatch, "patch") updatedContent += fmt.Sprintf("VERSION_NAME=%s\n", newVersion) case strings.HasPrefix(line, "VERSION_CODE="): diff --git a/semverbump.go b/semverbump.go index 39e1d8b..e92f0c0 100644 --- a/semverbump.go +++ b/semverbump.go @@ -75,3 +75,49 @@ func majorMinorPatchFromSemVer(semVer string) (int, int, int) { func semVerFromMajorMinorPatch(major, minor, patch int) string { return "v" + strconv.Itoa(major) + "." + strconv.Itoa(minor) + "." + strconv.Itoa(patch) } + +func BumpWithRollover(currentVersion, bumpType string) (string, error) { + if currentVersion == "" { + currentVersion = "v0.0.0" + } else { + if !semver.IsValid(currentVersion) { + if semver.IsValid("v" + currentVersion) { + currentVersion = "v" + currentVersion + } else { + return "", fmt.Errorf("invalid semVer tag '%s'", currentVersion) + } + } + if currentVersion == semver.Major(currentVersion) { + currentVersion = currentVersion + ".0.0" + } + if currentVersion == semver.MajorMinor(currentVersion) { + currentVersion = currentVersion + ".0" + } + } + + major, minor, patch := majorMinorPatchFromSemVer(currentVersion) + + switch bumpType { + case "major": + major++ + minor = 0 + patch = 0 + + case "minor": + minor++ + patch = 0 + + case "patch": + patch++ + // Handle rollover if patch reaches 10 (custom logic) + if patch >= 10 { + patch = 0 + minor++ + } + + default: + return "", fmt.Errorf("invalid bump type, expected 'major', 'minor' or 'patch', got '%s'", bumpType) + } + + return semVerFromMajorMinorPatch(major, minor, patch), nil +}