From d0f696152d2e09f357bae894e4eaf32b8a27266f Mon Sep 17 00:00:00 2001 From: Martin Mauch Date: Wed, 18 Dec 2024 14:09:01 +0100 Subject: [PATCH] Update mill to 0.12.4 --- .github/workflows/ci.yml | 2 +- .mill-version | 2 +- build.sc | 42 +++++++------ itest/src/cyclical/build.sc | 3 +- itest/src/minimal/build.sc | 3 +- itest/src/reconciledRange/build.sc | 4 +- .../mill/github/dependency/graph/Graph.scala | 8 +++ .../github/dependency/graph/Resolver.scala | 3 +- .../github/dependency/graph/Discover.scala | 3 +- .../mill/github/dependency/graph/Graph.scala | 12 ++++ .../github/dependency/graph/Discover.scala | 7 +++ .../mill/github/dependency/graph/Graph.scala | 8 +++ .../github/dependency/graph/Resolver.scala | 62 +++++++++++++++++++ .../mill/github/dependency/graph/Github.scala | 10 +-- .../graph/{Graph.scala => GraphModule.scala} | 9 +-- 15 files changed, 137 insertions(+), 41 deletions(-) create mode 100644 plugin/src-mill0.10/io/kipp/mill/github/dependency/graph/Graph.scala create mode 100644 plugin/src-mill0.11/io/kipp/mill/github/dependency/graph/Graph.scala create mode 100644 plugin/src-mill0.12/io/kipp/mill/github/dependency/graph/Discover.scala create mode 100644 plugin/src-mill0.12/io/kipp/mill/github/dependency/graph/Graph.scala create mode 100644 plugin/src-mill0.12/io/kipp/mill/github/dependency/graph/Resolver.scala rename plugin/src/io/kipp/mill/github/dependency/graph/{Graph.scala => GraphModule.scala} (74%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fa47103..6a3e390 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -41,7 +41,7 @@ jobs: strategy: fail-fast: false matrix: - java: ['8', '17'] + java: ['11', '17'] steps: - uses: actions/checkout@v4 diff --git a/.mill-version b/.mill-version index bd0119f..e01e0dd 100644 --- a/.mill-version +++ b/.mill-version @@ -1 +1 @@ -0.11.12 +0.12.4 diff --git a/build.sc b/build.sc index 5092b31..4262a5b 100644 --- a/build.sc +++ b/build.sc @@ -1,4 +1,4 @@ -import $ivy.`com.goyeau::mill-scalafix::0.4.0` +import $ivy.`com.goyeau::mill-scalafix::0.4.2` import $ivy.`com.lihaoyi::mill-contrib-buildinfo:$MILL_VERSION` import $ivy.`de.tototec::de.tobiasroeser.mill.integrationtest::0.7.1` import $ivy.`io.chris-kipp::mill-ci-release::0.1.10` @@ -17,7 +17,7 @@ import de.tobiasroeser.mill.vcs.version.VcsVersion import io.kipp.mill.ci.release.CiReleaseModule import io.kipp.mill.ci.release.SonatypeHost -val millVersions = Seq("0.10.15", "0.11.12") +val millVersions = Seq("0.12.4", "0.11.12", "0.10.15") val millBinaryVersions = millVersions.map(scalaNativeBinaryVersion) val scala213 = "2.13.14" val artifactBase = "mill-github-dependency-graph" @@ -102,25 +102,27 @@ trait ItestCross extends Cross.Module[String] with MillIntegrationTestModule { override def testInvocations: T[Seq[(PathRef, Seq[TestInvocation.Targets])]] = T { + val env = if(millTestVersion() >= "0.12") + Map( + "COURSIER_REPOSITORIES" -> s"central sonatype:releases ivy:file://${T.dest.toString.replaceFirst("testInvocations", "test")}/ivyRepo/local/[organisation]/[module]/[revision]/[type]s/[artifact].[ext]" + ) + else + Map.empty[String, String] Seq( - PathRef(testBase / "minimal") -> Seq( - TestInvocation.Targets(Seq("checkManifest"), noServer = true) - ), - PathRef(testBase / "directRelationship") -> Seq( - TestInvocation.Targets(Seq("verify"), noServer = true) - ), - PathRef(testBase / "eviction") -> Seq( - TestInvocation.Targets(Seq("verify"), noServer = true) - ), - PathRef(testBase / "range") -> Seq( - TestInvocation.Targets(Seq("verify"), noServer = true) - ), - PathRef(testBase / "reconciledRange") -> Seq( - TestInvocation.Targets(Seq("verify"), noServer = true) - ), - PathRef(testBase / "cyclical") -> Seq( - TestInvocation.Targets(Seq("checkManifest"), noServer = true) + "minimal" -> "checkManifest", + "directRelationship" -> "verify", + "eviction" -> "verify", + "range" -> "verify", + "reconciledRange" -> "verify", + "cyclical" -> "checkManifest" + ).map { case (testName, testMethod) => + PathRef(testBase / testName) -> Seq( + TestInvocation.Targets( + Seq(testMethod), + noServer = true, + env = env + ) ) - ) + } } } diff --git a/itest/src/cyclical/build.sc b/itest/src/cyclical/build.sc index f72e122..a93ddc1 100644 --- a/itest/src/cyclical/build.sc +++ b/itest/src/cyclical/build.sc @@ -21,7 +21,8 @@ object overflow extends ScalaModule { } def checkManifest(ev: Evaluator) = T.command { - val expected = ujson.read(os.read(os.pwd / "manifests.json")) + val projectDir = Iterator.iterate(os.pwd)(_ / os.up).find(dir => os.exists(dir / "manifests.json")).get + val expected = ujson.read(os.read(projectDir / "manifests.json")) val manifestMapping = Graph.generate(ev)() diff --git a/itest/src/minimal/build.sc b/itest/src/minimal/build.sc index 03162b0..6e1b382 100644 --- a/itest/src/minimal/build.sc +++ b/itest/src/minimal/build.sc @@ -17,7 +17,8 @@ object minimal extends ScalaModule { } def checkManifest(ev: Evaluator) = T.command { - val expected = ujson.read(os.read(os.pwd / "manifests.json")) + val projectDir = Iterator.iterate(os.pwd)(_ / os.up).find(dir => os.exists(dir / "manifests.json")).get + val expected = ujson.read(os.read(projectDir / "manifests.json")) val manifestMapping = Graph.generate(ev)() diff --git a/itest/src/reconciledRange/build.sc b/itest/src/reconciledRange/build.sc index a1795f2..569302e 100644 --- a/itest/src/reconciledRange/build.sc +++ b/itest/src/reconciledRange/build.sc @@ -10,7 +10,7 @@ object minimalDep extends ScalaModule { def scalaVersion = "2.13.8" def ivyDeps = Agg( - ivy"com.fasterxml.jackson.core:jackson-core:2.13.3" + ivy"com.fasterxml.jackson.core:jackson-core:2.12.3" ) } @@ -50,7 +50,7 @@ def verify(ev: Evaluator) = T.command { // out to ensure we're not creating invalid PURLs. val expected = Set( "org.scala-lang:scala-library:2.13.8", - "com.fasterxml.jackson.core:jackson-core:2.13.3", + "com.fasterxml.jackson.core:jackson-core:2.12.3", // NOTICE that com.fasterxml.jackson.core:jackson-core:[2.7.0,2.12.3] is not here "com.fasterxml.jackson.core:jackson-core:2.12.3", "com.fasterxml.jackson.core:jackson-databind:2.12.3", diff --git a/plugin/src-mill0.10/io/kipp/mill/github/dependency/graph/Graph.scala b/plugin/src-mill0.10/io/kipp/mill/github/dependency/graph/Graph.scala new file mode 100644 index 0000000..068a128 --- /dev/null +++ b/plugin/src-mill0.10/io/kipp/mill/github/dependency/graph/Graph.scala @@ -0,0 +1,8 @@ +package io.kipp.mill.github.dependency.graph + +object Graph extends GraphModule { + + import Discover._ + lazy val millDiscover: mill.define.Discover[this.type] = + mill.define.Discover[this.type] +} diff --git a/plugin/src-mill0.10/io/kipp/mill/github/dependency/graph/Resolver.scala b/plugin/src-mill0.10/io/kipp/mill/github/dependency/graph/Resolver.scala index c404809..0790f1d 100644 --- a/plugin/src-mill0.10/io/kipp/mill/github/dependency/graph/Resolver.scala +++ b/plugin/src-mill0.10/io/kipp/mill/github/dependency/graph/Resolver.scala @@ -21,7 +21,7 @@ object Resolver { private[graph] def resolveModuleTrees( evaluator: Evaluator, javaModules: Seq[JavaModule] - ): Seq[ModuleTrees] = Evaluator.evalOrThrow(evaluator) { + ): Seq[ModuleTrees] = evaluator.evalOrThrow() { javaModules.map { javaModule => T.task { @@ -40,6 +40,7 @@ object Resolver { deps = deps, mapDependencies = Some(mapDeps), customizer = custom, + coursierCacheCustomizer = None, ctx = Some(T.log) ) diff --git a/plugin/src-mill0.11/io/kipp/mill/github/dependency/graph/Discover.scala b/plugin/src-mill0.11/io/kipp/mill/github/dependency/graph/Discover.scala index 03459d1..8d100cc 100644 --- a/plugin/src-mill0.11/io/kipp/mill/github/dependency/graph/Discover.scala +++ b/plugin/src-mill0.11/io/kipp/mill/github/dependency/graph/Discover.scala @@ -1,6 +1,7 @@ package io.kipp.mill.github.dependency.graph private[graph] object Discover { - implicit def millEvaluatorTokenReader = + implicit def millEvaluatorTokenReader + : mainargs.TokensReader[mill.eval.Evaluator] = mill.main.TokenReaders.millEvaluatorTokenReader } diff --git a/plugin/src-mill0.11/io/kipp/mill/github/dependency/graph/Graph.scala b/plugin/src-mill0.11/io/kipp/mill/github/dependency/graph/Graph.scala new file mode 100644 index 0000000..e04815f --- /dev/null +++ b/plugin/src-mill0.11/io/kipp/mill/github/dependency/graph/Graph.scala @@ -0,0 +1,12 @@ +package io.kipp.mill.github.dependency.graph + +import scala.annotation.nowarn + +// In here for the Discover import +@nowarn("msg=Unused import") +object Graph extends GraphModule { + + import Discover._ + lazy val millDiscover: mill.define.Discover[this.type] = + mill.define.Discover[this.type] +} diff --git a/plugin/src-mill0.12/io/kipp/mill/github/dependency/graph/Discover.scala b/plugin/src-mill0.12/io/kipp/mill/github/dependency/graph/Discover.scala new file mode 100644 index 0000000..8d100cc --- /dev/null +++ b/plugin/src-mill0.12/io/kipp/mill/github/dependency/graph/Discover.scala @@ -0,0 +1,7 @@ +package io.kipp.mill.github.dependency.graph + +private[graph] object Discover { + implicit def millEvaluatorTokenReader + : mainargs.TokensReader[mill.eval.Evaluator] = + mill.main.TokenReaders.millEvaluatorTokenReader +} diff --git a/plugin/src-mill0.12/io/kipp/mill/github/dependency/graph/Graph.scala b/plugin/src-mill0.12/io/kipp/mill/github/dependency/graph/Graph.scala new file mode 100644 index 0000000..2ea6e45 --- /dev/null +++ b/plugin/src-mill0.12/io/kipp/mill/github/dependency/graph/Graph.scala @@ -0,0 +1,8 @@ +package io.kipp.mill.github.dependency.graph + +object Graph extends GraphModule { + + import Discover._ + lazy val millDiscover: mill.define.Discover = + mill.define.Discover[this.type] +} diff --git a/plugin/src-mill0.12/io/kipp/mill/github/dependency/graph/Resolver.scala b/plugin/src-mill0.12/io/kipp/mill/github/dependency/graph/Resolver.scala new file mode 100644 index 0000000..2004f4e --- /dev/null +++ b/plugin/src-mill0.12/io/kipp/mill/github/dependency/graph/Resolver.scala @@ -0,0 +1,62 @@ +package io.kipp.mill.github.dependency.graph + +import coursier.graph.DependencyTree +import mill._ +import mill.eval.Evaluator +import mill.scalalib.JavaModule +import mill.scalalib.Lib + +/** Utils to help find all your modules and resolve their dependencies. + */ +object Resolver { + + /** Given an evaluator and your javaModules, use coursier to resolve all of + * their dependencies into trees. + * + * @param evaluator Evaluator passed in from the command + * @param javaModules All the JavaModules to resolve dependencies from + * @return A collection of ModuleTrees + */ + private[graph] def resolveModuleTrees( + evaluator: Evaluator, + javaModules: Seq[JavaModule] + ): Seq[ModuleTrees] = evaluator.evalOrThrow() { + javaModules.map { javaModule => + Task.Anon { + + val deps = + javaModule.transitiveCompileIvyDeps() ++ javaModule + .transitiveIvyDeps() + val repos = javaModule.repositoriesTask() + val mapDeps = javaModule.mapDependencies() + val custom = javaModule.resolutionCustomizer() + + Lib + .resolveDependenciesMetadataSafe( + repositories = repos, + deps = deps, + mapDependencies = Some(mapDeps), + customizer = custom, + ctx = Some(T.log) + ) + .map { resolution => + val trees = + DependencyTree( + resolution = resolution, + roots = deps.map(_.dep).toSeq + ) + + ModuleTrees( + javaModule, + trees + ) + + } + + } + } + } + + private[graph] def computeModules(ev: Evaluator) = + ev.rootModule.millInternal.modules.collect { case j: JavaModule => j } +} diff --git a/plugin/src/io/kipp/mill/github/dependency/graph/Github.scala b/plugin/src/io/kipp/mill/github/dependency/graph/Github.scala index 9c1fdf3..4265bad 100644 --- a/plugin/src/io/kipp/mill/github/dependency/graph/Github.scala +++ b/plugin/src/io/kipp/mill/github/dependency/graph/Github.scala @@ -5,7 +5,7 @@ import io.kipp.github.dependency.graph.domain.Detector import io.kipp.github.dependency.graph.domain.Job import io.kipp.github.dependency.graph.domain.Manifest -import java.net.URL +import java.net.URI import java.time.Instant import scala.util.Properties @@ -16,7 +16,7 @@ import Writers._ */ object Github { - private val url = new URL( + private val url = new URI( s"${Env.githubApiUrl}/repos/${Env.githubRepository}/dependency-graph/snapshots" ) @@ -29,7 +29,7 @@ object Github { ctx.log.info("Submitting your snapshot to GitHub...") val payload = upickle.default.write(snapshot) val result = requests.post( - url.toString(), + url.toString, headers = Map( "Content-Type" -> "application/json", "Authorization" -> s"token ${Env.githubToken}" @@ -43,7 +43,7 @@ object Github { val totalDependencies = snapshot.manifests.values.foldLeft[Seq[String]](Seq.empty) { (total, manifest) => - total ++ manifest.resolved.map(_._1) + total ++ manifest.resolved.keys } val totalSize = totalDependencies.size val uniqueSize = totalDependencies.toSet.size @@ -69,7 +69,7 @@ object Github { val msg = s"""It looks like something went wrong when trying to submit your dependency graph. | - |[${result.statusCode}] ${result.statusMessage}""".stripMargin + |[${result.statusCode}] ${result.data}""".stripMargin throw new Exception(msg) } } diff --git a/plugin/src/io/kipp/mill/github/dependency/graph/Graph.scala b/plugin/src/io/kipp/mill/github/dependency/graph/GraphModule.scala similarity index 74% rename from plugin/src/io/kipp/mill/github/dependency/graph/Graph.scala rename to plugin/src/io/kipp/mill/github/dependency/graph/GraphModule.scala index 65c19f3..a15db6e 100644 --- a/plugin/src/io/kipp/mill/github/dependency/graph/Graph.scala +++ b/plugin/src/io/kipp/mill/github/dependency/graph/GraphModule.scala @@ -6,11 +6,7 @@ import mill.define.Command import mill.define.ExternalModule import mill.eval.Evaluator -import scala.annotation.nowarn - -// In here for the Discover import -@nowarn("msg=Unused import") -object Graph extends ExternalModule { +trait GraphModule extends ExternalModule { import Writers._ @@ -30,7 +26,4 @@ object Graph extends ExternalModule { manifests } - import Discover._ - lazy val millDiscover: mill.define.Discover[this.type] = - mill.define.Discover[this.type] }