Skip to content

Commit

Permalink
Bypass versionPolicyFindIssues and versionPolicyAssessCompatibility i…
Browse files Browse the repository at this point in the history
…f skip is true

This is a bit dirty because those tasks are expected to return a result. Skipping a task that returns a result means that we still have to return a result somehow (unless we fail the task). Here, we return an empty result.
  • Loading branch information
julienrf committed Nov 29, 2023
1 parent 00494f0 commit 923f7cb
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -314,22 +314,35 @@ object SbtVersionPolicySettings {
}
}
}.value,
versionPolicyFindIssues := {
val dependencyIssues = versionPolicyFindDependencyIssues.value
val mimaIssues = versionPolicyFindMimaIssues.value
assert(
dependencyIssues.map(_._1.revision).toSet == mimaIssues.map(_._1.revision).toSet,
"Dependency issues and Mima issues must be checked against the same previous releases"
)
for ((previousModule, dependencyReport) <- dependencyIssues) yield {
val (_, problems) =
mimaIssues
.find { case (id, _) => previousModule.revision == id.revision }
.get // See assertion above
previousModule -> (dependencyReport, problems)
}
},
versionPolicyAssessCompatibility := {
versionPolicyFindIssues := Def.ifS((versionPolicyFindIssues / skip).toTask)(Def.task {
streams.value.log.debug("Not finding incompatibilities with previous releases because 'versionPolicyFindIssues / skip' is 'true'")
Seq.empty[(ModuleID, (DependencyCheckReport, Seq[(IncompatibilityType, Problem)]))]
})(
Def.ifS[Seq[(ModuleID, (DependencyCheckReport, Seq[(IncompatibilityType, Problem)]))]](Def.task {
versionPolicyPreviousVersions.value.isEmpty
})(Def.task {
throw new MessageOnlyException("Unable to find compatibility issues because versionPolicyPreviousVersions is empty.")
})(Def.task {
versionPolicyPreviousVersions.value
val dependencyIssues = versionPolicyFindDependencyIssues.value
val mimaIssues = versionPolicyFindMimaIssues.value
assert(
dependencyIssues.map(_._1.revision).toSet == mimaIssues.map(_._1.revision).toSet,
"Dependency issues and Mima issues must be checked against the same previous releases"
)
for ((previousModule, dependencyReport) <- dependencyIssues) yield {
val (_, problems) =
mimaIssues
.find { case (id, _) => previousModule.revision == id.revision }
.get // See assertion above
previousModule -> (dependencyReport, problems)
}
})
).value,
versionPolicyAssessCompatibility := Def.ifS((versionPolicyAssessCompatibility / skip).toTask)(Def.task {
streams.value.log.debug("Not assessing the compatibility with previous releases because 'versionPolicyAssessCompatibility / skip' is 'true'")
Seq.empty[(ModuleID, Compatibility)]
})(Def.task {
// Results will be flawed if the `versionPolicyIntention` is set to `BinaryCompatible` or `None`
// because `versionPolicyFindIssues` only reports the issues that violate the intended compatibility level
if (versionPolicyIntention.?.value.exists(_ != Compatibility.BinaryAndSourceCompatible)) {
Expand All @@ -353,12 +366,13 @@ object SbtVersionPolicySettings {
}
previousRelease -> compatibility
}
}
}).value
)

def skipSettings = Seq(
versionCheck / skip := (publish / skip).value,
versionPolicyCheck / skip := (publish / skip).value
versionPolicyCheck / skip := (publish / skip).value,
versionPolicyAssessCompatibility / skip := (publish / skip).value,
)

def schemesGlobalSettings = Seq(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,10 @@ val v101 =
version := "1.0.1",
versionPolicyIntention := Compatibility.BinaryCompatible
)

val root =
project.in(file("."))
.settings(
name := "library-test-skip-root",
)
.aggregate(v101)
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@
> set v101/publish/skip := true
> v101/versionPolicyCheck
> v101/versionCheck

-> root/versionPolicyAssessCompatibility
> set root/publish/skip := true
> root/versionPolicyAssessCompatibility

0 comments on commit 923f7cb

Please sign in to comment.