-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvercmp.go
58 lines (44 loc) · 1.12 KB
/
vercmp.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"log"
"sort"
"strings"
"github.com/Masterminds/semver"
"github.com/pkg/errors"
)
func sortMakeVersionTags(tags []TagReply) []*semver.Version {
var vs []*semver.Version
for _, r := range tags {
v := strings.Replace(r.Name, "v", "", 1)
ver, err := semver.NewVersion(v)
if err != nil {
err = errors.Wrapf(err, "WARNING: error parsing version: %s", v)
log.Println(err)
continue
}
// vs[i] = ver
vs = append(vs, ver)
}
sort.Sort(sort.Reverse(semver.Collection(vs)))
return vs
}
func IsNewer(recent, current Version) bool {
if recent.Version == "" || current.Version == "" {
return false
}
recentVer, err := semver.NewVersion(recent.Version)
if err != nil {
err = errors.Wrapf(err, "failed to parse (%s) recent version: %s", recent.Name, recent.Version)
log.Println(err)
return false
}
currentVer, err := semver.NewVersion(current.Version)
if err != nil {
if current.Version != "" {
err = errors.Wrapf(err, "failed to parse (%s) current version: %s", current.Name, current.Version)
log.Println(err)
}
return true
}
return recentVer.GreaterThan(currentVer)
}