Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support non-SemVer version numbers #84

Closed
bric3 opened this issue Oct 27, 2021 · 0 comments
Closed

Support non-SemVer version numbers #84

bric3 opened this issue Oct 27, 2021 · 0 comments
Labels
enhancement New feature or request
Milestone

Comments

@bric3
Copy link

bric3 commented Oct 27, 2021

Without thinking much I created a version with this scheme major.minor

pluginVerison = 0.1
changelog {
    version.set(properties("pluginVersion"))
    path.set("${rootProject.projectDir}/CHANGELOG.md")
    header.set(provider { "[${version.get()}] - ${date()}" })
    itemPrefix.set("-")
    keepUnreleasedSection.set(true)
    unreleasedTerm.set("[Unreleased]")
    groups.set(emptyList())
}

tasks.patchPluginXml {
        version.set(properties("pluginVersion"))
        // ...
        changeNotes.set(provider {
            changelog.run {
                getOrNull(properties("pluginVersion")) ?: getLatest()
            }.toHTML()
        })
    }

This generated a changelog version header like this :

## [0.2.0] - 2021-10-27
### Added
- stuff

The patchPluginXML task failed with this exception

* What went wrong:
Execution failed for task ':patchPluginXml'.
> Error while evaluating property 'changeNotes' of task ':patchPluginXml'
   > Failed to calculate the value of task ':patchPluginXml' property 'changeNotes'.
      > org.jetbrains.changelog.exceptions.HeaderParseException: Header '[0.2] - 2021-10-27' does not contain version number.

By looking how the code works I identified the issue here

else -> split("""[^-+.0-9a-zA-Z]+""".toRegex()).firstOrNull(
headerParserRegex::matches

By default if the header regex is semver

internal fun getHeaderParserRegex() = when (val value = headerParserRegex.orNull) {
is Regex -> value
is String -> value.toRegex()
is Pattern -> value.toRegex()
null -> ChangelogPluginConstants.SEM_VER_REGEX
else -> throw IllegalArgumentException("Unsupported type of $value. Expected value types: Regex, String, Pattern.")
}

val SEM_VER_REGEX =
"""^((0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?)${'$'}""".toRegex() // ktlint-disable max-line-length
}

I suggest to rephrase the string in HeaderParserException to mention a mismatch between the actual version and the headerParserRegex.

@YannCebron YannCebron changed the title Tweak Support non-SemVer version numbres Apr 26, 2022
@YannCebron YannCebron changed the title Support non-SemVer version numbres Support non-SemVer version numbers Apr 26, 2022
@YannCebron YannCebron added the enhancement New feature or request label Apr 26, 2022
@hsz hsz added this to the next milestone Oct 18, 2022
hsz added a commit that referenced this issue Oct 18, 2022
@hsz hsz closed this as completed Oct 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants