forked from tcnksm/ghr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
version.go
56 lines (43 loc) · 1.24 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
package main
import (
"os"
"strconv"
"time"
"github.com/tcnksm/go-latest"
)
const Name = "ghr"
const Version string = "v0.4.0"
// Describe latest commit hash.
// This is automatically extracted by git describe --always.
var GitCommit string = ""
// verCheckCh is channel which gets go-latest.Response
var verCheckCh = make(chan *latest.CheckResponse)
// CheckTimeout is timeout of go-latest.Check executiom
var CheckTimeout time.Duration
// defaultCheckTimeout is default timeout of go-latest.Check
// execution.
var defaultCheckTimeout = 2 * time.Second
// envCheckTimeout is environmental varible to
// set go-latest.Check execution timeout.
const envCheckTimeout = "GHR_CHECK_WAIT"
func init() {
CheckTimeout = defaultCheckTimeout
if timeStr := os.Getenv(envCheckTimeout); timeStr != "" {
t, err := strconv.Atoi(timeStr)
// If wait to conv, ignore env value
if err == nil {
CheckTimeout = time.Duration(t)
}
}
go func() {
fixFunc := latest.DeleteFrontV()
githubTag := &latest.GithubTag{
Owner: "tcnksm",
Repository: "ghr",
FixVersionStrFunc: fixFunc,
}
// Ignore error, because it's not important for ghr fucntion
res, _ := latest.Check(githubTag, fixFunc(Version))
verCheckCh <- res
}()
}