/
main.go
48 lines (40 loc) · 872 Bytes
/
main.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
package main
import (
"bytes"
"fmt"
"os"
"os/exec"
"strings"
"github.com/blang/semver"
)
func main() {
var (
e error
l string
versionList semver.Versions
)
exec.Command("git", "fetch", "--tags").Run()
cmd := exec.Command("git", "tag", "-l")
b, _ := cmd.Output()
bfr := bytes.NewBuffer(b)
for e == nil {
l, e = bfr.ReadString('\n')
if v, ve := semver.Make(strings.Replace(strings.TrimSpace(l), "v", "", -1)); ve == nil {
versionList = append(versionList, v)
}
}
semver.Sort(versionList)
currentVersion := versionList[len(versionList)-1]
switch os.Args[1] {
case "bump_patch":
currentVersion.Patch++
case "bump_minor":
currentVersion.Patch = 0
currentVersion.Minor++
case "bump_major":
currentVersion.Patch = 0
currentVersion.Minor = 0
currentVersion.Major++
}
fmt.Printf("v%s", currentVersion)
}