-
Notifications
You must be signed in to change notification settings - Fork 0
/
selfupdate.go
44 lines (37 loc) · 1.06 KB
/
selfupdate.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
package main
import (
"log"
"github.com/blang/semver"
"github.com/rhysd/go-github-selfupdate/selfupdate"
)
const version = "0.9.6"
func doSelfUpdate() bool {
v := semver.MustParse(version)
latest, err := selfupdate.UpdateSelf(v, "achhabra2/kqb-scoreboard")
if err != nil {
log.Println("Binary update failed:", err)
return false
}
if latest.Version.Equals(v) {
// latest version is the same as current version. It means current binary is up to date.
log.Println("Current binary is the latest version", version)
return true
} else {
log.Println("Successfully updated to version", latest.Version)
log.Println("Release note:\n", latest.ReleaseNotes)
return true
}
}
func checkForUpdate() (bool, string) {
latest, found, err := selfupdate.DetectLatest("achhabra2/kqb-scoreboard")
if err != nil {
log.Println("Error occurred while detecting version:", err)
return false, ""
}
v := semver.MustParse(version)
if !found || latest.Version.LTE(v) {
log.Println("Current version is the latest")
return false, ""
}
return true, latest.Version.String()
}