Skip to content

Commit d568513

Browse files
authored
Merge pull request #148 from Gedochao/maintenance/publishing
Migrate publishing to Sonatype Maven Central
2 parents e9abd8f + cdb5522 commit d568513

File tree

1 file changed

+33
-16
lines changed

1 file changed

+33
-16
lines changed

build.mill.scala

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import scala.annotation.unused
1717
import scala.concurrent.duration._
1818
import scala.util.Properties.isWin
1919
import com.goyeau.mill.scalafix.ScalafixModule
20+
import com.lumidion.sonatype.central.client.core.{PublishingType, SonatypeCredentials}
2021

2122
object Versions {
2223
def scala213 = "2.13.16"
@@ -229,13 +230,14 @@ object tests extends ScalaJsCliModule {
229230
}
230231
}
231232

232-
def ghOrg = "virtuslab"
233-
def ghName = "scala-js-cli"
234-
trait ScalaJsCliPublishModule extends PublishModule {
233+
def ghOrg = "virtuslab"
234+
def ghName = "scala-js-cli"
235+
def publishOrg = "org.virtuslab.scala-cli"
236+
trait ScalaJsCliPublishModule extends SonatypeCentralPublishModule {
235237
import mill.scalalib.publish._
236238
def pomSettings: Target[PomSettings] = PomSettings(
237239
description = artifactName(),
238-
organization = "org.virtuslab.scala-cli",
240+
organization = publishOrg,
239241
url = s"https://github.com/$ghOrg/$ghName",
240242
licenses = Seq(License.`BSD-3-Clause`),
241243
versionControl = VersionControl.github(ghOrg, ghName),
@@ -313,18 +315,30 @@ object ci extends Module {
313315
@unused
314316
def publishSonatype(tasks: mill.main.Tasks[PublishModule.PublishData]): Command[Unit] =
315317
Task.Command {
318+
val publishVersion = finalPublishVersion
319+
System.err.println(s"Publish version: $publishVersion")
320+
val bundleName = s"$publishOrg-$ghName-$publishVersion"
321+
System.err.println(s"Publishing bundle: $bundleName")
316322
publishSonatype0(
317323
data = define.Target.sequence(tasks.value)(),
318-
log = Task.ctx().log
324+
log = Task.ctx().log,
325+
workspace = Task.workspace,
326+
env = Task.env,
327+
bundleName = bundleName
319328
)
320329
}
321330

322331
private def publishSonatype0(
323332
data: Seq[PublishModule.PublishData],
324-
log: mill.api.Logger
333+
log: mill.api.Logger,
334+
workspace: os.Path,
335+
env: Map[String, String],
336+
bundleName: String
325337
): Unit = {
326-
327-
val credentials = sys.env("SONATYPE_USERNAME") + ":" + sys.env("SONATYPE_PASSWORD")
338+
val credentials = SonatypeCredentials(
339+
username = sys.env("SONATYPE_USERNAME"),
340+
password = sys.env("SONATYPE_PASSWORD")
341+
)
328342
val pgpPassword = sys.env("PGP_PASSPHRASE")
329343
val timeout = 10.minutes
330344

@@ -341,11 +355,8 @@ object ci extends Module {
341355
)
342356
set.head
343357
}
344-
val publisher = new scalalib.publish.SonatypePublisher(
345-
uri = "https://oss.sonatype.org/service/local",
346-
snapshotUri = "https://oss.sonatype.org/content/repositories/snapshots",
358+
val publisher = new SonatypeCentralPublisher(
347359
credentials = credentials,
348-
signed = true,
349360
gpgArgs = Seq(
350361
"--detach-sign",
351362
"--batch=true",
@@ -360,11 +371,17 @@ object ci extends Module {
360371
readTimeout = timeout.toMillis.toInt,
361372
connectTimeout = timeout.toMillis.toInt,
362373
log = log,
363-
awaitTimeout = timeout.toMillis.toInt,
364-
stagingRelease = isRelease
374+
workspace = workspace,
375+
env = env,
376+
awaitTimeout = timeout.toMillis.toInt
377+
)
378+
val publishingType = if (isRelease) PublishingType.AUTOMATIC else PublishingType.USER_MANAGED
379+
val finalBundleName = if (bundleName.nonEmpty) Some(bundleName) else None
380+
publisher.publishAll(
381+
publishingType = publishingType,
382+
singleBundleName = finalBundleName,
383+
artifacts = artifacts: _*
365384
)
366-
367-
publisher.publishAll(isRelease, artifacts: _*)
368385
}
369386
@unused
370387
def upload(directory: String = "artifacts/"): Command[Unit] = Task.Command {

0 commit comments

Comments
 (0)