Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,18 @@ final class MillAlg[F[_]](defaultResolvers: List[Resolver])(implicit
override protected val scalafixIssue: Option[String] =
Some("https://github.com/scala-steward-org/scala-steward/issues/2838")

private def getMillVersion(buildRootDir: File): F[Option[Version]] =
List(
buildRootDir / s".$millVersionName",
buildRootDir / ".config" / millVersionName
).collectFirstSomeM(fileAlg.readFile).map(_.flatMap(parser.parseMillVersion))
private def getMillVersion(buildRootDir: File): F[Option[Version]] = {
val fromConfigFile =
List(
buildRootDir / s".$millVersionName",
buildRootDir / ".config" / millVersionName
).collectFirstSomeM(fileAlg.readFile).map(_.flatMap(parser.parseMillVersion))
val fromBuildFile = List(buildRootDir / "build.mill", buildRootDir / "build.mill.scala")
.collectFirstSomeM(fileAlg.readFile)
.map(_.flatMap(parser.parseBuildFileMillVersion))

fromBuildFile.orElse(fromConfigFile)
}

private def getMillPluginDeps(
millVersion: Version,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ object parser {
def parseMillVersion(s: String): Option[Version] =
Option(s.trim).filter(_.nonEmpty).map(Version.apply)

private val millVersionRegex = """\s*\/\/\|\s*mill-version:\s*['"]?(.+?)['"]?\s*""".r
def parseBuildFileMillVersion(s: String): Option[Version] = {
s.linesIterator.collectFirst {
case millVersionRegex(version) => Version(version)
}
}

/** Used to correctly format the Mill plugin artifacts will when included look like:
* - import $ivy.`com.goyeau::mill-scalafix::0.2.10`
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,31 @@ class MillVersionParserTest extends FunSuite {
val parsed = parser.parseMillVersion(versionFileContent).map(_.value)
assertEquals(parsed, expected)
}

test(s"parse version from build.mill file") {
val buildMillFileContent = """
|//|
|//| mill-version: 1.0.5
|""".stripMargin
val parsed = parser.parseBuildFileMillVersion(buildMillFileContent).map(_.value)
assertEquals(parsed, Some("1.0.5"))
}

test(s"parse quoted version from build.mill file") {
val buildMillFileContent = """
|//|
|//| mill-version: "1.0.5"
|""".stripMargin
val parsed = parser.parseBuildFileMillVersion(buildMillFileContent).map(_.value)
assertEquals(parsed, Some("1.0.5"))
}

test(s"parse single quoted version from build.mill file") {
val buildMillFileContent = """
|//|
|//| mill-version: '1.0.5'
|""".stripMargin
val parsed = parser.parseBuildFileMillVersion(buildMillFileContent).map(_.value)
assertEquals(parsed, Some("1.0.5"))
}
}
2 changes: 1 addition & 1 deletion project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ object Dependencies {
val scalacheck = "org.scalacheck" %% "scalacheck" % "1.19.0"
val scalaStewardMillPluginArtifactName = "scala-steward-mill-plugin"
val scalaStewardMillPlugin =
"org.scala-steward" % s"${scalaStewardMillPluginArtifactName}_mill0.11_2.13" % "0.18.2"
"org.scala-steward" % s"${scalaStewardMillPluginArtifactName}_mill1_3" % "0.18.2-9-0ad5e5"
val tomlj = "org.tomlj" % "tomlj" % "1.1.1"
}