-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathversion.go
64 lines (51 loc) · 1.37 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 (
"fmt"
"strconv"
"strings"
"github.com/Masterminds/semver"
)
func incrementMajor(version string) string {
parsedVersion := parse(version)
newVersion := parsedVersion.IncMajor()
return newVersion.String()
}
func incrementMinor(version string) string {
parsedVersion := parse(version)
newVersion := parsedVersion.IncMinor()
return newVersion.String()
}
func incrementPatch(version string) string {
parsedVersion := parse(version)
newVersion := parsedVersion.IncPatch()
return newVersion.String()
}
func parse(version string) *semver.Version {
if !isVersion(version) {
segments := strings.Split(version, ".")
version = fmt.Sprintf("%v.%v.%v", segments[0], segments[1], segments[2])
}
parsedVersion, err := semver.NewVersion(version)
check(err)
return parsedVersion
}
func isVersion(version string) bool {
_, err := semver.NewVersion(version)
if err != nil {
return false
}
return true
}
func buildAndroidVersionCode(version string) string {
parsedVersion := parse(version)
versionCode := parsedVersion.Major() * 1000000
versionCode += parsedVersion.Minor() * 10000
versionCode += parsedVersion.Patch() * 100
if versionCode > 2000000000 {
panic(fmt.Sprintf("Android versionCode cannot be greater than %v", 2000000000))
}
return strconv.FormatInt(versionCode, 10)
}
func buildUWPVersion(version string) string {
return version + ".0"
}