mirror of
https://github.com/MedzikUser/go-github-selfupdate.git
synced 2024-08-15 03:25:29 +00:00
do not assume a descending order (fix #11)
for testing, v0.0.9 is added to test-release-tar repository. https://github.com/rhysd-test/test-release-tar/releases
This commit is contained in:
parent
7bcefbd709
commit
02a5d46e86
1 changed files with 20 additions and 7 deletions
|
@ -60,18 +60,31 @@ func findReleaseAndAsset(rels []*github.RepositoryRelease) (*github.RepositoryRe
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// var ver sermver.Version
|
var ver semver.Version
|
||||||
// var asset *github.ReleaseAsset
|
var asset *github.ReleaseAsset
|
||||||
// var release *github.RepositoryRelease
|
var release *github.RepositoryRelease
|
||||||
|
|
||||||
|
// Find the latest version from the list of releases.
|
||||||
|
// Returned list from GitHub API is in the order of the date when created.
|
||||||
|
// ref: https://github.com/rhysd/go-github-selfupdate/issues/11
|
||||||
for _, rel := range rels {
|
for _, rel := range rels {
|
||||||
if asset, ver, ok := findAssetFromReleasse(rel, suffixes); ok {
|
if a, v, ok := findAssetFromReleasse(rel, suffixes); ok {
|
||||||
return rel, asset, ver, true
|
// Note: any version with suffix is less than any version without suffix.
|
||||||
|
// e.g. 0.0.1 > 0.0.1-beta
|
||||||
|
if release == nil || v.GTE(ver) {
|
||||||
|
ver = v
|
||||||
|
asset = a
|
||||||
|
release = rel
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if release == nil {
|
||||||
log.Println("Could not find any release for", runtime.GOOS, "and", runtime.GOARCH)
|
log.Println("Could not find any release for", runtime.GOOS, "and", runtime.GOARCH)
|
||||||
return nil, nil, semver.Version{}, false
|
return nil, nil, semver.Version{}, false
|
||||||
|
}
|
||||||
|
|
||||||
|
return release, asset, ver, true
|
||||||
}
|
}
|
||||||
|
|
||||||
// DetectLatest tries to get the latest version of the repository on GitHub. 'slug' means 'owner/name' formatted string.
|
// DetectLatest tries to get the latest version of the repository on GitHub. 'slug' means 'owner/name' formatted string.
|
||||||
|
|
Loading…
Reference in a new issue