From db6d7d2edbb0a40f092c9885de193f5691789b64 Mon Sep 17 00:00:00 2001 From: Li Haoyi Date: Tue, 30 May 2023 17:04:24 -0700 Subject: [PATCH] Distribute Mill Assembly via Maven Central (#2560) Creates a stub `dist` module whose only purpose is to take the `dev.assembly` and put it on maven central, which the updated bootstrap script will download. This should help reduce the number of external failure points in Mill bootstrap script; rather than having hard dependency on both Github and Maven Central, this PR reduces it to only a hard dependency on Maven Central. Maven Central is also by default a write-only package store. That means that short of sending them a lawyer letter, the packages published there are immutable (https://central.sonatype.org/faq/can-i-change-a-component). This is in contrast to Github release assets which are read/write. With Github, a bug in our CI auto-upload system could easily override/delete/corrupt already-published assemblies, causing a widespread outage to anyone depending on the bootstrap script (e.g. in CI) until someone fixes it. It is also vulnerable to Github outages, which are not unheard of. Distribution via Maven Central removes both Github outages and over-writing-existing-artifacts as possible failure modes. While Sonatype can and does have outages, that would already cause a failure in Mill's bootstrapping, so it would be no worse than it already is today The validity of the various URLs and bootstrap scripts etc. have been tested manually, but end-to-end testing will need to be done post-merge --- build.sc | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/build.sc b/build.sc index a75d878d71c..5e5a32aee69 100644 --- a/build.sc +++ b/build.sc @@ -1204,6 +1204,11 @@ object runner extends MillPublishScalaModule { } } +object dist extends MillPublishJavaModule{ + def jar = dev.assembly() + def moduleDeps = Seq(runner) +} + object dev extends MillPublishScalaModule { def moduleDeps = Seq(runner) @@ -1253,8 +1258,10 @@ object dev extends MillPublishScalaModule { mill.scalalib.Assembly.Rule.ExcludePattern("mill/local-test-overrides/.*") ) + // All modules that we want to aggregate as part of this `dev` assembly. + // Excluding itself, and the `dist` module that uses it lazy val allPublishModules = build.millInternal.modules.collect { - case m: PublishModule if m ne this => m + case m: PublishModule if (m ne this) && (m ne dist) => m } def assembly = T { @@ -1617,13 +1624,18 @@ def millBootstrap = T.sources(T.workspace / "mill") def bootstrapLauncher = T { val outputPath = T.ctx.dest / "mill" - val millBootstrapGrepPrefix = "\nDEFAULT_MILL_VERSION=" + val millBootstrapGrepPrefix = "(\n *DEFAULT_MILL_VERSION=)" + val millDownloadUrlPrefix = "(\n *MILL_DOWNLOAD_URL=)" os.write( outputPath, os.read(millBootstrap().head.path) .replaceAll( millBootstrapGrepPrefix + "[^\\n]+", - millBootstrapGrepPrefix + millVersion() + "$1" + millVersion() + ) + .replaceAll( + millDownloadUrlPrefix + "[^\\n]+", + "$1" + "\"https://repo1.maven.org/maven2/com/lihaoyi/mill-dist/\\$MILL_VERSION/mill-dist-\\$MILL_VERSION.jar\"" ) ) os.perms.set(outputPath, "rwxrwxrwx")