forked from cheptsov/AdvancedExpressionFolding
-
Notifications
You must be signed in to change notification settings - Fork 2
/
build-version.gradle.kts
84 lines (65 loc) · 2.58 KB
/
build-version.gradle.kts
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
74
75
76
77
78
79
80
81
82
83
84
import java.io.File
import java.io.InputStream
import java.io.Writer
import java.time.Instant
import java.util.*
fun getPropertiesFile(): File = file("gradle.properties")
fun readProperties(file: File): Properties {
val properties = Properties()
file.inputStream().use { inputStream: InputStream ->
properties.load(inputStream)
}
return properties
}
fun readVersion(properties: Properties): String =
properties.getProperty("pluginVersion") ?: throw GradleException("pluginVersion not found in gradle.properties")
fun incrementMinorVersion(version: String): String {
val versionParts = version.split('.').toMutableList()
if (versionParts.size != 3) {
throw GradleException("pluginVersion must have three parts separated by dots")
}
val minorPart = versionParts[1].toIntOrNull() ?: throw GradleException("Second part of pluginVersion is not a number")
versionParts[1] = (minorPart + 1).toString()
return versionParts.joinToString(".")
}
fun saveProperties(file: File, properties: Properties) {
file.writer().use { writer: Writer ->
properties.store(writer, null)
}
}
tasks.register("minorRelease") {
doLast {
val propertiesFile = getPropertiesFile()
val properties = readProperties(propertiesFile)
val version = readVersion(properties)
val newVersion = incrementMinorVersion(version)
properties.setProperty("pluginVersion", newVersion)
saveProperties(propertiesFile, properties)
println("Updated pluginVersion to $newVersion")
}
}
tasks.register("canaryRelease") {
doLast {
val propertiesFile = getPropertiesFile()
val properties = readProperties(propertiesFile)
val version = readVersion(properties)
val timestamp = Instant.now().toEpochMilli()
val newVersion = "$version-$timestamp-canary"
properties.setProperty("pluginVersion", newVersion)
saveProperties(propertiesFile, properties)
println("Updated pluginVersion to $newVersion")
}
}
tasks.register("canaryEapRelease") {
doLast {
val propertiesFile = getPropertiesFile()
val properties = readProperties(propertiesFile)
val version = readVersion(properties)
val newVersion = "$version".replace("-canary", "-eap-canary")
properties.setProperty("pluginVersion", newVersion)
properties.setProperty("pluginSinceBuild", "242.10180.25")
properties.setProperty("pluginUntilBuild", "242.*")
saveProperties(propertiesFile, properties)
println("Updated pluginVersion to $newVersion")
}
}