-
Notifications
You must be signed in to change notification settings - Fork 35
/
updatebuildno.go
62 lines (52 loc) · 1.04 KB
/
updatebuildno.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
package main
import (
"log"
"os"
"io/ioutil"
"time"
"strconv"
"regexp"
"fmt"
)
func main() {
f, err := os.OpenFile("src/buildno/buildno.go", os.O_RDWR, 0755)
if err != nil {
log.Fatal(err)
}
defer f.Close()
if _, err := f.Seek(0, 0); err != nil {
log.Fatal(err)
}
data, err := ioutil.ReadAll(f)
if err != nil {
log.Fatal(err)
}
var buildNo int64
if ma := regexp.MustCompile(`BuildNo\s*=\s*"(\d+)"`).FindSubmatch(data); len(ma) > 0 {
buildNo, err = strconv.ParseInt(string(ma[1]), 10, 64)
if err != nil {
log.Fatal(err)
}
} else {
log.Fatal("BuildNo not match")
}
buildNo++
var now = time.Now()
buildDate := fmt.Sprintf("%04d%02d%02d",
now.Year(),
now.Month(),
now.Day(),
)
fmt.Printf("%v.%v\n", buildDate, buildNo)
if _, err := f.Seek(0, 0); err != nil {
log.Fatal(err)
}
if err := f.Truncate(0); err != nil {
log.Fatal(err)
}
f.WriteString(fmt.Sprintf(`
package buildno
var BuildDate = "%s"
var BuildNo = "%d"
`, buildDate, buildNo))
}