Skip to content

Commit

Permalink
Ability to pass GPG arguments to publish
Browse files Browse the repository at this point in the history
  • Loading branch information
joan38 committed May 5, 2020
1 parent 306454d commit 5e6cc59
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 22 deletions.
21 changes: 8 additions & 13 deletions scalalib/src/PublishModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -115,22 +115,20 @@ trait PublishModule extends JavaModule { outer =>
}

def publish(sonatypeCreds: String,
gpgPassphrase: String = null,
gpgKeyName: String = null,
signed: Boolean = true,
gpgArgs: Seq[String] = Seq.empty,
release: Boolean,
readTimeout: Int = 60000,
connectTimeout: Int = 5000,
release: Boolean,
awaitTimeout: Int = 120 * 1000,
stagingRelease: Boolean = true): define.Command[Unit] = T.command {
val PublishModule.PublishData(artifactInfo, artifacts) = publishArtifacts()
new SonatypePublisher(
sonatypeUri,
sonatypeSnapshotUri,
sonatypeCreds,
Option(gpgPassphrase),
Option(gpgKeyName),
signed,
gpgArgs,
readTimeout,
connectTimeout,
T.log,
Expand Down Expand Up @@ -160,28 +158,25 @@ object PublishModule extends ExternalModule {


def publishAll(sonatypeCreds: String,
gpgPassphrase: String = null,
publishArtifacts: mill.main.Tasks[PublishModule.PublishData],
readTimeout: Int = 60000,
connectTimeout: Int = 5000,
signed: Boolean = true,
gpgArgs: Seq[String] = Seq.empty,
release: Boolean = false,
gpgKeyName: String = null,
sonatypeUri: String = "https://oss.sonatype.org/service/local",
sonatypeSnapshotUri: String = "https://oss.sonatype.org/content/repositories/snapshots",
signed: Boolean = true,
readTimeout: Int = 60000,
connectTimeout: Int = 5000,
awaitTimeout: Int = 120 * 1000,
stagingRelease: Boolean = true) = T.command {

val x: Seq[(Seq[(os.Path, String)], Artifact)] = T.sequence(publishArtifacts.value)().map{
case PublishModule.PublishData(a, s) => (s.map{case (p, f) => (p.path, f)}, a)
}
new SonatypePublisher(
sonatypeUri,
sonatypeSnapshotUri,
sonatypeCreds,
Option(gpgPassphrase),
Option(gpgKeyName),
signed,
gpgArgs,
readTimeout,
connectTimeout,
T.log,
Expand Down
13 changes: 4 additions & 9 deletions scalalib/src/publish/SonatypePublisher.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ import os.Shellable
class SonatypePublisher(uri: String,
snapshotUri: String,
credentials: String,
gpgPassphrase: Option[String],
gpgKeyName: Option[String],
signed: Boolean,
gpgArgs: Seq[String],
readTimeout: Int,
connectTimeout: Int,
log: Logger,
Expand All @@ -25,7 +24,6 @@ class SonatypePublisher(uri: String,
}

def publishAll(release: Boolean, artifacts: (Seq[(os.Path, String)], Artifact)*): Unit = {

val mappings = for ((fileMapping0, artifact) <- artifacts) yield {
val publishPath = Seq(
artifact.group.replace(".", "/"),
Expand All @@ -35,7 +33,7 @@ class SonatypePublisher(uri: String,
val fileMapping = fileMapping0.map { case (file, name) => (file, publishPath + "/" + name) }

val signedArtifacts = if (signed) fileMapping.map {
case (file, name) => poorMansSign(file, gpgPassphrase, gpgKeyName) -> s"$name.asc"
case (file, name) => gpgSigned(file, gpgArgs) -> s"$name.asc"
} else Seq()

artifact -> (fileMapping ++ signedArtifacts).flatMap {
Expand Down Expand Up @@ -154,12 +152,9 @@ class SonatypePublisher(uri: String,
}

// http://central.sonatype.org/pages/working-with-pgp-signatures.html#signing-a-file
private def poorMansSign(file: os.Path, maybePassphrase: Option[String], maybeKeyName: Option[String]): os.Path = {
private def gpgSigned(file: os.Path, args: Seq[String]): os.Path = {
val fileName = file.toString
val optionFlag = (flag: String, ov: Option[String]) => ov.map(flag :: _ :: Nil).getOrElse(Nil)
val command = "gpg" ::
optionFlag("--passphrase", maybePassphrase) ++ optionFlag("-u", maybeKeyName) ++
Seq("--batch", "--yes", "-a", "-b", fileName)
val command = Seq("gpg", "--batch", "--yes", "-a", "-b", fileName) ++ args

os.proc(command.map(v => v: Shellable))
.call(stdin = os.Inherit, stdout = os.Inherit, stderr = os.Inherit)
Expand Down

0 comments on commit 5e6cc59

Please sign in to comment.