From ba0f3efa9dc1b6ca42b3699d46fdeeed5df6a00f Mon Sep 17 00:00:00 2001 From: Andrapyre <42009361+Andrapyre@users.noreply.github.com> Date: Mon, 16 Sep 2024 18:50:37 +0200 Subject: [PATCH 1/2] adding support for sonatype central --- .../scala/com/geirsson/CiReleasePlugin.scala | 63 ++++++++++++++----- 1 file changed, 46 insertions(+), 17 deletions(-) diff --git a/plugin/src/main/scala/com/geirsson/CiReleasePlugin.scala b/plugin/src/main/scala/com/geirsson/CiReleasePlugin.scala index 5837796..cc0db7b 100644 --- a/plugin/src/main/scala/com/geirsson/CiReleasePlugin.scala +++ b/plugin/src/main/scala/com/geirsson/CiReleasePlugin.scala @@ -133,6 +133,8 @@ object CiReleasePlugin extends AutoPlugin { publishArtifact.in(Test) := false, publishMavenStyle := true, commands += Command.command("ci-release") { currentState => + val shouldDeployToSonatypeCentral = isDeploySetToSonatypeCentral(currentState) + val isSnapshot = isSnapshotVersion(currentState) if (!isSecure) { println("No access to secret variables, doing nothing") currentState @@ -145,27 +147,45 @@ object CiReleasePlugin extends AutoPlugin { // https://github.com/olafurpg/sbt-ci-release/issues/64 val reloadKeyFiles = "; set pgpSecretRing := pgpSecretRing.value; set pgpPublicRing := pgpPublicRing.value" - if (!isTag) { - if (isSnapshotVersion(currentState)) { - println(s"No tag push, publishing SNAPSHOT") + + if (shouldDeployToSonatypeCentral) { + if (isSnapshot) { + println(s"Sonatype Central does not accept snapshots, only official releases. Aborting release.") + currentState + } else if (!isTag) { + println(s"No tag published. Cannot publish an official release without a tag and Sonatype Central does not accept snapshot releases. Aborting release.") + currentState + } else { + println("Tag push detected, publishing a stable release") reloadKeyFiles :: - sys.env.getOrElse("CI_SNAPSHOT_RELEASE", "+publish") :: + sys.env.getOrElse("CI_CLEAN", "; clean ; sonatypeBundleClean") :: + sys.env.getOrElse("CI_RELEASE", "+publishSigned") :: + sys.env.getOrElse("CI_SONATYPE_RELEASE", "sonatypeCentralRelease") :: currentState - } else { - // Happens when a tag is pushed right after merge causing the master branch - // job to pick up a non-SNAPSHOT version even if TRAVIS_TAG=false. - println( - "Snapshot releases must have -SNAPSHOT version number, doing nothing" - ) - currentState } } else { - println("Tag push detected, publishing a stable release") - reloadKeyFiles :: - sys.env.getOrElse("CI_CLEAN", "; clean ; sonatypeBundleClean") :: - sys.env.getOrElse("CI_RELEASE", "+publishSigned") :: - sys.env.getOrElse("CI_SONATYPE_RELEASE", "sonatypeBundleRelease") :: - currentState + if (!isTag) { + if (isSnapshot) { + println(s"No tag push, publishing SNAPSHOT") + reloadKeyFiles :: + sys.env.getOrElse("CI_SNAPSHOT_RELEASE", "+publish") :: + currentState + } else { + // Happens when a tag is pushed right after merge causing the master branch + // job to pick up a non-SNAPSHOT version even if TRAVIS_TAG=false. + println( + "Snapshot releases must have -SNAPSHOT version number, doing nothing" + ) + currentState + } + } else { + println("Tag push detected, publishing a stable release") + reloadKeyFiles :: + sys.env.getOrElse("CI_CLEAN", "; clean ; sonatypeBundleClean") :: + sys.env.getOrElse("CI_RELEASE", "+publishSigned") :: + sys.env.getOrElse("CI_SONATYPE_RELEASE", "sonatypeBundleRelease") :: + currentState + } } } } @@ -179,6 +199,15 @@ object CiReleasePlugin extends AutoPlugin { publishTo := sonatypePublishToBundle.value ) + def isDeploySetToSonatypeCentral(state: State): Boolean = { + sonatypeCredentialHost.in(ThisBuild).get(Project.extract(state).structure.data) match { + case Some(value) if value == Sonatype.sonatypeCentralHost => { + true + } + case _ => false + } + } + def isSnapshotVersion(state: State): Boolean = { version.in(ThisBuild).get(Project.extract(state).structure.data) match { case Some(v) => v.endsWith("-SNAPSHOT") From a4b4e59ad5a1516b868e41ae5c5ee8fda241f074 Mon Sep 17 00:00:00 2001 From: Andrapyre <42009361+Andrapyre@users.noreply.github.com> Date: Mon, 16 Sep 2024 21:11:17 +0200 Subject: [PATCH 2/2] adding documentation --- readme.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/readme.md b/readme.md index c793a60..c22af14 100644 --- a/readme.md +++ b/readme.md @@ -361,6 +361,20 @@ Enjoy 👌 ## FAQ +### How do I publish to Sonatype Central? + +As of February 2024, Sonatype has released a new portal, called Sonatype Central. Users can configure their libraries to be published via this portal by adding the following to `build.sbt`: + +```sbt +import xerial.sbt.Sonatype.sonatypeCentralHost + +ThisBuild / sonatypeCredentialHost := sonatypeCentralHost +``` + +Users can generate a two-part token, containing username and password values, in their [account](https://central.sonatype.com/account) and then set these to the _SONATYPE_USERNAME_ and _SONATYPE_PASSWORD_ environment variables. All other steps should then work as documented. + + + ### How do I disable publishing in certain projects? Add the following to the project settings (works only in sbt 1)