Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pre-release detection logic when fetching latest GitHub revision #3140

Merged
merged 1 commit into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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