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

Add MIMA_CHECK_DIRECTION environment input for direction #98

Merged
merged 2 commits into from
Apr 15, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
26 changes: 21 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,29 @@ object module extends ScalaModule with PublishModule with Mima {

### mimaCheckDirection

The required direction of binary compatibility can be set by overriding `mimaCheckDirection`:
The required direction of binary compatibility can be set in two ways:

```scala
override def mimaCheckDirection = CheckDirection.Both
```
- By setting the `MIMA_CHECK_DIRECTION` environment variable when running Mill
```
MIMA_CHECK_DIRECTION=forward mill __.mimaReportBinaryIssues
```

The possible values are `backward` (default), `forward` and `both`.

This is useful when you want to check for different directions at the same time,
for example when you might want to have separate CI checks for forward and
backward compatibility to evaluate if changes introduce source compatibilities.

- By overriding `mimaCheckDirection`:

```scala
override def mimaCheckDirection = CheckDirection.Both
```

The possible values are `CheckDirection.Backward` (default), `CheckDirection/Forward` and `CheckDirection.Both`.

The possible directions are `Backward` (default), `Forward` and `Both`.
This is useful when the setting is static and you want to keep the setting in
your `build.sc` file.

### mimaBinaryIssueFilters

Expand Down
6 changes: 1 addition & 5 deletions build.sc
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import mill._

import mill.scalalib._
import mill.scalalib.api.Util.scalaNativeBinaryVersion
import mill.scalalib.publish._
import $ivy.`com.lihaoyi::mill-contrib-buildinfo:`
import mill.contrib.buildinfo.BuildInfo
import $ivy.`com.lihaoyi::mill-contrib-bloop:$MILL_VERSION`
import $ivy.`de.tototec::de.tobiasroeser.mill.integrationtest::0.6.1`
import de.tobiasroeser.mill.integrationtest._
import $ivy.`com.goyeau::mill-scalafix::0.2.11`
Expand Down Expand Up @@ -53,9 +51,7 @@ class MillMimaCross(val millBinaryVersion: String)
override def moduleDeps = super.moduleDeps ++ Seq(`mill-mima-worker-api`)
override def artifactName = s"mill-mima_mill$millBinaryVersion"
override def millSourcePath = super.millSourcePath / os.up
def mimaPreviousArtifacts = Agg(
ivy"com.github.lolgab::mima_mill$millBinaryVersion:0.0.1"
)
def mimaPreviousVersions = Seq("0.0.17")
override def sources = T.sources(
super.sources() ++ Seq(
millSourcePath / s"src-mill${millVersion(millBinaryVersion).split('.').take(2).mkString(".")}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.github.lolgab.mill.mima

import upickle.default._

sealed trait CheckDirection
sealed trait CheckDirection extends Product with Serializable
object CheckDirection {
case object Backward extends CheckDirection
case object Forward extends CheckDirection
Expand Down
17 changes: 16 additions & 1 deletion mill-mima/src/com/github/lolgab/mill/mima/MimaBase.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,22 @@ private[mima] trait MimaBase
)
}

def mimaCheckDirection: Target[CheckDirection] = T { CheckDirection.Backward }
private def mimaCheckDirectionInput = T.input {
T.env.get("MIMA_CHECK_DIRECTION")
}

/** Compatibility checking direction. */
def mimaCheckDirection: Target[CheckDirection] = T {
mimaCheckDirectionInput() match {
case Some("both") => Result.Success(CheckDirection.Both)
case Some("forward") => Result.Success(CheckDirection.Forward)
case Some("backward") | None => Result.Success(CheckDirection.Backward)
case Some(other) =>
Result.Failure(
s"Invalid check direction \"$other\". Valid values are \"backward\", \"forward\" or \"both\"."
)
}
}

private[mima] def resolvedMimaPreviousArtifacts: T[Agg[(Dep, PathRef)]] = T {
resolveSeparateNonTransitiveDeps(mimaPreviousArtifacts)().map(p =>
Expand Down