-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbumpVersion.gradle
More file actions
69 lines (53 loc) · 1.95 KB
/
bumpVersion.gradle
File metadata and controls
69 lines (53 loc) · 1.95 KB
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
def getVersionName = { getVersionProps()['app.build.version'] }
ext.filePropsPath = 'src/main/resources/application.properties'
def getVersionProps() {
def versionPropsFile = file(filePropsPath)
versionPropsFile.setWritable(true, false)
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', filePropsPath].execute(null, project.rootDir)
addChanges.waitForProcessOutput(System.out, System.err)
Process createCommit = ['git', 'commit', "-m ${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 void save(major, minor, patch) {
save("${major}.${minor}.${patch}".toString())
}
private void save(versionName) {
File propsFile = file(filePropsPath)
def versionProps = getVersionProps()
def text = propsFile
.getText()
.replace(
'app.build.version='.concat(versionProps.get('app.build.version')),
'app.build.version='.concat(versionName)
)
propsFile.setText(text)
commitAndSetTag(versionName)
}
task bumpPatch() {
group = 'bumper'
doLast {
save(getVersionNameMajor(), getVersionNameMinor(), getVersionNamePatch() + 1)
}
}
task bumpMinor() {
group = 'bumper'
doLast {
save(getVersionNameMajor(), getVersionNameMinor() + 1, 0)
}
}
task bumpMajor() {
group = 'bumper'
doLast {
save(getVersionNameMajor() + 1, 0, 0)
}
}