From 629de31706942ea7b98152607eaa15915755f3b9 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 | 3 +++ build.gradle | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/.gitignore b/.gitignore index d6f2f3b9..3afca64b 100644 --- a/.gitignore +++ b/.gitignore @@ -34,3 +34,6 @@ output/ Convert.class ModelPart.class libs/ +/src/main/generated/.cache/ +/CHANGES.md +/modrinth.json diff --git a/build.gradle b/build.gradle index 78bbabdc..0235c5f2 100644 --- a/build.gradle +++ b/build.gradle @@ -327,4 +327,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