feat(autoversion): special casing for mods specifying mod loaders in their build
This commit is contained in:
parent
39a4f6c53f
commit
47c14f9c28
@ -18,11 +18,13 @@ data class SemanticVersion(val major: Int, val minor: Int, val patch: Int, val t
|
|||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
return "$major.$minor.$patch" + when (type) {
|
return "$major.$minor.$patch" + when (type) {
|
||||||
VersionType.RELEASE -> typeSupplement?.let { "-$it" } ?: ""
|
VersionType.RELEASE -> typeSupplement.possiblyPrefix("-")
|
||||||
else -> "-${type.semanticName}" + if(typeSupplement != null) ".$typeSupplement" else ""
|
else -> "-${type.semanticName}" + typeSupplement.possiblyPrefix(".")
|
||||||
} + if (build == null) "" else "+$build"
|
} + build.possiblyPrefix("+")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun String?.possiblyPrefix(prefix: String) = if (this == null) "" else "$prefix$this"
|
||||||
|
|
||||||
fun unclassifiedToString(): String {
|
fun unclassifiedToString(): String {
|
||||||
return "$major.$minor.$patch" + if (build == null) "" else "+$build"
|
return "$major.$minor.$patch" + if (build == null) "" else "+$build"
|
||||||
}
|
}
|
||||||
@ -45,6 +47,10 @@ data class SemanticVersion(val major: Int, val minor: Int, val patch: Int, val t
|
|||||||
private val restrictedSemver = Regex("$versionCore(?:-(alpha|beta|rc|pre)(\\.?[a-zA-Z0-9-]+)?)?(\\+$buildPattern)?")
|
private val restrictedSemver = Regex("$versionCore(?:-(alpha|beta|rc|pre)(\\.?[a-zA-Z0-9-]+)?)?(\\+$buildPattern)?")
|
||||||
|
|
||||||
fun parse(source: String): SemanticVersion {
|
fun parse(source: String): SemanticVersion {
|
||||||
|
return tryParse(source) ?: throw IllegalArgumentException("Source does not match supported version patterns: $source")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun tryParse(source: String): SemanticVersion? {
|
||||||
val legacyMatch = legacyVersion.matchEntire(source)
|
val legacyMatch = legacyVersion.matchEntire(source)
|
||||||
if (legacyMatch != null) {
|
if (legacyMatch != null) {
|
||||||
val m = legacyMatch.groupValues
|
val m = legacyMatch.groupValues
|
||||||
@ -65,7 +71,7 @@ data class SemanticVersion(val major: Int, val minor: Int, val patch: Int, val t
|
|||||||
m[6].ifEmpty { null }?.substring(1)
|
m[6].ifEmpty { null }?.substring(1)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
throw IllegalArgumentException("Source does not match supported version patterns: $source")
|
return null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,32 +4,48 @@ import kotlin.jvm.optionals.getOrDefault
|
|||||||
|
|
||||||
val isRelease = project.hasProperty("release")
|
val isRelease = project.hasProperty("release")
|
||||||
|
|
||||||
|
val specialCaseBuilds = setOf("forge", "fabric", "neoforge")
|
||||||
|
fun List<Tag>.filter(): Pair<Tag, Tag?>? {
|
||||||
|
if (isEmpty()) return null
|
||||||
|
if (size == 1) return first() to null
|
||||||
|
|
||||||
|
val ver = SemanticVersion.tryParse(first().name)
|
||||||
|
// special case: some mod projects use the format 1.0.0+forge to classify builds for different loaders
|
||||||
|
// this ensures changelogs get generated within the same loader branch
|
||||||
|
if (ver?.build in specialCaseBuilds) {
|
||||||
|
val preceding = drop(1).firstOrNull { SemanticVersion.tryParse(it.name)?.build == ver?.build }
|
||||||
|
if (preceding != null) return first() to preceding
|
||||||
|
}
|
||||||
|
|
||||||
|
return first() to get(1)
|
||||||
|
}
|
||||||
|
|
||||||
versionS = "0.0.0+nogit"
|
versionS = "0.0.0+nogit"
|
||||||
versionType = VersionType.ALPHA
|
versionType = VersionType.ALPHA
|
||||||
if (File(projectDir, ".git").exists()) {
|
if (File(projectDir, ".git").exists()) {
|
||||||
initializeGit()
|
initializeGit()
|
||||||
Git.open(projectDir).use { git ->
|
Git.open(projectDir).use { git ->
|
||||||
versionS = "0.0.0+notag"
|
versionS = "0.0.0+notag"
|
||||||
val tags: List<Tag> = git.getTags()
|
val tags = git.getTags().filter()
|
||||||
if (tags.isNotEmpty()) {
|
if (tags != null) {
|
||||||
if (tags[0].fullMessage != null) {
|
if (tags.first.fullMessage != null) {
|
||||||
changelog += "${tags[0].fullMessage}\n"
|
changelog += "${tags.first.fullMessage}\n"
|
||||||
changelogHtml += "<p>${tags[0].fullMessage}</p>\n"
|
changelogHtml += "<p>${tags.first.fullMessage}</p>\n"
|
||||||
}
|
}
|
||||||
versionS = tags[0].name
|
versionS = tags.first.name
|
||||||
lastRelease = versionS
|
lastRelease = versionS
|
||||||
val parsedVersion = SemanticVersion.parse(versionS)
|
val parsedVersion = SemanticVersion.parse(versionS)
|
||||||
versionType = parsedVersion.type
|
versionType = parsedVersion.type
|
||||||
versionS = parsedVersion.unclassifiedToString()
|
versionS = parsedVersion.unclassifiedToString()
|
||||||
if (isRelease) {
|
if (isRelease) {
|
||||||
changelog += "Commits in ${versionType.displayName} $versionS:\n"
|
changelog += "Commits in ${versionType.displayName} $versionS:\n"
|
||||||
val log = git.log(if (tags.size >= 2) tags[1].peeledId else null, tags[0].peeledId).reversed()
|
val log = git.log(tags.second?.peeledId, tags.first.peeledId).reversed()
|
||||||
changelog += log.joinToString("\n") { "- ${it.shortMessage}" }
|
changelog += log.joinToString("\n") { "- ${it.shortMessage}" }
|
||||||
changelogHtml += "<ul>\n" + log.joinToString("") { " <li>${it.shortMessage}</li>\n" } + "</ul>"
|
changelogHtml += "<ul>\n" + log.joinToString("") { " <li>${it.shortMessage}</li>\n" } + "</ul>"
|
||||||
nextRelease = parsedVersion
|
nextRelease = parsedVersion
|
||||||
} else {
|
} else {
|
||||||
changelog += "Commits after ${versionType.displayName} $versionS:\n"
|
changelog += "Commits after ${versionType.displayName} $versionS:\n"
|
||||||
val log = git.log(tags[0].peeledId, git.repository.resolve("HEAD")).reversed()
|
val log = git.log(tags.first.peeledId, git.repository.resolve("HEAD")).reversed()
|
||||||
changelog += log.joinToString("\n") { "- ${it.shortMessage}" }
|
changelog += log.joinToString("\n") { "- ${it.shortMessage}" }
|
||||||
changelogHtml += "<ul>\n" + log.joinToString("") { " <li>${it.shortMessage}</li>\n" } + "</ul>"
|
changelogHtml += "<ul>\n" + log.joinToString("") { " <li>${it.shortMessage}</li>\n" } + "</ul>"
|
||||||
val type = log.stream()
|
val type = log.stream()
|
||||||
|
Loading…
Reference in New Issue
Block a user