Skip to content

Commit

Permalink
Add gpg 2 support
Browse files Browse the repository at this point in the history
Fixes #95
Ref sbt/sbt-pgp#184
Ref https://dev.gnupg.org/T2313

This parses the gpg version number and uses `--batch --import` to
import the secret key.

This should fix the mysterious error message we see on GitHub Actions:
error sending to agent: Inappropriate ioctl for device
  • Loading branch information
eed3si9n committed Dec 3, 2020
1 parent 766a162 commit 8922517
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ onLoadMessage := s"Welcome to sbt-ci-release ${version.value}"
skip in publish := true // don't publish the root project

lazy val plugin = project
.enablePlugins(SbtPlugin)
.settings(
moduleName := "sbt-ci-release",
sbtPlugin := true,
sbtVersion in pluginCrossBuild := "1.0.4",
addSbtPlugin("com.dwijnand" % "sbt-dynver" % "4.1.1"),
addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "1.0.0"),
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.9.5"),
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "2.0.1")
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "2.1.1")
)
16 changes: 13 additions & 3 deletions plugin/src/main/scala/com/geirsson/CiReleasePlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,26 @@ object CiReleasePlugin extends AutoPlugin {
System.getenv("GITLAB_CI") == "true"

def setupGpg(): Unit = {
List("gpg", "--version").!
val versionLine = List("gpg", "--version").!!.linesIterator.toList.head
println(versionLine)
val TaggedVersion = """(\d{1,14})([\.\d{1,14}]*)((?:-\w+)*)""".r
val gpgVersion: Long = versionLine.split(" ").last match {
case TaggedVersion(m, _, _) => m.toLong
case _ => 0L
}
// https://dev.gnupg.org/T2313
val importCommand =
if (gpgVersion < 2L) "--import"
else "--batch --import"
val secret = sys.env("PGP_SECRET")
if (isAzure) {
// base64 encoded gpg secrets are too large for Azure variables but
// they fit within the 4k limit when compressed.
Files.write(Paths.get("gpg.zip"), Base64.getDecoder.decode(secret))
s"unzip gpg.zip".!
s"gpg --import gpg.key".!
s"gpg $importCommand gpg.key".!
} else {
(s"echo $secret" #| "base64 --decode" #| "gpg --import").!
(s"echo $secret" #| "base64 --decode" #| s"gpg $importCommand").!
}
}

Expand Down

0 comments on commit 8922517

Please sign in to comment.