This repository has been archived by the owner on Oct 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
version.gradle.kts
59 lines (48 loc) · 1.7 KB
/
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
fun captureExec(configure: ExecSpec.() -> Unit): String? {
val stdout = java.io.ByteArrayOutputStream()
try {
exec {
configure()
standardOutput = stdout
}
} catch (e: org.gradle.process.internal.ExecException) {
logger.error(e.message)
return null
}
return stdout.toString()
}
// tag or commit hash
val currentTagOrHash = captureExec {
commandLine("git", "describe", "--tags", "--always")
}?.trim()?.substringAfterLast('-')
// current or last tag
val currentOrLastTag = captureExec {
commandLine("git", "describe", "--abbrev=0", "--tags")
}?.trim() ?: "v0.0.0"
val describeTags = captureExec {
commandLine("git", "describe", "--tags")
}?.trim() ?: "v0.0.0"
val currentHash = captureExec {
commandLine("git", "describe", "--abbrev=0", "--always")
}?.trim() ?: "v0.0.0"
logger.lifecycle("describeTagsAlways: '$currentTagOrHash'")
logger.lifecycle("tag: '$currentOrLastTag'")
logger.lifecycle("tag2: '$describeTags'")
logger.lifecycle("commit-hash: '$currentHash'")
val currentIsATag = currentTagOrHash != currentOrLastTag
val isSnapshot = currentIsATag && currentOrLastTag.startsWith("v")
val versionStr: String = if (isSnapshot) {
val lastVersion = currentOrLastTag.substringAfter("v")
var (major, minor, patch) = lastVersion.split('.').map { it.toInt() }
patch++
val nextVersion = "$major.$minor.$patch"
// bintrayRepository = "snapshot"
// "$nextVersion-SNAPSHOT"
"$nextVersion-dev+$currentTagOrHash"
} else {
extra["vcsTag"] = currentTagOrHash
currentOrLastTag.substringAfter('v')
}
extra["isSnapshot"] = isSnapshot
project.version = versionStr
logger.lifecycle("project.version: ${project.version}")