build: Upgrade versioning to handle multiple minecraft versions

This commit is contained in:
Linnea Gräf
2024-11-15 00:27:53 +01:00
parent 2c8152335e
commit f158a9d8b0
3 changed files with 30 additions and 23 deletions

View File

@@ -1,26 +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()
val pb = ProcessBuilder(*args)
.redirectOutput(ProcessBuilder.Redirect.PIPE)
.start()
pb.waitFor()
return pb.inputStream.readAllBytes().decodeToString().trim()
}
private val tag = "([0-9.]+)\\.0".toRegex()
private val tagOffset = "([0-9.]+)\\.0-([0-9]+)..+".toRegex()
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)
return matchEntire(string)?.let(block)
}
fun getGitTagInfo(): String {
val str = execString("git", "describe", "--tags", "HEAD")
tag.useMatcher(str) {
return it.groupValues[0]
}
tagOffset.useMatcher(str) {
return it.groupValues[1] + "." + it.groupValues[2]
}
return "nogitversion"
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"
}