diff options
Diffstat (limited to 'build-logic/src/main/kotlin/lookupversion.kt')
-rw-r--r-- | build-logic/src/main/kotlin/lookupversion.kt | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/build-logic/src/main/kotlin/lookupversion.kt b/build-logic/src/main/kotlin/lookupversion.kt new file mode 100644 index 0000000..8a7c2de --- /dev/null +++ b/build-logic/src/main/kotlin/lookupversion.kt @@ -0,0 +1,25 @@ +fun execString(vararg args: String): String { + val pb = ProcessBuilder(*args) + .redirectOutput(ProcessBuilder.Redirect.PIPE) + .start() + pb.waitFor() + return pb.inputStream.readAllBytes().decodeToString().trim() +} + +private val tag = "([0-9.]+)(?:\\+[^-]*)?".toRegex() +private val tagOffset = "([0-9.]+)(?:\\+.*)?-([0-9]+)-(.+)".toRegex() + +inline fun <T> Regex.useMatcher(string: String, block: (MatchResult) -> T): T? { + return matchEntire(string)?.let(block) +} + +fun getGitTagInfo(mcVersion: String): String { + val str = execString("git", "describe", "--tags", "HEAD") + tag.useMatcher(str) { + return it.groupValues[1] + "+mc$mcVersion" + } + tagOffset.useMatcher(str) { + return it.groupValues[1] + "-dev+mc$mcVersion+" + it.groupValues[3] + } + return "nogitversion+mc$mcVersion" +} |