Skip to content

Commit

Permalink
Fix latest semver detection for release branches (#4388)
Browse files Browse the repository at this point in the history
  • Loading branch information
abhay-krishna authored Feb 28, 2025
1 parent a595125 commit 065f1e2
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions tools/version-tracker/pkg/util/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ func GetGoVersion(goBinaryLocation string) (string, error) {
}

func EnsurePatchVersion(version string) string {
hasLeadingV := (version[0] == 'v')
// Remove 'v' prefix if present
version = strings.TrimPrefix(version, "v")
if hasLeadingV {
version = strings.TrimPrefix(version, "v")
}

// Regular expression to match version components
re := regexp.MustCompile(`^(\d+\.\d+)(?:\.(\d+))?(.*)$`)
Expand All @@ -43,7 +46,11 @@ func EnsurePatchVersion(version string) string {

if patch == "" {
// If patch version is missing, add ".0"
return fmt.Sprintf("%s.0%s", majorMinor, metadata)
version = fmt.Sprintf("%s.0%s", majorMinor, metadata)
}

if hasLeadingV {
version = fmt.Sprintf("v%s", version)
}

// If patch version is present, return the original version
Expand Down

0 comments on commit 065f1e2

Please sign in to comment.