From 0dc5932e9aa00077e3c2634dbfa044b9ab584c73 Mon Sep 17 00:00:00 2001 From: Frank Date: Mon, 19 Jun 2023 19:31:27 +0200 Subject: [PATCH] Task to auto increment build version --- .gitignore | 2 ++ build.gradle | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/.gitignore b/.gitignore index 646f606f..3afca64b 100644 --- a/.gitignore +++ b/.gitignore @@ -35,3 +35,5 @@ Convert.class ModelPart.class libs/ /src/main/generated/.cache/ +/CHANGES.md +/modrinth.json diff --git a/build.gradle b/build.gradle index 1c4d720d..9521bb06 100644 --- a/build.gradle +++ b/build.gradle @@ -352,4 +352,37 @@ curseforge { debug = false forgeGradleIntegration = false } +} + +task nextVersion() { + doLast { + def inputFile = new File('modrinth.json') + def gameVersions = java.net.URLEncoder.encode(project.modrinth_versions, "UTF-8") + new URL("https://api.modrinth.com/v2/project/${project.modrinth_id}/version?&game_versions=${gameVersions}").withInputStream { i -> inputFile.withOutputStream { it << i } } + + def json = new groovy.json.JsonSlurper().parseText(inputFile.text) + def version = json[0].version_number + + //increment patch version + def indexedVersionList = version.split(/\./).toList().withIndex() + indexedVersionList = indexedVersionList.collect { num, idx -> num.toInteger() } + indexedVersionList[2] = indexedVersionList[2].value + 1 + def updatedVersion = indexedVersionList.join(".") + + println "\n\n" + println "------------- CURRENT VERSION -------------" + println "Last Published Version: " + version + println " Game Versions: " + json[0].game_versions + println " Status: " + json[0].status + println " Featured: " + json[0].featured + println " Downloaded: " + json[0].downloads + println "\n" + println "-------------- NEXT VERSION ---------------" + println "Next Version: " + updatedVersion + println "\n\n" + + def propertiesFile = new File("gradle.properties") + def newContents = propertiesFile.text.replaceFirst("mod_version=\\d+.\\d+.\\d+", "mod_version=${updatedVersion}") + propertiesFile.text = newContents + } } \ No newline at end of file