Skip to content

Commit

Permalink
Merge pull request #163 from eed3si9n/wip/gpg2
Browse files Browse the repository at this point in the history
Add gpg 2 support
  • Loading branch information
olafurpg authored Dec 4, 2020
2 parents 766a162 + 8922517 commit 509f540
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 509f540

Please sign in to comment.