From e683aa1e6c2e6efe2502e78f23c86fbb9d4b86fe Mon Sep 17 00:00:00 2001 From: Linnea Gräf Date: Thu, 11 Jul 2024 02:21:41 +0200 Subject: Add auto version generator [no changelog] --- build.gradle.kts | 2 +- buildSrc/src/lookupversion.kt | 31 +++++++++++++++++++++++++++++++ docs/release_script.sh | 5 +---- gradle.properties | 1 - 4 files changed, 33 insertions(+), 6 deletions(-) create mode 100644 buildSrc/src/lookupversion.kt 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 + * + * 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 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 -- cgit