build: Upgrade versioning to handle multiple minecraft versions
This commit is contained in:
@@ -31,7 +31,7 @@ plugins {
|
|||||||
id("moe.nea.mc-auto-translations") version "0.1.0"
|
id("moe.nea.mc-auto-translations") version "0.1.0"
|
||||||
}
|
}
|
||||||
|
|
||||||
version = getGitTagInfo() + "-mc${libs.versions.minecraft.get()}"
|
version = getGitTagInfo(libs.versions.minecraft.get())
|
||||||
group = rootProject.property("maven_group").toString()
|
group = rootProject.property("maven_group").toString()
|
||||||
|
|
||||||
java {
|
java {
|
||||||
|
|||||||
@@ -1,26 +1,25 @@
|
|||||||
|
|
||||||
fun execString(vararg args: String): String {
|
fun execString(vararg args: String): String {
|
||||||
val pb = ProcessBuilder(*args)
|
val pb = ProcessBuilder(*args)
|
||||||
.redirectOutput(ProcessBuilder.Redirect.PIPE)
|
.redirectOutput(ProcessBuilder.Redirect.PIPE)
|
||||||
.start()
|
.start()
|
||||||
pb.waitFor()
|
pb.waitFor()
|
||||||
return pb.inputStream.readAllBytes().decodeToString().trim()
|
return pb.inputStream.readAllBytes().decodeToString().trim()
|
||||||
}
|
}
|
||||||
|
|
||||||
private val tag = "([0-9.]+)\\.0".toRegex()
|
private val tag = "([0-9.]+)(?:\\+.*)?".toRegex()
|
||||||
private val tagOffset = "([0-9.]+)\\.0-([0-9]+)..+".toRegex()
|
private val tagOffset = "([0-9.]+)(?:\\+.*)?-([0-9]+)-(.+)".toRegex()
|
||||||
|
|
||||||
inline fun <T> Regex.useMatcher(string: String, block: (MatchResult) -> T): T? {
|
inline fun <T> Regex.useMatcher(string: String, block: (MatchResult) -> T): T? {
|
||||||
return matchEntire(string)?.let(block)
|
return matchEntire(string)?.let(block)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getGitTagInfo(): String {
|
fun getGitTagInfo(mcVersion: String): String {
|
||||||
val str = execString("git", "describe", "--tags", "HEAD")
|
val str = execString("git", "describe", "--tags", "HEAD")
|
||||||
tag.useMatcher(str) {
|
tag.useMatcher(str) {
|
||||||
return it.groupValues[0]
|
return it.groupValues[1] + "+mc$mcVersion"
|
||||||
}
|
}
|
||||||
tagOffset.useMatcher(str) {
|
tagOffset.useMatcher(str) {
|
||||||
return it.groupValues[1] + "." + it.groupValues[2]
|
return it.groupValues[1] + "-dev+mc$mcVersion+" + it.groupValues[3]
|
||||||
}
|
}
|
||||||
return "nogitversion"
|
return "nogitversion+mc$mcVersion"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,7 +84,6 @@ parse_commandline "$@"
|
|||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
REMOTE=origin
|
REMOTE=origin
|
||||||
BRANCH=master
|
|
||||||
|
|
||||||
basedir="$(dirname "$(dirname "$(realpath "$0")")")"
|
basedir="$(dirname "$(dirname "$(realpath "$0")")")"
|
||||||
echo "Found base directory at $basedir"
|
echo "Found base directory at $basedir"
|
||||||
@@ -104,8 +103,10 @@ if [ -n "$(git status --porcelain)" ] && [ "$_arg_no_check" == off ]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! [[ "$(git rev-parse --abbrev-ref HEAD)" = "$BRANCH" ]]; then
|
current_branch="$(git rev-parse --abbrev-ref HEAD)"
|
||||||
echo "Not on branch $BRANCH."
|
|
||||||
|
if ! [[ "$current_branch" = "master" ]] && ! [[ "$current_branch" = mc-* ]]; then
|
||||||
|
echo "Not on branch master or a mc- branch."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -117,8 +118,15 @@ oldversion="$(git describe --tags --abbrev=0|tr -d '\n')"
|
|||||||
|
|
||||||
echo "Choosing old version as $oldversion"
|
echo "Choosing old version as $oldversion"
|
||||||
|
|
||||||
|
# TODO: auto choose next version based on a command line flag: --minor --hotfix --major as well as minecraft info from libs.versions.toml
|
||||||
echo -n "Choosing next version as: "
|
echo -n "Choosing next version as: "
|
||||||
read newversion
|
read newversion
|
||||||
|
|
||||||
|
if ! [[ "$newversion" = *+mc* ]] && [ "$_arg_no_check" == off ]; then
|
||||||
|
echo "Illegal next version $newversion. Please use a.b.c+mcx.y.z"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
echo "Confirming new version as $newversion"
|
echo "Confirming new version as $newversion"
|
||||||
|
|
||||||
echo Committing release commit
|
echo Committing release commit
|
||||||
@@ -153,7 +161,7 @@ cat "$releasenotes"
|
|||||||
echo ----------------------------------------------
|
echo ----------------------------------------------
|
||||||
|
|
||||||
echo Pushing to github
|
echo Pushing to github
|
||||||
git push "$REMOTE" "$BRANCH" "$newversion"
|
git push "$REMOTE" "HEAD" "$newversion"
|
||||||
|
|
||||||
if command -v gh; then
|
if command -v gh; then
|
||||||
echo Creating github release
|
echo Creating github release
|
||||||
|
|||||||
Reference in New Issue
Block a user