semantically bump version.txt for alskartv with rollover
This commit is contained in:
parent
d4de0f0a1d
commit
47d5112e7b
3 changed files with 47 additions and 3 deletions
BIN
api-server
BIN
api-server
Binary file not shown.
4
main.go
4
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="):
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue