From cf013b5ab5ed57d4b51d475755d1381f69acf0f7 Mon Sep 17 00:00:00 2001 From: LoJoSho Date: Sat, 30 Nov 2024 14:59:38 -0600 Subject: [PATCH] feat: testing git commit in version --- build.gradle.kts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index 58265fa..6002203 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -11,7 +11,7 @@ plugins { } group = "me.lojosho" -version = "0.5.1" +version = "0.5.2-${getGitCommitHash()}" allprojects { apply(plugin = "java") @@ -304,4 +304,16 @@ class PublishData(private val project: Project) { fun append(name: String, appendCommit: Boolean, commitHash: String): String = 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 + } } \ No newline at end of file