-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathversioning.gradle
72 lines (58 loc) · 2.33 KB
/
versioning.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
def getVersionName = { getVersionProps()['appVersionName'] }
def getVersionProps() {
def versionPropsFile = file('gradle.properties')
if (!versionPropsFile.exists()) {
versionPropsFile.createNewFile()
}
def versionProps = new Properties()
versionProps.load(new FileInputStream(versionPropsFile))
return versionProps
}
def getVersionNamePatch = { (getVersionName() =~ /\d+/)[2].toInteger() }
def getVersionNameMinor = { (getVersionName() =~ /\d+/)[1].toInteger() }
def getVersionNameMajor = { (getVersionName() =~ /\d+/)[0].toInteger() }
private void commitAndSetTag(versionName) {
Process addChanges = ['git', 'add', 'gradle.properties'].execute(null, project.rootDir)
addChanges.waitForProcessOutput(System.out, System.err)
Process createCommit = ['git', 'commit', "-m Release ${versionName}"].execute(null, project.rootDir)
createCommit.waitForProcessOutput(System.out, System.err)
Process createTag = ['git', 'tag', "v${versionName}".toString()].execute(null, project.rootDir)
createTag.waitForProcessOutput(System.out, System.err)
}
private def getAppVersionCode() { getVersionProps()['appVersionCode'].toInteger() }
private void save(major, minor, patch, versionCode) {
save("${major}.${minor}.${patch}".toString(), versionCode.toString())
}
private void save(versionName, versionCode) {
def versionProps = getVersionProps()
versionProps['appVersionName'] = versionName
versionProps['appVersionCode'] = versionCode
versionProps.store(file('gradle.properties').newWriter(), null)
commitAndSetTag(versionName)
}
task bumperInit() {
group = 'bumper'
doLast {
def versionName = project.hasProperty('bumperVersionName') ? bumperVersionName : '1.0.0'
def versionCode = project.hasProperty('bumperVersionCode') ? bumperVersionCode : '1'
save(versionName, versionCode)
}
}
task bumperVersionPatch () {
group = 'bumper'
doLast {
save(getVersionNameMajor(), getVersionNameMinor(), getVersionNamePatch() + 1, getAppVersionCode() + 1)
}
}
task bumperVersionMinor () {
group = 'bumper'
doLast {
save(getVersionNameMajor(), getVersionNameMinor() + 1, 0, getAppVersionCode() + 1)
}
}
task bumperVersionMajor () {
group = 'bumper'
doLast {
save(getVersionNameMajor() + 1, 0, 0, getAppVersionCode() + 1)
}
}