task updateForgeJson {
doLast {
def page = "https://github.com/Librazy/TooltipFilter/releases"
if (System.getenv("FORGE_RELEASE_HOMEPAGE") != null) {
page = System.getenv("FORGE_RELEASE_HOMEPAGE")
} else if(System.getenv("GIT_ORIGIN_URL") != null) {
page = System.getenv("GIT_ORIGIN_URL").replace(".git", "") + "/Releases"
}
exec {
executable = 'git'
args = [ 'remote', 'set-branches', '--add', 'origin', 'update' ]
}
exec {
executable = 'git'
args = [ 'fetch', '--all' ]
}
exec {
executable = 'git'
args = [ 'checkout', 'update' ]
}
def updateFile = new File('update.json')
def json
if (updateFile.exists()) {
json = new JsonSlurper().parseText(updateFile.getText())
}
else {
def builder = new JsonBuilder()
json = builder(
homepage: page,
promos: new HashMap<>()
)
}
exec {
executable = 'git'
args = [ 'checkout', project.minecraft.version]
}
def outStream = new ByteArrayOutputStream()
exec {
executable = 'git'
args = [ 'log', '-n', '1', "--format='%B'"]
standardOutput = outStream
}
def fullLog = outStream.toString().replaceAll("^\\s*'\\s*|\\s*'\\s*\$", "").replaceAll("[\\r\\n]+", "\n")
json['homepage'] = page
json['promos'][project.minecraft.version + '-latest'] = project.version
if(fullLog.startsWith("[recommended]")){
json['promos'][project.minecraft.version + '-recommended'] = project.version
}
exec {
executable = 'git'
args = [ 'checkout', 'update']
}
def writeFile = new File('update.json')
if (!json.containsKey(project.minecraft.version)) json.put(project.minecraft.version, new HashMap<>())
def version = json[project.minecraft.version]
version.put(project.version, fullLog)
writeFile.write JsonOutput.prettyPrint(JsonOutput.toJson(json))
exec {
executable = 'git'
args = [ 'add', '.']
}
exec {
executable = 'git'
args = [ 'commit', '-m', 'Generated update.json']
}
exec {
executable = 'git'
args = [ 'checkout', project.minecraft.version]
}
}
}