142 lines
4.6 KiB
Groovy
Executable File
142 lines
4.6 KiB
Groovy
Executable File
import groovy.json.JsonOutput
|
|
|
|
version = gitDescribe()
|
|
group= "com.replaymod"
|
|
|
|
subprojects {
|
|
buildscript {
|
|
repositories {
|
|
mavenLocal()
|
|
mavenCentral()
|
|
maven {
|
|
name = "forge"
|
|
url = "http://files.minecraftforge.net/maven"
|
|
}
|
|
maven {
|
|
name = "sonatype"
|
|
url = "https://oss.sonatype.org/content/repositories/snapshots/"
|
|
}
|
|
maven { url 'https://jitpack.io' }
|
|
}
|
|
dependencies {
|
|
classpath('com.github.SpongePowered:MixinGradle:dcfaf61'){ // 0.6
|
|
// Because forgegradle requires 6.0 (not -debug-all) while mixingradle depends on 5.0
|
|
// and putting mixin right here will place it before forge in the class loader
|
|
exclude group: 'org.ow2.asm', module: 'asm-debug-all'
|
|
}
|
|
}
|
|
}
|
|
|
|
// Thanks for wasting my time gradle...
|
|
// Workaround for https://discuss.gradle.org/t/idea-plugin-bug/21525
|
|
apply plugin: 'eclipse'
|
|
apply plugin: 'idea'
|
|
}
|
|
|
|
def gitDescribe() {
|
|
try {
|
|
def stdout = new ByteArrayOutputStream()
|
|
exec {
|
|
commandLine 'git', 'describe', '--always', '--dirty=*'
|
|
standardOutput = stdout
|
|
}
|
|
return stdout.toString().trim()
|
|
} catch (e) {
|
|
return "unknown"
|
|
}
|
|
}
|
|
|
|
apply from: 'versions/preprocessor.gradle'
|
|
|
|
task setCoreVersion() {
|
|
doLast {
|
|
def vars = [MC: project.mcVersion as int, DEV_ENV: 1]
|
|
project.convertTree(vars, 'src/main/java')
|
|
project.convertTree(vars, 'src/main/resources')
|
|
project.convertTree(vars, 'versions/core/build.gradle')
|
|
}
|
|
}
|
|
|
|
def generateVersionsJson() {
|
|
// List all tags
|
|
def stdout = new ByteArrayOutputStream()
|
|
project.exec {
|
|
commandLine 'git', 'for-each-ref', '--sort=taggerdate', '--format=%(refname:short)', 'refs/tags'
|
|
standardOutput = stdout
|
|
}
|
|
def versions = stdout.toString().tokenize('\n').reverse()
|
|
def mcVersions = versions.collect {it.substring(0, it.indexOf('-'))}.unique().reverse()
|
|
|
|
def root = [
|
|
homepage: 'https://www.replaymod.com/download/',
|
|
promos: [:]
|
|
]
|
|
mcVersions.forEach { mcVersion ->
|
|
def mcVersionRoot = [:]
|
|
def latest
|
|
def recommended
|
|
versions.forEach {
|
|
def (thisMcVersion, modVersion, preVersion) = it.tokenize('-')
|
|
if (thisMcVersion == mcVersion) {
|
|
mcVersionRoot[it] = "See https://github.com/ReplayMod/ReplayMod/releases/$it"
|
|
if (latest == null) latest = it
|
|
if (preVersion == null) {
|
|
if (recommended == null) recommended = it
|
|
}
|
|
}
|
|
}
|
|
root[mcVersion] = mcVersionRoot
|
|
root.promos[mcVersion + '-latest'] = latest
|
|
if (recommended != null) {
|
|
root.promos[mcVersion + '-recommended'] = recommended
|
|
}
|
|
}
|
|
root
|
|
}
|
|
|
|
task doRelease() {
|
|
doLast {
|
|
// Parse version
|
|
def version = project.releaseVersion as String
|
|
if (project.version.endsWith('*')) {
|
|
throw new InvalidUserDataException('Git working tree is dirty. Make sure to commit all changes.')
|
|
}
|
|
def (mcVersion, modVersion, preVersion) = version.tokenize('-')
|
|
preVersion = preVersion != null && preVersion.startsWith('b') ? preVersion.substring(1) : null
|
|
|
|
// Create new tag
|
|
if (preVersion != null) {
|
|
project.exec {
|
|
commandLine 'git', 'tag',
|
|
'-m', "Pre-release $preVersion of $modVersion for Minecraft $mcVersion",
|
|
"$mcVersion-$modVersion-b$preVersion"
|
|
}
|
|
} else {
|
|
project.exec {
|
|
commandLine 'git', 'tag',
|
|
'-m', "Release $modVersion for Minecraft $mcVersion",
|
|
"$mcVersion-$modVersion"
|
|
}
|
|
}
|
|
|
|
// Switch to master branch to update versions.json
|
|
project.exec { commandLine 'git', 'checkout', 'master' }
|
|
|
|
// Generate versions.json content
|
|
def versionsRoot = generateVersionsJson()
|
|
def versionsJson = JsonOutput.prettyPrint(JsonOutput.toJson(versionsRoot))
|
|
|
|
// Write versions.json
|
|
new File('versions.json').write(versionsJson)
|
|
|
|
// Commit changes
|
|
project.exec { commandLine 'git', 'add', 'versions.json' }
|
|
project.exec { commandLine 'git', 'commit', '-m', "Update versions.json for $version" }
|
|
|
|
// Return to previous branch
|
|
project.exec { commandLine 'git', 'checkout', '-' }
|
|
}
|
|
}
|
|
|
|
defaultTasks 'build'
|