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 {
|
||||
return "$major.$minor.$patch" + when (type) {
|
||||
VersionType.RELEASE -> typeSupplement?.let { "-$it" } ?: ""
|
||||
else -> "-${type.semanticName}" + if(typeSupplement != null) ".$typeSupplement" else ""
|
||||
} + if (build == null) "" else "+$build"
|
||||
VersionType.RELEASE -> typeSupplement.possiblyPrefix("-")
|
||||
else -> "-${type.semanticName}" + typeSupplement.possiblyPrefix(".")
|
||||
} + build.possiblyPrefix("+")
|
||||
}
|
||||
|
||||
private fun String?.possiblyPrefix(prefix: String) = if (this == null) "" else "$prefix$this"
|
||||
|
||||
fun unclassifiedToString(): String {
|
||||
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)?")
|
||||
|
||||
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)
|
||||
if (legacyMatch != null) {
|
||||
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)
|
||||
)
|
||||
}
|
||||
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 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"
|
||||
versionType = VersionType.ALPHA
|
||||
if (File(projectDir, ".git").exists()) {
|
||||
initializeGit()
|
||||
Git.open(projectDir).use { git ->
|
||||
versionS = "0.0.0+notag"
|
||||
val tags: List<Tag> = git.getTags()
|
||||
if (tags.isNotEmpty()) {
|
||||
if (tags[0].fullMessage != null) {
|
||||
changelog += "${tags[0].fullMessage}\n"
|
||||
changelogHtml += "<p>${tags[0].fullMessage}</p>\n"
|
||||
val tags = git.getTags().filter()
|
||||
if (tags != null) {
|
||||
if (tags.first.fullMessage != null) {
|
||||
changelog += "${tags.first.fullMessage}\n"
|
||||
changelogHtml += "<p>${tags.first.fullMessage}</p>\n"
|
||||
}
|
||||
versionS = tags[0].name
|
||||
versionS = tags.first.name
|
||||
lastRelease = versionS
|
||||
val parsedVersion = SemanticVersion.parse(versionS)
|
||||
versionType = parsedVersion.type
|
||||
versionS = parsedVersion.unclassifiedToString()
|
||||
if (isRelease) {
|
||||
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}" }
|
||||
changelogHtml += "<ul>\n" + log.joinToString("") { " <li>${it.shortMessage}</li>\n" } + "</ul>"
|
||||
nextRelease = parsedVersion
|
||||
} else {
|
||||
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}" }
|
||||
changelogHtml += "<ul>\n" + log.joinToString("") { " <li>${it.shortMessage}</li>\n" } + "</ul>"
|
||||
val type = log.stream()
|
||||
|
Loading…
Reference in New Issue
Block a user