Skip to content

Commit 7dac44f

Browse files
authored
Migrate publishing to Sonatype Maven Central (#3704)
* Fix passing environment variables to the Sonatype publisher * Migrate publishing to Sonatype Maven Central
1 parent c0e412a commit 7dac44f

File tree

3 files changed

+47
-34
lines changed

3 files changed

+47
-34
lines changed

build.mill.scala

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import $packages._
44
import $ivy.`com.lihaoyi::mill-contrib-bloop:$MILL_VERSION`
55
import $ivy.`io.get-coursier::coursier-launcher:2.1.24`
66
import $ivy.`io.github.alexarchambault.mill::mill-native-image-upload:0.1.31-1`
7+
import build.ci.publishVersion
78
import build.project.deps
89
import deps.{Cli, Deps, Docker, InternalDeps, Java, Scala, TestDeps}
910
import build.project.publish
@@ -386,7 +387,7 @@ trait Core extends ScalaCliCrossSbtModule
386387
with ScalaCliScalafixModule {
387388
def crossScalaVersion: String = crossValue
388389

389-
def moduleDeps: Seq[PublishModule] = Seq(
390+
def moduleDeps: Seq[SonatypeCentralPublishModule] = Seq(
390391
config(crossScalaVersion)
391392
)
392393
def compileModuleDeps: Seq[JavaModule] = Seq(
@@ -577,8 +578,8 @@ trait Directives extends ScalaCliCrossSbtModule
577578
with ScalaCliPublishModule
578579
with HasTests
579580
with ScalaCliScalafixModule {
580-
def crossScalaVersion: String = crossValue
581-
def moduleDeps: Seq[PublishModule] = Seq(
581+
def crossScalaVersion: String = crossValue
582+
def moduleDeps: Seq[SonatypeCentralPublishModule] = Seq(
582583
options(crossScalaVersion),
583584
core(crossScalaVersion),
584585
`build-macros`(crossScalaVersion),
@@ -639,9 +640,9 @@ trait Directives extends ScalaCliCrossSbtModule
639640
trait Config extends ScalaCliCrossSbtModule
640641
with ScalaCliPublishModule
641642
with ScalaCliScalafixModule {
642-
def crossScalaVersion: String = crossValue
643-
def moduleDeps: Seq[PublishModule] = Seq(`specification-level`(crossScalaVersion))
644-
def ivyDeps: Target[Agg[Dep]] = {
643+
def crossScalaVersion: String = crossValue
644+
def moduleDeps: Seq[SonatypeCentralPublishModule] = Seq(`specification-level`(crossScalaVersion))
645+
def ivyDeps: Target[Agg[Dep]] = {
645646
val maybeCollectionCompat =
646647
if (crossScalaVersion.startsWith("2.12.")) Seq(Deps.collectionCompat)
647648
else Nil
@@ -666,8 +667,8 @@ trait Config extends ScalaCliCrossSbtModule
666667

667668
trait Options extends ScalaCliCrossSbtModule with ScalaCliPublishModule with HasTests
668669
with ScalaCliScalafixModule {
669-
def crossScalaVersion: String = crossValue
670-
def moduleDeps: Seq[PublishModule] = Seq(
670+
def crossScalaVersion: String = crossValue
671+
def moduleDeps: Seq[SonatypeCentralPublishModule] = Seq(
671672
core(crossScalaVersion)
672673
)
673674
def compileModuleDeps: Seq[JavaModule] = Seq(
@@ -723,17 +724,17 @@ trait Scala3Graal extends ScalaCliCrossSbtModule
723724
}
724725

725726
trait Scala3GraalProcessor extends CrossScalaModule with ScalaCliPublishModule {
726-
def moduleDeps: Seq[PublishModule] = Seq(`scala3-graal`(crossScalaVersion))
727-
def finalMainClass: Target[String] = "scala.cli.graal.CoursierCacheProcessor"
727+
def moduleDeps: Seq[SonatypeCentralPublishModule] = Seq(`scala3-graal`(crossScalaVersion))
728+
def finalMainClass: Target[String] = "scala.cli.graal.CoursierCacheProcessor"
728729
}
729730

730731
trait Build extends ScalaCliCrossSbtModule
731732
with ScalaCliPublishModule
732733
with HasTests
733734
with ScalaCliScalafixModule {
734-
def crossScalaVersion: String = crossValue
735-
def millSourcePath: os.Path = super.millSourcePath / os.up / "build"
736-
def moduleDeps: Seq[PublishModule] = Seq(
735+
def crossScalaVersion: String = crossValue
736+
def millSourcePath: os.Path = super.millSourcePath / os.up / "build"
737+
def moduleDeps: Seq[SonatypeCentralPublishModule] = Seq(
737738
options(crossScalaVersion),
738739
directives(crossScalaVersion),
739740
`scala-cli-bsp`,
@@ -931,7 +932,7 @@ trait Cli extends CrossSbtModule with ProtoBuildModule with CliLaunchers
931932
def javacOptions: Target[Seq[String]] = Task {
932933
super.javacOptions() ++ Seq("--release", "16")
933934
}
934-
def moduleDeps: Seq[PublishModule] = Seq(
935+
def moduleDeps: Seq[SonatypeCentralPublishModule] = Seq(
935936
`build-module`(crossScalaVersion),
936937
config(crossScalaVersion),
937938
`scala3-graal`(crossScalaVersion),
@@ -1343,10 +1344,16 @@ object `local-repo` extends LocalRepo {
13431344

13441345
// Helper CI commands
13451346
def publishSonatype(tasks: mill.main.Tasks[PublishModule.PublishData]) = Task.Command {
1347+
val pv = publishVersion()
1348+
System.err.println(s"Publish version: $pv")
1349+
val bundleName = s"$organization-$ghName-$pv"
1350+
System.err.println(s"Publishing bundle: $bundleName")
13461351
publish.publishSonatype(
13471352
data = define.Target.sequence(tasks.value)(),
13481353
log = Task.ctx().log,
1349-
workspace = Task.workspace
1354+
workspace = Task.workspace,
1355+
env = Task.env,
1356+
bundleName = bundleName
13501357
)
13511358
}
13521359

project/publish/package.mill.scala

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
package build.project.publish
22
import $ivy.`de.tototec::de.tobiasroeser.mill.vcs.version::0.4.0`
33
import $ivy.`org.eclipse.jgit:org.eclipse.jgit:6.8.0.202311291450-r`
4-
import build.project.settings, settings.{PublishLocalNoFluff, workspaceDirName}
5-
4+
import build.project.settings
5+
import com.lumidion.sonatype.central.client.core.{PublishingType, SonatypeCredentials}
6+
import settings.{PublishLocalNoFluff, workspaceDirName}
67
import de.tobiasroeser.mill.vcs.version._
7-
import mill._, scalalib._
8+
import mill._
9+
import scalalib._
810
import org.eclipse.jgit.api.Git
911

1012
import java.nio.charset.Charset
11-
1213
import scala.concurrent.duration._
1314
import scala.jdk.CollectionConverters._
1415

@@ -121,7 +122,7 @@ def finalPublishVersion: Target[String] = {
121122

122123
def organization = "org.virtuslab.scala-cli"
123124

124-
trait ScalaCliPublishModule extends PublishModule with PublishLocalNoFluff {
125+
trait ScalaCliPublishModule extends SonatypeCentralPublishModule with PublishLocalNoFluff {
125126
import mill.scalalib.publish._
126127
def pomSettings: Target[PomSettings] = PomSettings(
127128
description = artifactName(),
@@ -154,10 +155,14 @@ trait ScalaCliPublishModule extends PublishModule with PublishLocalNoFluff {
154155
def publishSonatype(
155156
data: Seq[PublishModule.PublishData],
156157
log: mill.api.Logger,
157-
workspace: os.Path
158+
workspace: os.Path,
159+
env: Map[String, String],
160+
bundleName: String
158161
): Unit = {
159-
160-
val credentials = sys.env("SONATYPE_USERNAME") + ":" + sys.env("SONATYPE_PASSWORD")
162+
val credentials = SonatypeCredentials(
163+
username = sys.env("SONATYPE_USERNAME"),
164+
password = sys.env("SONATYPE_PASSWORD")
165+
)
161166
val pgpPassword = sys.env("PGP_PASSWORD")
162167
val timeout = 10.minutes
163168

@@ -166,7 +171,7 @@ def publishSonatype(
166171
(s.map { case (p, f) => (p.path, f) }, a)
167172
}
168173

169-
val isRelease = {
174+
val isRelease: Boolean = {
170175
val versions = artifacts.map(_._2.version).toSet
171176
val set = versions.map(!_.endsWith("-SNAPSHOT"))
172177
assert(
@@ -175,11 +180,8 @@ def publishSonatype(
175180
)
176181
set.head
177182
}
178-
val publisher = new scalalib.publish.SonatypePublisher(
179-
uri = "https://oss.sonatype.org/service/local",
180-
snapshotUri = "https://oss.sonatype.org/content/repositories/snapshots",
183+
val publisher = new SonatypeCentralPublisher(
181184
credentials = credentials,
182-
signed = true,
183185
gpgArgs = Seq(
184186
"--detach-sign",
185187
"--batch=true",
@@ -195,12 +197,16 @@ def publishSonatype(
195197
connectTimeout = timeout.toMillis.toInt,
196198
log = log,
197199
workspace = workspace,
198-
env = sys.env,
199-
awaitTimeout = timeout.toMillis.toInt,
200-
stagingRelease = isRelease
200+
env = env,
201+
awaitTimeout = timeout.toMillis.toInt
202+
)
203+
val publishingType = if (isRelease) PublishingType.AUTOMATIC else PublishingType.USER_MANAGED
204+
val finalBundleName = if (bundleName.nonEmpty) Some(bundleName) else None
205+
publisher.publishAll(
206+
publishingType = publishingType,
207+
singleBundleName = finalBundleName,
208+
artifacts = artifacts: _*
201209
)
202-
203-
publisher.publishAll(isRelease, artifacts: _*)
204210
}
205211

206212
// from https://github.com/sbt/sbt-ci-release/blob/35b3d02cc6c247e1bb6c10dd992634aa8b3fe71f/plugin/src/main/scala/com/geirsson/CiReleasePlugin.scala#L33-L39

project/settings/package.mill.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ trait HasTests extends SbtModule {
545545
}
546546
}
547547

548-
trait PublishLocalNoFluff extends PublishModule {
548+
trait PublishLocalNoFluff extends SonatypeCentralPublishModule {
549549
def emptyZip: Target[PathRef] = Task {
550550
import java.io._
551551
import java.util.zip._

0 commit comments

Comments
 (0)