feat: add support for type supplements in bumpVersion
This commit is contained in:
parent
e873e9f907
commit
997c3f80a9
@ -18,6 +18,7 @@ abstract class BumpVersionTask : DefaultTask() {
|
||||
@get:Input abstract val nextVersionType: Property<String>
|
||||
@get:Input abstract val nextRelease: Property<SemanticVersion>
|
||||
@get:Input abstract val lastRelease: Property<String>
|
||||
@get:Input abstract val typeSupplement: Property<String>
|
||||
|
||||
@TaskAction
|
||||
fun action() {
|
||||
@ -26,7 +27,7 @@ abstract class BumpVersionTask : DefaultTask() {
|
||||
val vt = nextVersionType
|
||||
.map { VersionType.byName(it) ?: throw IllegalStateException("Unrecognized version type: $this") }
|
||||
.getOrThrow { IllegalStateException("bumpVersion requires you to set -PversionType=release|beta|alpha") }
|
||||
val name = nextRelease.get().withType(vt).toString()
|
||||
val name = nextRelease.get().withType(vt, typeSupplement.orNull).toString()
|
||||
Git.open(gitDir.asFile.get()).use { git ->
|
||||
git.tag().setName(name).call()
|
||||
logger.warn("Created release $name (last was ${lastRelease.get()}). Make sure to push it!")
|
||||
|
@ -6,7 +6,7 @@ package io.gitlab.jfronny.scripts
|
||||
* For example, the pre-release type identifier is restricted to alpha, beta, rc followed by an optional number.
|
||||
* Parsing also supports legacy version strings like v1.2.3, b1.2.3, a1.2.3, rc1.2.3.
|
||||
*/
|
||||
data class SemanticVersion(val major: Int, val minor: Int, val patch: Int, val type: VersionType, val typeSupplement: Int?, val build: String?): Comparable<SemanticVersion> {
|
||||
data class SemanticVersion(val major: Int, val minor: Int, val patch: Int, val type: VersionType, val typeSupplement: String?, val build: String?): Comparable<SemanticVersion> {
|
||||
constructor(major: Int, minor: Int, patch: Int, versionType: VersionType) : this(major, minor, patch, versionType, null, null)
|
||||
constructor(major: Int, minor: Int, patch: Int) : this(major, minor, patch, VersionType.RELEASE)
|
||||
|
||||
@ -18,7 +18,7 @@ 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 -> ""
|
||||
VersionType.RELEASE -> typeSupplement ?: ""
|
||||
else -> "-${type.semanticName}" + if(typeSupplement != null) ".$typeSupplement" else ""
|
||||
} + if (build == null) "" else "+$build"
|
||||
}
|
||||
@ -33,7 +33,7 @@ data class SemanticVersion(val major: Int, val minor: Int, val patch: Int, val t
|
||||
CommitType.BREAKING -> SemanticVersion(major + 1, 0, 0, versionType, null, build)
|
||||
}
|
||||
|
||||
fun withType(versionType: VersionType) = SemanticVersion(major, minor, patch, versionType, null, build)
|
||||
fun withType(versionType: VersionType, typeSupplement: String? = null) = SemanticVersion(major, minor, patch, versionType, typeSupplement, build)
|
||||
|
||||
companion object {
|
||||
private val identifier = Regex("[a-zA-Z1-9][a-zA-Z0-9]*")
|
||||
@ -41,7 +41,7 @@ data class SemanticVersion(val major: Int, val minor: Int, val patch: Int, val t
|
||||
private val number = Regex("[1-9][0-9]*|0")
|
||||
private val versionCore = Regex("($number)\\.($number)(?:\\.($number))?")
|
||||
private val legacyVersion = Regex("([vba]|rc)$versionCore(\\+$buildPattern)?")
|
||||
private val restrictedSemver = Regex("$versionCore(?:-(alpha|beta|rc|pre)(\\.?\\d+)?)?(\\+$buildPattern)?")
|
||||
private val restrictedSemver = Regex("$versionCore(?:-(alpha|beta|rc|pre)(\\.?[a-zA-Z0-9-]+)?)?(\\+$buildPattern)?")
|
||||
|
||||
fun parse(source: String): SemanticVersion {
|
||||
val legacyMatch = legacyVersion.matchEntire(source)
|
||||
@ -60,7 +60,7 @@ data class SemanticVersion(val major: Int, val minor: Int, val patch: Int, val t
|
||||
return SemanticVersion(
|
||||
m[1].toInt(), m[2].toInt(), m[3].ifEmpty { "0" }.toInt(),
|
||||
VersionType.byName(m[4].ifEmpty { "release" })!!,
|
||||
m[5].ifEmpty { null }?.trimStart('.')?.toInt(),
|
||||
m[5].ifEmpty { null }?.trimStart('.'),
|
||||
m[6].ifEmpty { null }?.substring(1)
|
||||
)
|
||||
}
|
||||
|
@ -69,4 +69,5 @@ tasks.register("bumpVersion", BumpVersionTask::class) {
|
||||
nextVersionType = project.provider { nprop("nextVersionType") }
|
||||
nextRelease = project.provider { project.nextRelease }
|
||||
lastRelease = project.provider { project.lastRelease }
|
||||
typeSupplement = project.provider { nprop("typeSupplement") }
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user