summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLi Haoyi <haoyi.sg@gmail.com>2018-02-09 19:27:02 -0800
committerLi Haoyi <haoyi.sg@gmail.com>2018-02-09 19:27:02 -0800
commit3e6744393de81a9f0aded7412f92209831f0f9d0 (patch)
treee45734d619864ae45551a71790b2e86ff5bc9ce6
parente88838a99118d7c4ac489313129c7534610dfbe6 (diff)
downloadmill-3e6744393de81a9f0aded7412f92209831f0f9d0.tar.gz
mill-3e6744393de81a9f0aded7412f92209831f0f9d0.tar.bz2
mill-3e6744393de81a9f0aded7412f92209831f0f9d0.zip
Allow publishing to sonatype without immediate release
-rwxr-xr-xci/release.py27
-rw-r--r--scalalib/src/mill/scalalib/PublishModule.scala24
-rw-r--r--scalalib/src/mill/scalalib/publish/SonatypePublisher.scala35
3 files changed, 51 insertions, 35 deletions
diff --git a/ci/release.py b/ci/release.py
index c08a1b17..5777d183 100755
--- a/ci/release.py
+++ b/ci/release.py
@@ -3,23 +3,26 @@
from subprocess import check_call
import tempfile
import os, base64
-check_call(["sbt", "bin/test:assembly"])
+
is_master_commit = (
os.environ["TRAVIS_PULL_REQUEST"] == "false" and
(os.environ["TRAVIS_BRANCH"] == "master" or os.environ["TRAVIS_TAG"] != "")
)
-_, tmp = tempfile.mkstemp()
+if is_master_commit:
+ check_call(["sbt", "bin/test:assembly"])
+
+ _, tmp = tempfile.mkstemp()
-with open(tmp, "w") as f:
- f.write(base64.b64decode(os.environ["GPG_PRIVATE_KEY_B64"]))
+ with open(tmp, "w") as f:
+ f.write(base64.b64decode(os.environ["GPG_PRIVATE_KEY_B64"]))
-check_call(["gpg", "--import", tmp])
+ check_call(["gpg", "--import", tmp])
-check_call([
- "target/bin/mill",
- "mill.scalalib.PublishModule/publishAll",
- "lihaoyi:" + os.environ["SONATYPE_PASSWORD"],
- os.environ["GPG_PASSWORD"],
- "__.publishArtifacts"
-])
+ check_call([
+ "target/bin/mill",
+ "mill.scalalib.PublishModule/publishAll",
+ "lihaoyi:" + os.environ["SONATYPE_PASSWORD"],
+ os.environ["GPG_PASSWORD"],
+ "__.publishArtifacts"
+ ])
diff --git a/scalalib/src/mill/scalalib/PublishModule.scala b/scalalib/src/mill/scalalib/PublishModule.scala
index a6835dad..e6c88b01 100644
--- a/scalalib/src/mill/scalalib/PublishModule.scala
+++ b/scalalib/src/mill/scalalib/PublishModule.scala
@@ -63,7 +63,7 @@ trait PublishModule extends ScalaModule { outer =>
def publishArtifacts = T{
val baseName = s"${artifactId()}-${publishVersion()}"
- (
+ PublishModule.PublishData(
artifactMetadata(),
Seq(
jar() -> s"$baseName.jar",
@@ -74,26 +74,35 @@ trait PublishModule extends ScalaModule { outer =>
)
}
- def publish(sonatypeCreds: String, gpgPassphrase: String): define.Command[Unit] = T.command {
- val (artifactInfo, artifacts) = publishArtifacts()
+ def publish(sonatypeCreds: String,
+ gpgPassphrase: String,
+ release: Boolean): define.Command[Unit] = T.command {
+ val PublishModule.PublishData(artifactInfo, artifacts) = publishArtifacts()
new SonatypePublisher(
sonatypeUri,
sonatypeSnapshotUri,
sonatypeCreds,
gpgPassphrase,
T.ctx().log
- ).publish(artifacts.map{case (a, b) => (a.path, b)}, artifactInfo)
+ ).publish(artifacts.map{case (a, b) => (a.path, b)}, artifactInfo, release)
}
}
object PublishModule extends ExternalModule{
+ case class PublishData(meta: Artifact, payload: Seq[(PathRef, String)])
+
+ object PublishData{
+ implicit def jsonify: upickle.default.ReadWriter[PublishData] = upickle.default.macroRW
+ }
+
def publishAll(sonatypeCreds: String,
gpgPassphrase: String,
- publishArtifacts: mill.main.MagicScopt.Tasks[(mill.scalalib.publish.Artifact, Seq[(PathRef, String)])],
+ publishArtifacts: mill.main.MagicScopt.Tasks[PublishModule.PublishData],
sonatypeUri: String = "https://oss.sonatype.org/service/local",
- sonatypeSnapshotUri: String = "https://oss.sonatype.org/content/repositories/snapshots") = T.command{
+ sonatypeSnapshotUri: String = "https://oss.sonatype.org/content/repositories/snapshots",
+ release: Boolean = false) = T.command{
val x: Seq[(Seq[(Path, String)], Artifact)] = Task.sequence(publishArtifacts.value)().map{
- case (a, s) => (s.map{case (p, f) => (p.path, f)}, a)
+ case PublishModule.PublishData(a, s) => (s.map{case (p, f) => (p.path, f)}, a)
}
new SonatypePublisher(
sonatypeUri,
@@ -102,6 +111,7 @@ object PublishModule extends ExternalModule{
gpgPassphrase,
T.ctx().log
).publishAll(
+ release,
x:_*
)
}
diff --git a/scalalib/src/mill/scalalib/publish/SonatypePublisher.scala b/scalalib/src/mill/scalalib/publish/SonatypePublisher.scala
index 1977d8aa..4d03e182 100644
--- a/scalalib/src/mill/scalalib/publish/SonatypePublisher.scala
+++ b/scalalib/src/mill/scalalib/publish/SonatypePublisher.scala
@@ -16,10 +16,10 @@ class SonatypePublisher(uri: String,
private val api = new SonatypeHttpApi(uri, credentials)
- def publish(fileMapping: Seq[(Path, String)], artifact: Artifact): Unit = {
- publishAll(fileMapping -> artifact)
+ def publish(fileMapping: Seq[(Path, String)], artifact: Artifact, release: Boolean): Unit = {
+ publishAll(release, fileMapping -> artifact)
}
- def publishAll(artifacts: (Seq[(Path, String)], Artifact)*): Unit = {
+ def publishAll(release: Boolean, artifacts: (Seq[(Path, String)], Artifact)*): Unit = {
val mappings = for ((fileMapping0, artifact) <- artifacts) yield {
val publishPath = Seq(
@@ -51,7 +51,7 @@ class SonatypePublisher(uri: String,
}
val releaseGroups = releases.groupBy(_._1.group)
for((group, groupReleases) <- releaseGroups){
- publishRelease(groupReleases.flatMap(_._2), group, releases.map(_._1))
+ publishRelease(release, groupReleases.flatMap(_._2), group, releases.map(_._1))
}
}
@@ -67,7 +67,8 @@ class SonatypePublisher(uri: String,
reportPublishResults(publishResults, artifacts)
}
- private def publishRelease(payloads: Seq[(String, Array[Byte])],
+ private def publishRelease(release: Boolean,
+ payloads: Seq[(String, Array[Byte])],
stagingProfile: String,
artifacts: Seq[Artifact]): Unit = {
val profileUri = api.getStagingProfileUri(stagingProfile)
@@ -82,22 +83,24 @@ class SonatypePublisher(uri: String,
}
reportPublishResults(publishResults, artifacts)
- log.info("Closing staging repository")
- api.closeStagingRepo(profileUri, stagingRepoId)
+ if (release) {
+ log.info("Closing staging repository")
+ api.closeStagingRepo(profileUri, stagingRepoId)
- log.info("Waiting for staging repository to close")
- awaitRepoStatus("closed", stagingRepoId)
+ log.info("Waiting for staging repository to close")
+ awaitRepoStatus("closed", stagingRepoId)
- log.info("Promoting staging repository")
- api.promoteStagingRepo(profileUri, stagingRepoId)
+ log.info("Promoting staging repository")
+ api.promoteStagingRepo(profileUri, stagingRepoId)
- log.info("Waiting for staging repository to release")
- awaitRepoStatus("released", stagingRepoId)
+ log.info("Waiting for staging repository to release")
+ awaitRepoStatus("released", stagingRepoId)
- log.info("Dropping staging repository")
- api.dropStagingRepo(profileUri, stagingRepoId)
+ log.info("Dropping staging repository")
+ api.dropStagingRepo(profileUri, stagingRepoId)
- log.info(s"Published ${artifacts.map(_.id).mkString(", ")} successfully")
+ log.info(s"Published ${artifacts.map(_.id).mkString(", ")} successfully")
+ }
}
private def reportPublishResults(publishResults: Seq[HttpResponse[String]],