-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathversions.gradle
73 lines (59 loc) · 1.61 KB
/
versions.gradle
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
ext {
compileSdkVersion = 30
minSdkVersion = 21
targetSdkVersion = 30
buildToolsVersion = "30.0.3"
versionCode = generateVersionCode()
versionName = generateVersionName()
}
// 0
private static def majorVersion() {
return 1
}
// 0
private static def minorVersion() {
return 0
}
// 00
private static def revisionVersion() {
return 0
}
static def generateVersionCode() {
return majorVersion() * 100000 + minorVersion() * 1000 + revisionVersion()
}
static def generateVersionName() {
def versionName = "${majorVersion()}.${minorVersion()}.${revisionVersion()}"
def suffix = generateVersionSuffix()
if (suffix.isEmpty()) {
return versionName;
} else {
return "${versionName}.${suffix}-${commitId()}"
}
}
static def releaseTime() {
return new Date().format("yyMMddHHmm", TimeZone.getTimeZone("GMT+08:00"))
}
private static def commitVersion() {
Process process = "git rev-list --count HEAD".execute()
process.waitFor()
return process.getText().toInteger()
}
private static def commitId() {
Process process = "git rev-parse --short HEAD".execute()
process.waitFor()
return process.getText().trim()
}
private static def generateVersionSuffix() {
Process process = "git symbolic-ref --short -q HEAD".execute()
process.waitFor()
def branch = process.getText().trim();
System.println("generateVersionSuffix: Branch=" + branch)
switch (branch) {
case "master":
return "";
case "develop":
return "dev"
default:
return branch.replaceAll(File.pathSeparator, "-")
}
}