feat: add support for type supplements in bumpVersion
All checks were successful
ci/woodpecker/push/pages Pipeline was successful
ci/woodpecker/push/gradle Pipeline was successful

This commit is contained in:
Johannes Frohnmeyer 2024-09-30 18:23:41 +02:00
parent e873e9f907
commit 997c3f80a9
Signed by: Johannes
GPG Key ID: E76429612C2929F4
3 changed files with 8 additions and 6 deletions

View File

@ -18,6 +18,7 @@ abstract class BumpVersionTask : DefaultTask() {
@get:Input abstract val nextVersionType: Property<String> @get:Input abstract val nextVersionType: Property<String>
@get:Input abstract val nextRelease: Property<SemanticVersion> @get:Input abstract val nextRelease: Property<SemanticVersion>
@get:Input abstract val lastRelease: Property<String> @get:Input abstract val lastRelease: Property<String>
@get:Input abstract val typeSupplement: Property<String>
@TaskAction @TaskAction
fun action() { fun action() {
@ -26,7 +27,7 @@ abstract class BumpVersionTask : DefaultTask() {
val vt = nextVersionType val vt = nextVersionType
.map { VersionType.byName(it) ?: throw IllegalStateException("Unrecognized version type: $this") } .map { VersionType.byName(it) ?: throw IllegalStateException("Unrecognized version type: $this") }
.getOrThrow { IllegalStateException("bumpVersion requires you to set -PversionType=release|beta|alpha") } .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.open(gitDir.asFile.get()).use { git ->
git.tag().setName(name).call() git.tag().setName(name).call()
logger.warn("Created release $name (last was ${lastRelease.get()}). Make sure to push it!") logger.warn("Created release $name (last was ${lastRelease.get()}). Make sure to push it!")

View File

@ -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. * 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. * 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, versionType: VersionType) : this(major, minor, patch, versionType, null, null)
constructor(major: Int, minor: Int, patch: Int) : this(major, minor, patch, VersionType.RELEASE) 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 { override fun toString(): String {
return "$major.$minor.$patch" + when (type) { return "$major.$minor.$patch" + when (type) {
VersionType.RELEASE -> "" VersionType.RELEASE -> typeSupplement ?: ""
else -> "-${type.semanticName}" + if(typeSupplement != null) ".$typeSupplement" else "" else -> "-${type.semanticName}" + if(typeSupplement != null) ".$typeSupplement" else ""
} + if (build == null) "" else "+$build" } + 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) 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 { companion object {
private val identifier = Regex("[a-zA-Z1-9][a-zA-Z0-9]*") 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 number = Regex("[1-9][0-9]*|0")
private val versionCore = Regex("($number)\\.($number)(?:\\.($number))?") private val versionCore = Regex("($number)\\.($number)(?:\\.($number))?")
private val legacyVersion = Regex("([vba]|rc)$versionCore(\\+$buildPattern)?") 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 { fun parse(source: String): SemanticVersion {
val legacyMatch = legacyVersion.matchEntire(source) 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( return SemanticVersion(
m[1].toInt(), m[2].toInt(), m[3].ifEmpty { "0" }.toInt(), m[1].toInt(), m[2].toInt(), m[3].ifEmpty { "0" }.toInt(),
VersionType.byName(m[4].ifEmpty { "release" })!!, VersionType.byName(m[4].ifEmpty { "release" })!!,
m[5].ifEmpty { null }?.trimStart('.')?.toInt(), m[5].ifEmpty { null }?.trimStart('.'),
m[6].ifEmpty { null }?.substring(1) m[6].ifEmpty { null }?.substring(1)
) )
} }

View File

@ -69,4 +69,5 @@ tasks.register("bumpVersion", BumpVersionTask::class) {
nextVersionType = project.provider { nprop("nextVersionType") } nextVersionType = project.provider { nprop("nextVersionType") }
nextRelease = project.provider { project.nextRelease } nextRelease = project.provider { project.nextRelease }
lastRelease = project.provider { project.lastRelease } lastRelease = project.provider { project.lastRelease }
typeSupplement = project.provider { nprop("typeSupplement") }
} }