mirror of https://github.com/dapr/cli.git
Add version parsing check skip malformed versions and avoid panic (#1469)
* Add version parsing check skip malformed versions and avoid panic Signed-off-by: Anton Troshin <anton@diagrid.io> * lint Signed-off-by: Anton Troshin <anton@diagrid.io> * do not return error on nil, skip bad versions Signed-off-by: Anton Troshin <anton@diagrid.io> * 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> --------- Signed-off-by: Anton Troshin <anton@diagrid.io>
This commit is contained in:
parent
6d5e64d964
commit
25d9ece42f
|
@ -119,11 +119,18 @@ func GetLatestReleaseGithub(githubURL string) (string, error) {
|
||||||
latestVersion := defaultVersion
|
latestVersion := defaultVersion
|
||||||
|
|
||||||
for _, release := range githubRepoReleases {
|
for _, release := range githubRepoReleases {
|
||||||
if !strings.Contains(release.TagName, "-rc") {
|
cur, err := version.NewVersion(strings.TrimPrefix(release.TagName, "v"))
|
||||||
cur, _ := version.NewVersion(strings.TrimPrefix(release.TagName, "v"))
|
if err != nil || cur == nil {
|
||||||
if cur.GreaterThan(latestVersion) {
|
print.WarningStatusEvent(os.Stdout, "Malformed version %s, skipping", release.TagName)
|
||||||
latestVersion = cur
|
continue
|
||||||
}
|
}
|
||||||
|
// Prerelease versions and versions with metadata are skipped.
|
||||||
|
if cur.Prerelease() != "" || cur.Metadata() != "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if cur.GreaterThan(latestVersion) {
|
||||||
|
latestVersion = cur
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -162,6 +162,52 @@ func TestGetVersionsGithub(t *testing.T) {
|
||||||
"no releases",
|
"no releases",
|
||||||
"",
|
"",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"Malformed version no releases",
|
||||||
|
"/malformed_version_no_releases",
|
||||||
|
`[
|
||||||
|
{
|
||||||
|
"url": "https://api.github.com/repos/dapr/dapr/releases/186741665",
|
||||||
|
"html_url": "https://github.com/dapr/dapr/releases/tag/vedge",
|
||||||
|
"id": 186741665,
|
||||||
|
"tag_name": "vedge",
|
||||||
|
"target_commitish": "master",
|
||||||
|
"name": "Dapr Runtime vedge",
|
||||||
|
"draft": false,
|
||||||
|
"prerelease": false
|
||||||
|
}
|
||||||
|
] `,
|
||||||
|
"no releases",
|
||||||
|
"",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Malformed version with latest",
|
||||||
|
"/malformed_version_with_latest",
|
||||||
|
`[
|
||||||
|
{
|
||||||
|
"url": "https://api.github.com/repos/dapr/dapr/releases/186741665",
|
||||||
|
"html_url": "https://github.com/dapr/dapr/releases/tag/vedge",
|
||||||
|
"id": 186741665,
|
||||||
|
"tag_name": "vedge",
|
||||||
|
"target_commitish": "master",
|
||||||
|
"name": "Dapr Runtime vedge",
|
||||||
|
"draft": false,
|
||||||
|
"prerelease": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "https://api.github.com/repos/dapr/dapr/releases/44766923",
|
||||||
|
"html_url": "https://github.com/dapr/dapr/releases/tag/v1.5.1",
|
||||||
|
"id": 44766923,
|
||||||
|
"tag_name": "v1.5.1",
|
||||||
|
"target_commitish": "master",
|
||||||
|
"name": "Dapr Runtime v1.5.1",
|
||||||
|
"draft": false,
|
||||||
|
"prerelease": false
|
||||||
|
}
|
||||||
|
] `,
|
||||||
|
"",
|
||||||
|
"1.5.1",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
m := http.NewServeMux()
|
m := http.NewServeMux()
|
||||||
s := http.Server{Addr: ":12345", Handler: m, ReadHeaderTimeout: time.Duration(5) * time.Second}
|
s := http.Server{Addr: ":12345", Handler: m, ReadHeaderTimeout: time.Duration(5) * time.Second}
|
||||||
|
|
Loading…
Reference in New Issue