Skip to content

Commit

Permalink
Fix pre-release detection logic when fetching latest GitHub revision (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
abhay-krishna authored May 2, 2024
1 parent e82ea2a commit b58c152
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 24 deletions.
1 change: 1 addition & 0 deletions tools/version-tracker/pkg/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const (
AttributionsFilePattern = "*ATTRIBUTION.txt"
PatchesDirectory = "patches"
FailedPatchApplyMarker = "patch does not apply"
SemverRegex = `v?(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)(?:-(?P<prerelease>(?: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<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?`
FailedPatchApplyRegex = "Patch failed at .*"
FailedPatchFilesRegex = "error: (.*): patch does not apply"
BottlerocketReleasesFile = "BOTTLEROCKET_RELEASES"
Expand Down
36 changes: 12 additions & 24 deletions tools/version-tracker/pkg/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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]
Expand All @@ -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
}

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit b58c152

Please sign in to comment.