-
Notifications
You must be signed in to change notification settings - Fork 6
/
releaser.go
119 lines (85 loc) · 2.07 KB
/
releaser.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// +build ignore
package main
import (
"flag"
"fmt"
"html/template"
"io/ioutil"
"log"
"os"
"strings"
"time"
)
type versionInfo struct {
Major string
Minor string
Patch string
Year int
}
func main() {
versionCmd := flag.String("version", "0.0.0", `go run releaser.go -version="1.0.0" `)
flag.Parse()
versionArr := strings.Split(*versionCmd, ".")
if len(versionArr) < 3 {
log.Fatal("Incorrect version format provided")
}
year := time.Now().Year()
version := versionInfo{
Major: versionArr[0],
Minor: versionArr[1],
Patch: versionArr[2],
Year: year,
}
versionTemplateFile, err := ioutil.ReadFile("versioninfo.json.template")
if err != nil {
log.Fatal(err)
}
//Version Info file
versionInfoFileString := string(versionTemplateFile)
versionTemplate := template.New("Version")
versionTemplate, _ = versionTemplate.Parse(versionInfoFileString)
versionFile, err := os.Create("versioninfo.json")
if err != nil {
log.Fatal(err)
}
err = versionTemplate.Execute(versionFile, version)
if err != nil {
fmt.Println(err)
}
versionFile.Close()
//Release SVG shield for README.md
releaseSVGTemplateFile, err := ioutil.ReadFile("release.svg.template")
if err != nil {
log.Fatal(err)
}
releaseSVGString := string(releaseSVGTemplateFile)
svgTemplate := template.New("SVG")
svgTemplate, _ = svgTemplate.Parse(releaseSVGString)
releaseFile, err := os.Create("images/release.svg")
if err != nil {
log.Fatal(err)
}
err = svgTemplate.Execute(releaseFile, version)
if err != nil {
fmt.Println(err)
}
releaseFile.Close()
//App Version Package
versionGoTemplateFile, err := ioutil.ReadFile("version.go.template")
if err != nil {
log.Fatal(err)
}
versionGoString := string(versionGoTemplateFile)
versionGoTemplate := template.New("versionGo")
versionGoTemplate, _ = versionGoTemplate.Parse(versionGoString)
versionGoFile, err := os.Create("version/version.go")
if err != nil {
log.Fatal(err)
}
err = versionGoTemplate.Execute(versionGoFile, version)
if err != nil {
fmt.Println(err)
}
releaseFile.Close()
fmt.Println("done")
}