plugins { id 'idea' id 'eclipse' id 'fabric-loom' version "${loom_version}" id 'maven-publish' id "com.modrinth.minotaur" version "2.+" id "com.matthewprenger.cursegradle" version "1.4.0" } apply from: "bclib.gradle" //from https://lowcarbrob.medium.com/android-pro-tip-generating-your-apps-changelog-from-git-inside-build-gradle-19a07533eec4 String generateChangelog() { println "Assembeling Changelog ..." def lastTag = "git describe --tags --abbrev=0".execute().text.trim() def gitLogCmd = "git log $lastTag..HEAD --oneline --no-merges --pretty=format:\"%s\"".execute().text.trim() def features = "" def fixes = "" def changes = "" gitLogCmd.eachLine { gitLine -> def line = gitLine.substring(1, gitLine.length() - 1) if (line.trim().startsWith("[")) { def sline = line.split("]", 2) if (sline.length == 2) { def type = sline[0].trim().toLowerCase().substring(1) def comment = sline[1].trim() //filter issue links if (comment.contains("(")) { def cline = comment.split("\\(", 2) if (cline.length == 2 && cline[1].contains("#")) { comment = cline[0].trim() } } if (type == "fix" || type == "fixes" || type == "fixed") { fixes += "- $comment \n" } else if (type == "feature" || type == "features") { features += "- $comment \n" } else if (type == "change" || type == "changes" || type == "changed") { changes += "- $comment \n" } else { println "Unknown Type: $type ($line)" } } } } def changelog = "" if (!features.isEmpty()) { changelog += "#### Features\n" changelog += features.trim() changelog += "\n\n" } if (!changes.isEmpty()) { changelog += "#### Changes\n" changelog += changes.trim() changelog += "\n\n" } if (!fixes.isEmpty()) { changelog += "#### Fixes\n" changelog += fixes.trim() changelog += "\n\n" } println "Changelog since $lastTag:\n$changelog" return changelog } task changelog() { doLast { new File(projectDir, "CHANGES.md").text = generateChangelog() } } modrinth { def changes = new File(projectDir, "CHANGES.md") if (changes.exists()) { changes = changes.getText('UTF-8') } else { changes = "" } def modrinth_token = new File(projectDir, "../MODRINTH_TOKEN") if (modrinth_token.exists()) { modrinth_token = modrinth_token.text } else { modrinth_token = "" } def slurper = new groovy.json.JsonSlurper() token = modrinth_token projectId = project.archives_base_name versionNumber = project.mod_version versionType = project.release_channel uploadFile = remapJar gameVersions = slurper.parseText(project.modrinth_versions) loaders = ["fabric"] changelog = changes dependencies { required.project "fabric-api" optional.project "modmenu" } debugMode = false } curseforge { def slurper = new groovy.json.JsonSlurper() apiKey = new File(projectDir, "../CURSEFORGE_TOKEN") if (apiKey.exists()) { apiKey = apiKey.text } else { apiKey = "" } def changes = new File(projectDir, "CHANGES.md") if (changes.exists()) { changes = changes.getText('UTF-8') } else { changes = "" } project { id = '495191' changelogType = 'markdown' changelog = changes releaseType = project.release_channel def versions = slurper.parseText(project.modrinth_versions); def latestVersion = '' for (v in versions) { addGameVersion v latestVersion = "[$v]" } addGameVersion 'Fabric' addGameVersion 'Java 17' relations { requiredDependency 'fabric-api' optionalDependency 'modmenu' } mainArtifact(remapJar) { displayName = "$project.archives_base_name-$project.version $latestVersion" } afterEvaluate { mainArtifact(remapJar.outputs) } } options { 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.archives_base_name}/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 def fabricFile = new File("src/main/resources/fabric.mod.json") newContents = fabricFile.text.replaceFirst('"version": ".+"', "\"version\": \"${updatedVersion}\"") fabricFile.text = newContents } }