9
0
mirror of https://github.com/HibiscusMC/HibiscusCommons.git synced 2025-12-19 15:09:26 +00:00

feat: testing git commit in version

This commit is contained in:
LoJoSho
2024-11-30 14:59:38 -06:00
parent 1a794fa1ea
commit cf013b5ab5

View File

@@ -11,7 +11,7 @@ plugins {
}
group = "me.lojosho"
version = "0.5.1"
version = "0.5.2-${getGitCommitHash()}"
allprojects {
apply(plugin = "java")
@@ -305,3 +305,15 @@ class PublishData(private val project: Project) {
name.plus(append).plus(if (appendCommit && addCommit) "-".plus(commitHash) else "")
}
}
fun getGitCommitHash(): String {
return try {
val process = ProcessBuilder("git", "rev-parse", "--short", "HEAD")
.redirectErrorStream(true)
.start()
process.inputStream.bufferedReader().use { it.readLine().trim() }
} catch (e: Exception) {
"unknown" // Fallback if Git is not available or an error occurs
}
}