Skip to content

Avoid false positives versionCheck when versionScheme != early-semver #123

@bjaglin

Description

@bjaglin

/**
* Validates that the given new `version` matches the claimed `compatibility` level.
* @return Some validation error, or None if the version is valid.
*/
def isValidVersion(compatibility: Compatibility, version: String): Boolean = {
val versionNumber = VersionNumber(version)
val major = versionNumber._1
val minor = versionNumber._2
val patch = versionNumber._3
compatibility match {
case Compatibility.None =>
// No compatibility is guaranteed: the major version must be incremented (or the minor version, if major is 0)
if (major.contains(0)) patch.contains(0) // minor version bump
else minor.contains(0) && patch.contains(0) // major version bump
case Compatibility.BinaryCompatible =>
// No source compatibility is guaranteed, the minor version must be incremented (or the patch version, if major is 0)
if (major.contains(0)) true // always OK
else patch.contains(0) // minor version bump
case Compatibility.BinaryAndSourceCompatible =>
// OK, the version can be set to whatever
true
}
}
assumes the module being checked is early-semver as of v2.0.1.

It should either support other versionSchemes or fail if it's not early-semver.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions