Change from tag-based versioning to commit/file based
This commit is contained in:
85
build.gradle
85
build.gradle
@@ -1,6 +1,21 @@
|
|||||||
import groovy.json.JsonOutput
|
import groovy.json.JsonOutput
|
||||||
|
|
||||||
version = gitDescribe()
|
def latestVersion = file('version.txt').readLines().first()
|
||||||
|
def releaseCommit = command('git', 'blame', '-p', '-l', 'version.txt').first().tokenize(' ').first()
|
||||||
|
if (latestVersion == '2.1.0') { // First version since change from tag-based
|
||||||
|
releaseCommit = '35ac26e91689ac9bdf12dbb9902c452464a75108' // git rev-parse 1.12.2-2.1.0
|
||||||
|
}
|
||||||
|
def currentCommit = command('git', 'rev-parse', 'HEAD').first()
|
||||||
|
if (releaseCommit == currentCommit) {
|
||||||
|
version = latestVersion
|
||||||
|
} else {
|
||||||
|
def diff = command('git', 'log', '--format=oneline', "$releaseCommit..$currentCommit").size()
|
||||||
|
version = "$latestVersion-$diff-g${currentCommit.substring(0, 7)}"
|
||||||
|
}
|
||||||
|
if (gitDescribe().endsWith('*')) {
|
||||||
|
version = "$version*"
|
||||||
|
}
|
||||||
|
|
||||||
group= "com.replaymod"
|
group= "com.replaymod"
|
||||||
|
|
||||||
subprojects {
|
subprojects {
|
||||||
@@ -69,15 +84,36 @@ task setCoreVersion() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def generateVersionsJson() {
|
def command(Object...cmd) {
|
||||||
// List all tags
|
|
||||||
def stdout = new ByteArrayOutputStream()
|
def stdout = new ByteArrayOutputStream()
|
||||||
project.exec {
|
exec {
|
||||||
commandLine 'git', 'for-each-ref', '--sort=taggerdate', '--format=%(refname:short)', 'refs/tags'
|
commandLine cmd
|
||||||
standardOutput = stdout
|
standardOutput = stdout
|
||||||
}
|
}
|
||||||
def versions = stdout.toString().tokenize('\n').reverse()
|
return stdout.toString().tokenize('\n')
|
||||||
def mcVersions = versions.collect {it.substring(0, it.indexOf('-'))}.unique().reverse()
|
}
|
||||||
|
|
||||||
|
def generateVersionsJson() {
|
||||||
|
// Find all tag-style releases by listing all tags
|
||||||
|
def tagVersions = command 'git', 'for-each-ref', '--sort=taggerdate', '--format=%(refname:short)', 'refs/tags'
|
||||||
|
|
||||||
|
// Find all commit-style releases
|
||||||
|
// List all commits
|
||||||
|
def releaseCommits =
|
||||||
|
command 'git', 'log', '--format=%H', '--date-order', '-E',
|
||||||
|
'--grep', /Pre-release [0-9]+ of [0-9]+\.[0-9]+\.[0-9]+/,
|
||||||
|
'--grep', /Release [0-9]+\.[0-9]+\.[0-9]+/
|
||||||
|
// Find version string and MC versions for each commit hash
|
||||||
|
def commitVersions = releaseCommits.collect { commit ->
|
||||||
|
def version = command('git', 'show', "$commit:version.txt").first()
|
||||||
|
def mcVersions = command 'git', 'ls-tree', '-d', '--name-only', "$commit:versions"
|
||||||
|
mcVersions.remove('core')
|
||||||
|
return mcVersions.collect { "$it-$version" }
|
||||||
|
}.flatten()
|
||||||
|
|
||||||
|
def versions = commitVersions + tagVersions.reverse()
|
||||||
|
def mcVersions = versions.collect {it.substring(0, it.indexOf('-'))}.unique()
|
||||||
|
mcVersions.sort(new OrderBy([0, 1, 2].collect { i -> { it -> (it.tokenize('.')[i] ?: '0') as int } }))
|
||||||
|
|
||||||
def root = [
|
def root = [
|
||||||
homepage: 'https://www.replaymod.com/download/',
|
homepage: 'https://www.replaymod.com/download/',
|
||||||
@@ -90,7 +126,9 @@ def generateVersionsJson() {
|
|||||||
versions.forEach {
|
versions.forEach {
|
||||||
def (thisMcVersion, modVersion, preVersion) = it.tokenize('-')
|
def (thisMcVersion, modVersion, preVersion) = it.tokenize('-')
|
||||||
if (thisMcVersion == mcVersion) {
|
if (thisMcVersion == mcVersion) {
|
||||||
mcVersionRoot[it] = "See https://github.com/ReplayMod/ReplayMod/releases/$it"
|
mcVersionRoot[it] = tagVersions.contains(it) ?
|
||||||
|
"See https://github.com/ReplayMod/ReplayMod/releases/$it" :
|
||||||
|
'See https://www.replaymod.com/forum/thread/100'
|
||||||
if (latest == null) latest = it
|
if (latest == null) latest = it
|
||||||
if (preVersion == null) {
|
if (preVersion == null) {
|
||||||
if (recommended == null) recommended = it
|
if (recommended == null) recommended = it
|
||||||
@@ -110,34 +148,27 @@ task doRelease() {
|
|||||||
doLast {
|
doLast {
|
||||||
// Parse version
|
// Parse version
|
||||||
def version = project.releaseVersion as String
|
def version = project.releaseVersion as String
|
||||||
if (project.version.endsWith('*')) {
|
if (gitDescribe().endsWith('*')) {
|
||||||
throw new InvalidUserDataException('Git working tree is dirty. Make sure to commit all changes.')
|
throw new InvalidUserDataException('Git working tree is dirty. Make sure to commit all changes.')
|
||||||
}
|
}
|
||||||
def (mcVersion, modVersion, preVersion) = version.tokenize('-')
|
def (modVersion, preVersion) = version.tokenize('-')
|
||||||
preVersion = preVersion != null && preVersion.startsWith('b') ? preVersion.substring(1) : null
|
preVersion = preVersion != null && preVersion.startsWith('b') ? preVersion.substring(1) : null
|
||||||
|
|
||||||
// Create new tag
|
// Create new commit
|
||||||
if (preVersion != null) {
|
def commitMessage = preVersion != null ?
|
||||||
project.exec {
|
"Pre-release $preVersion of $modVersion" :
|
||||||
commandLine 'git', 'tag',
|
"Release $modVersion"
|
||||||
'-m', "Pre-release $preVersion of $modVersion for Minecraft $mcVersion",
|
file('version.txt').write("$version\n")
|
||||||
"$mcVersion-$modVersion-b$preVersion"
|
command 'git', 'add', 'version.txt'
|
||||||
}
|
command 'git', 'commit', '-m', commitMessage
|
||||||
} 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
|
// Generate versions.json content
|
||||||
def versionsRoot = generateVersionsJson()
|
def versionsRoot = generateVersionsJson()
|
||||||
def versionsJson = JsonOutput.prettyPrint(JsonOutput.toJson(versionsRoot))
|
def versionsJson = JsonOutput.prettyPrint(JsonOutput.toJson(versionsRoot))
|
||||||
|
|
||||||
|
// Switch to master branch to update versions.json
|
||||||
|
command 'git', 'checkout', 'master'
|
||||||
|
|
||||||
// Write versions.json
|
// Write versions.json
|
||||||
new File('versions.json').write(versionsJson)
|
new File('versions.json').write(versionsJson)
|
||||||
|
|
||||||
|
|||||||
1
version.txt
Normal file
1
version.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
2.1.0
|
||||||
@@ -24,9 +24,7 @@ sourceCompatibility = 1.8
|
|||||||
targetCompatibility = 1.8
|
targetCompatibility = 1.8
|
||||||
|
|
||||||
afterEvaluate {
|
afterEvaluate {
|
||||||
def gitVer = gitDescribe()
|
version = project.minecraft.version + '-' + rootProject.version
|
||||||
if (gitVer.startsWith('1.12.2-')) gitVer = gitVer.substring('1.12.2-'.length()) // until the first proper version
|
|
||||||
version = project.minecraft.version + '-' + gitVer
|
|
||||||
}
|
}
|
||||||
group= "com.replaymod"
|
group= "com.replaymod"
|
||||||
archivesBaseName = "replaymod"
|
archivesBaseName = "replaymod"
|
||||||
@@ -204,19 +202,6 @@ jar {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def gitDescribe() {
|
|
||||||
try {
|
|
||||||
def stdout = new ByteArrayOutputStream()
|
|
||||||
exec {
|
|
||||||
commandLine 'git', 'describe', '--always', '--dirty=*'
|
|
||||||
standardOutput = stdout
|
|
||||||
}
|
|
||||||
return stdout.toString().trim()
|
|
||||||
} catch (e) {
|
|
||||||
return "unknown"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
processResources
|
processResources
|
||||||
{
|
{
|
||||||
// this will ensure that this task is redone when the versions change.
|
// this will ensure that this task is redone when the versions change.
|
||||||
|
|||||||
Reference in New Issue
Block a user