-
Notifications
You must be signed in to change notification settings - Fork 39
/
version.go
64 lines (52 loc) · 1.33 KB
/
version.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
59
60
61
62
63
64
package main
import (
"bytes"
"fmt"
"time"
log "github.com/Sirupsen/logrus"
latest "github.com/tcnksm/go-latest"
)
// Name is application name
const Name = "walter"
// Version is application version
const Version string = "v2.0.0"
// GitCommit describes latest commit hash.
// This is automatically extracted by git describe --always.
var GitCommit string
const defaultCheckTimeout = 2 * time.Second
// OutputVersion display version number
func OutputVersion() string {
var buf bytes.Buffer
fmt.Fprintf(&buf, "%s version %s", Name, Version)
if len(GitCommit) != 0 {
fmt.Fprintf(&buf, " (%s)", GitCommit)
}
fmt.Fprintf(&buf, "\n")
// Check latest version is release or not.
verCheckCh := make(chan *latest.CheckResponse)
go func() {
fixFunc := latest.DeleteFrontV()
githubTag := &latest.GithubTag{
Owner: "walter-cd",
Repository: "walter",
FixVersionStrFunc: fixFunc,
}
res, err := latest.Check(githubTag, fixFunc(Version))
if err != nil {
// Don't return error
log.Debugf("[ERROR] Check lastet version is failed: %s", err)
return
}
verCheckCh <- res
}()
select {
case <-time.After(defaultCheckTimeout):
case res := <-verCheckCh:
if res.Outdated {
fmt.Fprintf(&buf,
"Latest version of walter is v%s, please upgrade!\n",
res.Current)
}
}
return buf.String()
}