-
Notifications
You must be signed in to change notification settings - Fork 1
/
bump-version.gradle
37 lines (32 loc) · 1.44 KB
/
bump-version.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
import java.util.regex.Pattern
tasks.register('version') {
doLast {
String currentVersion = project.version
List<Integer> parts = currentVersion.tokenize(".")*.toInteger()
// Command line argument -DbumpType=major
String bumpType = System.getProperty("bumpType")
if (bumpType == "major") {
parts[0] = parts[0] + 1
parts[1] = 0
parts[2] = 0
} else if (bumpType == "minor") {
parts[1] = parts[1] + 1
parts[2] = 0
} else if (bumpType == "patch") {
parts[2] = parts[2] + 1
} else {
throw new IllegalArgumentException("bumpType argument can have only major, minor and patch")
}
String newVersion = parts.join(".")
File buildGradleFile = new File("./build.gradle")
Pattern pattern = ~/\nversion (.*)\n/
buildGradleFile.text = buildGradleFile.text.replaceFirst(pattern, "\nversion \"${newVersion}\"\n")
exec { commandLine("git", "add", "build.gradle") }
exec { commandLine("git", "add", "CHANGELOG.md") }
exec { commandLine("git", "add", "README.md") }
exec { commandLine("git", "commit", "-m", "release: v${newVersion}") }
exec { commandLine("git", "tag", "-a", "v${newVersion}", "-m", "release: v${newVersion}") }
exec { commandLine("git", "push", "origin") }
exec { commandLine("git", "push", "origin", "--tags") }
}
}