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

Add version parsing check skip malformed versions and avoid panic #1469

Merged
merged 4 commits into from
Nov 22, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
simplify condition to skip prerelease and versions with metadata
print warning on error and non-semver version tag

Signed-off-by: Anton Troshin <anton@diagrid.io>
antontroshin committed Nov 22, 2024

Unverified

The committer email address is not verified.
commit 3a4e423340da128836a4c9a36cedf3c37a94acb2
28 changes: 12 additions & 16 deletions pkg/version/version.go
Original file line number Diff line number Diff line change
@@ -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
}
}