Skip to content

Commit

Permalink
Filter out pre-release tags in upgrader flow (aws#3089)
Browse files Browse the repository at this point in the history
  • Loading branch information
abhay-krishna committed Jun 25, 2024
1 parent 2b55789 commit d9bb039
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions tools/version-tracker/pkg/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func getCommitsForRepo(client *github.Client, org, repo string) ([]*github.Repos
for {
commits, resp, err := client.Repositories.ListCommits(context.Background(), org, repo, listCommitOptions)
if err != nil {
return nil, fmt.Errorf("calling ListCommits for [%s/%s] repository: %v", org, repo, err)
return nil, fmt.Errorf("calling ListCommits API for [%s/%s] repository: %v", org, repo, err)
}
allCommits = append(allCommits, commits...)

Expand Down Expand Up @@ -148,6 +148,14 @@ func GetLatestRevision(client *github.Client, org, repo, currentRevision string,
continue
}
}
releaseForTag, _, err := client.Repositories.GetReleaseByTag(context.Background(), org, repo, tagName)
if err != nil {
return "", false, fmt.Errorf("calling GetReleaseByTag API for tag %s in [%s/%s] repository: %v", tagName, org, repo, err)
}
if *releaseForTag.Prerelease {
continue
}

latestRevision = tagName

// Determine if upgrade is required based on current and latest revisions
Expand All @@ -161,7 +169,7 @@ func GetLatestRevision(client *github.Client, org, repo, currentRevision string,
}
}
} else {
// If the project has neither Github releases nor tags, pick the latest commit.
// If the project does not have Github tags, pick the latest commit.
allCommits, err := getCommitsForRepo(client, org, repo)
if err != nil {
return "", false, fmt.Errorf("getting all commits for [%s/%s] repository: %v", org, repo, err)
Expand Down Expand Up @@ -202,7 +210,7 @@ func isUpgradeRequired(client *github.Client, org, repo, latestRevision string,

// If the latest revision comes after the current revision both chronologically and semantically, then declare that
// an upgrade is required
if latestRevisionCommitEpoch > currentRevisionCommitEpoch && latestRevisionSemver.GreaterThan(currentRevisionSemver) {
if latestRevisionSemver.GreaterThan(currentRevisionSemver) || latestRevisionCommitEpoch > currentRevisionCommitEpoch {
needsUpgrade = true
shouldBreak = true
} else if latestRevisionSemver.Equal(currentRevisionSemver) {
Expand Down Expand Up @@ -236,7 +244,7 @@ func GetGoVersionForLatestRevision(client *github.Client, org, repo, latestRevis
if _, ok := constants.ProjectReleaseAssets[projectFullName]; ok {
release, _, err := client.Repositories.GetReleaseByTag(context.Background(), org, repo, latestRevision)
if err != nil {
return "", fmt.Errorf("calling GetReleaseByTag for tag %s in [%s/%s] repository: %v", latestRevision, org, repo, err)
return "", fmt.Errorf("calling GetReleaseByTag API for tag %s in [%s/%s] repository: %v", latestRevision, org, repo, err)
}
var tarballName, tarballUrl string
projectReleaseAsset := constants.ProjectReleaseAssets[projectFullName]
Expand Down

0 comments on commit d9bb039

Please sign in to comment.