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

fix #155 by extracting version without suffix #175

Merged
merged 5 commits into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
# SBT stuff
target/

# Bloop/Metals/VSCode stuff
.bloop
.bsp
.metals
.vscode
metals.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ object DependencyCheckReport {
def message = "missing dependency"
}

@data class SemVerVersion(major: Int, minor: Int, patch: Int, suffix: Seq[Version.Item])
seigert marked this conversation as resolved.
Show resolved Hide resolved

@deprecated("This method is internal.", "1.1.0")
def apply(
currentModules: Map[(String, String), String],
Expand Down Expand Up @@ -153,24 +155,37 @@ object DependencyCheckReport {
previousVersion == currentVersion
case VersionCompatibility.SemVer | VersionCompatibility.EarlySemVer | VersionCompatibility.SemVerSpec =>
// Early SemVer and SemVer Spec are equivalent regarding source compatibility
extractSemVerNumbers(currentVersion).zip(extractSemVerNumbers(previousVersion)).headOption match {
case Some(((currentMajor, currentMinor, currentPatch), (previousMajor, previousMinor, previousPatch))) =>
currentMajor == previousMajor && {
if (currentMajor == 0)
currentMinor == previousMinor && currentPatch == previousPatch
else
currentMinor == previousMinor && currentPatch >= previousPatch
(extractSemVerNumbers(currentVersion), extractSemVerNumbers(previousVersion)) match {
case (Some(currentSemVer), Some(previousSemVer)) =>
def sameMajor = currentSemVer.major == previousSemVer.major
def sameMinor = currentSemVer.minor == previousSemVer.minor
def samePatch = currentSemVer.patch == previousSemVer.patch
def sameSuffix = currentSemVer.suffix == previousSemVer.suffix

if (currentSemVer.major == 0) {
sameMajor && sameMinor && samePatch && sameSuffix
} else {
// 1.0.0-RC1 may be source incompatible to 1.0.0-RC2
// but!
// 1.0.1-RC2 must be source compatible both to 1.0.1-RC1 and 1.0.0 (w/o suffix!)
def compatPatch =
(currentSemVer.patch > 0 && samePatch) ||
(currentSemVer.patch > previousSemVer.patch && previousSemVer.suffix.isEmpty)

sameMajor && sameMinor && ((samePatch && sameSuffix) || compatPatch)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this could be simplified to:

Suggested change
def compatPatch =
(currentSemVer.patch > 0 && samePatch) ||
(currentSemVer.patch > previousSemVer.patch && previousSemVer.suffix.isEmpty)
sameMajor && sameMinor && ((samePatch && sameSuffix) || compatPatch)
def compatPatch =
previousSemVer.suffix.isEmpty || previousSemVer.patch > 0
sameMajor && sameMinor && compatPatch

(untested)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've used your check, but we still need (samePatch && sameSuffix) to allow 1.0.0-RC1 be source compat to itself. :(

}
case None => currentVersion == previousVersion
case _ => false
}
}

private def extractSemVerNumbers(versionString: String): Option[(Int, Int, Int)] = {
private def extractSemVerNumbers(versionString: String): Option[SemVerVersion] = {
val version = Version(versionString)
if (version.items.size == 3 && version.items.forall(_.isInstanceOf[Version.Number])) {
val Seq(major, minor, patch) = version.items.collect { case num: Version.Number => num.value }
Some((major, minor, patch))
} else None // Not a normalized version number (e.g., 1.0.0-RC1)
version.items match {
case Vector(major: Version.Number, minor: Version.Number, patch: Version.Number, suffix @ _*) =>
Some(SemVerVersion(major.value, minor.value, patch.value, suffix))
case _ =>
None // Not a semantic version number (e.g., 1.0-RC1)
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,29 @@ object DependencyCheckReportTest extends BasicTestSuite {
withScheme(VersionCompatibility.PackVer) { (isCompatible, isBreaking) =>
isBreaking ("1.0.1", "1.0.0")
isBreaking ("1.1.0", "1.0.0")
isBreaking ("2.0.0", "1.0.0")
isCompatible("1.2.3", "1.2.3")
isBreaking ("1.2.3", "1.2.3-RC1")
isCompatible("1.2.3-RC1", "1.2.3-RC1")
isBreaking ("1.2.3", "1.2.3-RC1")
isCompatible("1.2.3", "1.2.3")
isBreaking ("2.0.0", "1.0.0")
}
withScheme(VersionCompatibility.EarlySemVer) { (isCompatible, isBreaking) =>
isBreaking ("0.1.1", "0.1.0")
isBreaking ("0.2.0", "0.1.0")
isBreaking ("1.0.0", "0.1.0")
isCompatible("1.0.1", "1.0.0")
isBreaking ("1.1.0", "1.0.0")
isBreaking ("2.0.0", "1.0.0")
isBreaking ("1.0.0", "1.0.0-RC1")
isCompatible("1.0.0-RC1", "1.0.0-RC1")
isBreaking ("0.1.1", "0.1.0")
isBreaking ("0.2.0", "0.1.0")
isCompatible("1.0.0-RC1", "1.0.0-RC1")
isBreaking ("1.0.0-RC2", "1.0.0-RC1")
isBreaking ("1.0.0", "1.0.0-RC1")
isCompatible("1.0.1-RC1", "1.0.0")
isCompatible("1.0.1-RC2", "1.0.1-RC1")
isBreaking ("1.0.1", "1.0.0-RC1")
isCompatible("1.0.1", "1.0.0")
isBreaking ("1.1.0-RC1", "1.0.0")
isBreaking ("1.1.0-RC2", "1.1.0-RC1")
isBreaking ("1.1.0", "1.0.0-RC1")
isBreaking ("1.1.0", "1.0.0")
isCompatible("1.2.1-SNAPSHOT", "1.2.0")
seigert marked this conversation as resolved.
Show resolved Hide resolved
seigert marked this conversation as resolved.
Show resolved Hide resolved
isBreaking ("2.0.0-RC1", "1.0.0")
isBreaking ("2.0.0", "1.0.0-RC1")
isBreaking ("2.0.0", "1.0.0")
}
}

Expand Down