diff --git a/tools/version-tracker/pkg/constants/constants.go b/tools/version-tracker/pkg/constants/constants.go index 19e22211fb..d523b9710f 100644 --- a/tools/version-tracker/pkg/constants/constants.go +++ b/tools/version-tracker/pkg/constants/constants.go @@ -32,6 +32,7 @@ const ( AttributionsFilePattern = "*ATTRIBUTION.txt" PatchesDirectory = "patches" FailedPatchApplyMarker = "patch does not apply" + SemverRegex = `v?(?P0|[1-9]\d*)\.(?P0|[1-9]\d*)\.(?P0|[1-9]\d*)(?:-(?P(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?P[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?` FailedPatchApplyRegex = "Patch failed at .*" FailedPatchFilesRegex = "error: (.*): patch does not apply" BottlerocketReleasesFile = "BOTTLEROCKET_RELEASES" diff --git a/tools/version-tracker/pkg/github/github.go b/tools/version-tracker/pkg/github/github.go index b7342cc935..6ccdd1257a 100644 --- a/tools/version-tracker/pkg/github/github.go +++ b/tools/version-tracker/pkg/github/github.go @@ -129,10 +129,9 @@ func GetLatestRevision(client *github.Client, org, repo, currentRevision string, latestRevision = *allCommits[0].SHA needsUpgrade = true } else { - currentRevisionForSemver := currentRevision - if org == "kubernetes" && repo == "autoscaler" { - currentRevisionForSemver = strings.ReplaceAll(currentRevisionForSemver, "cluster-autoscaler-", "") - } + semverRegex := regexp.MustCompile(constants.SemverRegex) + currentRevisionForSemver := semverRegex.FindString(currentRevision) + // Get SemVer construct corresponding to the current revision tag. currentRevisionSemver, err := semver.New(currentRevisionForSemver) if err != nil { @@ -141,17 +140,13 @@ func GetLatestRevision(client *github.Client, org, repo, currentRevision string, for _, tag := range allTags { tagName := *tag.Name - tagNameForSemver := tagName if org == "kubernetes" && repo == "autoscaler" { if !strings.HasPrefix(tagName, "cluster-autoscaler-") { continue } - tagNameForSemver = strings.ReplaceAll(tagNameForSemver, "cluster-autoscaler-", "") - } - semverRegex := regexp.MustCompile(`v?\d+\.\d+\.\d+`) - if !semverRegex.MatchString(tagNameForSemver) { - continue } + tagNameForSemver := semverRegex.FindString(tagName) + if releaseBranched { releaseBranch := os.Getenv(constants.ReleaseBranchEnvvar) releaseNumber := strings.Split(releaseBranch, "-")[1] @@ -160,18 +155,12 @@ func GetLatestRevision(client *github.Client, org, repo, currentRevision string, continue } } - releaseForTag, _, err := client.Repositories.GetReleaseByTag(context.Background(), org, repo, tagName) - preRelease := false + + revisionSemver, err := semver.New(tagNameForSemver) if err != nil { - if strings.Contains(err.Error(), "404 Not Found") { - preRelease = false - } else { - return "", false, fmt.Errorf("calling GetReleaseByTag API for tag %s in [%s/%s] repository: %v", tagName, org, repo, err) - } - } else { - preRelease = *releaseForTag.Prerelease + return "", false, fmt.Errorf("getting semver for the version under consideration: %v", err) } - if preRelease { + if revisionSemver.Prerelease != "" { continue } @@ -209,10 +198,9 @@ func isUpgradeRequired(client *github.Client, org, repo, latestRevision string, return false, false, fmt.Errorf("getting epoch time corresponding to latest revision commit: %v", err) } - latestRevisionForSemver := latestRevision - if org == "kubernetes" && repo == "autoscaler" { - latestRevisionForSemver = strings.ReplaceAll(latestRevisionForSemver, "cluster-autoscaler-", "") - } + semverRegex := regexp.MustCompile(constants.SemverRegex) + latestRevisionForSemver := semverRegex.FindString(latestRevision) + // Get SemVer construct corresponding to the latest revision tag. latestRevisionSemver, err := semver.New(latestRevisionForSemver) if err != nil {