Add auto version generator

[no changelog]
This commit is contained in:
Linnea Gräf
2024-07-11 02:21:41 +02:00
parent feca9c937b
commit e683aa1e6c
4 changed files with 33 additions and 6 deletions

View File

@@ -0,0 +1,31 @@
/*
* SPDX-FileCopyrightText: 2024 Linnea Gräf <nea@nea.moe>
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
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.]+)\\.0".toRegex()
private val tagOffset = "([0-9.]+)\\.0-([0-9]+)..+".toRegex()
inline fun <T> Regex.useMatcher(string: String, block: (MatchResult) -> T): T? {
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"
}