Skip to content

Commit

Permalink
simplify condition to skip prerelease and versions with metadata
Browse files Browse the repository at this point in the history
print warning on error and non-semver version tag

Signed-off-by: Anton Troshin <[email protected]>
  • Loading branch information
antontroshin committed Nov 22, 2024
1 parent 74e4d6f commit 3a4e423
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions pkg/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,22 +119,18 @@ func GetLatestReleaseGithub(githubURL string) (string, error) {
latestVersion := defaultVersion

for _, release := range githubRepoReleases {
if !strings.Contains(release.TagName, "-rc") {
cur, err := version.NewVersion(strings.TrimPrefix(release.TagName, "v"))
if err != nil {
if strings.HasPrefix(err.Error(), "Malformed version") {
continue
}
return "", err
}
// just a safety check to make sure we don't get a nil version.
// all errors should be handled above.
if cur == nil {
continue
}
if cur.GreaterThan(latestVersion) {
latestVersion = cur
}
cur, err := version.NewVersion(strings.TrimPrefix(release.TagName, "v"))
if err != nil || cur == nil {
print.WarningStatusEvent(os.Stdout, "Malformed version %s, skipping", release.TagName)
continue
}
// Prerelease versions and versions with metadata are skipped.
if cur.Prerelease() != "" || cur.Metadata() != "" {
continue
}

if cur.GreaterThan(latestVersion) {
latestVersion = cur
}
}

Expand Down

0 comments on commit 3a4e423

Please sign in to comment.