Added: Current Commit Hash (Thanks Booky)

This commit is contained in:
Bram 2024-07-08 09:54:11 +02:00
parent e093a4ffc6
commit 2e684dd561
No known key found for this signature in database
GPG key ID: 13E608068F40E3CC
2 changed files with 22 additions and 2 deletions

View file

@ -1,7 +1,27 @@
import java.io.ByteArrayOutputStream
plugins {
entitylib.`library-conventions`
}
group = "me.tofaa.entitylib"
description = rootProject.name
version = "2.4.1-SNAPSHOT"
val fullVersion = "2.4.1"
val snapshot = true
fun getVersionMeta(): String {
if (!snapshot) {
return ""
}
var commitHash = ""
if (file(".git").isDirectory) {
val stdout = ByteArrayOutputStream()
exec {
commandLine("git", "rev-parse", "--short", "HEAD")
standardOutput = stdout
}
commitHash = "+${stdout.toString().trim()}"
}
return "$commitHash-SNAPSHOT"
}
version = "$fullVersion${getVersionMeta()}"

View file

@ -63,7 +63,7 @@ abstract class ELVersionTask : DefaultTask() {
val snapShot: Boolean
) {
companion object {
private val REGEX = Regex("""(\d+)\.(\d+)\.(\d+)(-SNAPSHOT)?""")
private val REGEX = Regex("""(\d+)\.(\d+)\.(\d+)(?:\+[0-9a-f]+)?(-SNAPSHOT)?""")
fun fromString(version: String): Version {
val match = REGEX.matchEntire(version) ?: throw IllegalArgumentException("Invalid version: $version")