aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build.gradle.kts2
-rw-r--r--buildSrc/src/lookupversion.kt31
-rwxr-xr-xdocs/release_script.sh5
-rw-r--r--gradle.properties1
4 files changed, 33 insertions, 6 deletions
diff --git a/build.gradle.kts b/build.gradle.kts
index 33f018e..812bf3c 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -183,7 +183,7 @@ tasks.test {
useJUnitPlatform()
}
-version = rootProject.property("mod_version").toString()
+version = getGitTagInfo()
group = rootProject.property("maven_group").toString()
loom {
diff --git a/buildSrc/src/lookupversion.kt b/buildSrc/src/lookupversion.kt
new file mode 100644
index 0000000..2fe9bb9
--- /dev/null
+++ b/buildSrc/src/lookupversion.kt
@@ -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"
+}
diff --git a/docs/release_script.sh b/docs/release_script.sh
index 6f22c13..5026dfd 100755
--- a/docs/release_script.sh
+++ b/docs/release_script.sh
@@ -121,11 +121,8 @@ echo -n "Choosing next version as: "
read newversion
echo "Confirming new version as $newversion"
-echo Editing gradle.properties
-sed -i -E 's/(mod_version *= *).*/\1'"$newversion"'/' "$basedir"/gradle.properties
-git add gradle.properties
echo Committing release commit
-git commit -m 'Prepare release '"$newversion"'
+git commit --allow-empty -m 'Prepare release '"$newversion"'
[no changelog]'
echo Tagging release commit
diff --git a/gradle.properties b/gradle.properties
index 380103d..abca2cd 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -7,6 +7,5 @@ org.gradle.jvmargs=-Xmx4096M
loom.platform=fabric
archives_base_name=Firmament
-mod_version=1.8.0
maven_group=moe.nea.firmament