diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9d4f92b..987a4f6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,4 +13,4 @@ jobs: java-version: 8 cache: sbt - uses: sbt/setup-sbt@v1 - - run: sbt compile + - run: sbt +compile diff --git a/build.sbt b/build.sbt index b0db712..f3745f3 100644 --- a/build.sbt +++ b/build.sbt @@ -16,25 +16,31 @@ inThisBuild( url("https://geirsson.com") ) ), - crossScalaVersions := Seq(scala212) ) ) onLoadMessage := s"Welcome to sbt-ci-release ${version.value}" - +crossScalaVersions := Nil publish / skip := true // don't publish the root project lazy val plugin = project .enablePlugins(SbtPlugin) .settings( moduleName := "sbt-ci-release", + crossScalaVersions := Seq(scala212, scala3), + scalacOptions ++= { + scalaBinaryVersion.value match { + case "2.12" => "-Xsource:3" :: Nil + case _ => Nil + } + }, (pluginCrossBuild / sbtVersion) := { scalaBinaryVersion.value match { case "2.12" => "1.5.8" case _ => "2.0.0-M2" } }, - addSbtPlugin("com.github.sbt" % "sbt-dynver" % "5.0.1"), + addSbtPlugin("com.github.sbt" % "sbt-dynver" % "5.1.0"), addSbtPlugin("com.github.sbt" % "sbt-git" % "2.1.0"), addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.3.0"), addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.12.2") diff --git a/plugin/src/main/scala/com/geirsson/PipeFail.scala b/plugin/src/main/scala-2.12/com/geirsson/PipeFail.scala similarity index 87% rename from plugin/src/main/scala/com/geirsson/PipeFail.scala rename to plugin/src/main/scala-2.12/com/geirsson/PipeFail.scala index 1e46f8b..a4d793f 100644 --- a/plugin/src/main/scala/com/geirsson/PipeFail.scala +++ b/plugin/src/main/scala-2.12/com/geirsson/PipeFail.scala @@ -19,14 +19,15 @@ object PipeFail { override def buffer[T](f: => T): T = f } - Try(p1.!!(logger)).map(result => + + Try(p1.!!(logger)).map((result) => (p2 #< new ByteArrayInputStream(result.getBytes)) ) match { - case Failure(exception) => + case Failure(ex) => error match { case Some(errorMessageFromPipe) => - throw new RuntimeException(errorMessageFromPipe, exception) - case None => throw exception + throw new RuntimeException(errorMessageFromPipe, ex) + case None => throw ex } case Success(value) => value } diff --git a/plugin/src/main/scala-3/com/geirsson/PipeFail.scala b/plugin/src/main/scala-3/com/geirsson/PipeFail.scala new file mode 100644 index 0000000..09b305a --- /dev/null +++ b/plugin/src/main/scala-3/com/geirsson/PipeFail.scala @@ -0,0 +1,27 @@ +package com.geirsson + +import java.io.ByteArrayInputStream +import scala.sys.process.{ProcessBuilder, ProcessLogger} +import scala.util.{Failure, Success, Try} + +object PipeFail: + implicit class PipeFailOps(p1: ProcessBuilder): + @volatile + private var error: Option[String] = None + def #|!(p2: ProcessBuilder): ProcessBuilder = + val logger = new ProcessLogger: + override def out(s: => String): Unit = () + override def err(s: => String): Unit = + error = Some(s) + override def buffer[T](f: => T): T = f + Try(p1.!!(logger)).map((result) => + (p2 #< new ByteArrayInputStream(result.getBytes)) + ) match + case Failure(ex) => + error match { + case Some(errorMessageFromPipe) => + throw new RuntimeException(errorMessageFromPipe, ex) + case None => throw ex + } + case Success(value) => value +end PipeFail diff --git a/plugin/src/main/scala/com/geirsson/CiReleasePlugin.scala b/plugin/src/main/scala/com/geirsson/CiReleasePlugin.scala index e9386fb..ad99c50 100644 --- a/plugin/src/main/scala/com/geirsson/CiReleasePlugin.scala +++ b/plugin/src/main/scala/com/geirsson/CiReleasePlugin.scala @@ -4,24 +4,24 @@ import com.geirsson.PipeFail.PipeFailOps import com.github.sbt.git.GitPlugin import com.github.sbt.git.SbtGit.GitKeys import com.jsuereth.sbtpgp.SbtPgp -import com.jsuereth.sbtpgp.SbtPgp.autoImport._ +import com.jsuereth.sbtpgp.SbtPgp.autoImport.* import java.nio.file.Files import java.nio.file.Paths import java.nio.charset.StandardCharsets import java.util.Base64 import sbt.Def -import sbt.Keys._ -import sbt._ +import sbt.Keys.* +import sbt.{ given, * } import sbt.plugins.JvmPlugin import sbtdynver.DynVerPlugin -import sbtdynver.DynVerPlugin.autoImport._ +import sbtdynver.DynVerPlugin.autoImport.* import scala.deprecated -import scala.sys.process._ +import scala.sys.process.{ given, * } import scala.util.control.NonFatal import xerial.sbt.Sonatype -import xerial.sbt.Sonatype.autoImport._ +import xerial.sbt.Sonatype.autoImport.* object CiReleasePlugin extends AutoPlugin { @@ -93,7 +93,9 @@ object CiReleasePlugin extends AutoPlugin { s"unzip gpg.zip".! s"gpg $importCommand gpg.key".! } else { - (s"echo $secret" #|! "base64 --decode" #|! s"gpg $importCommand").! + (Process(s"echo $secret") #|! + Process("base64 --decode") #|! + Process(s"gpg $importCommand")).! } } diff --git a/project/plugins.sbt b/project/plugins.sbt index 48fe06d..b8ae257 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,6 +1,9 @@ Compile / unmanagedSourceDirectories += (ThisBuild / baseDirectory).value.getParentFile / "plugin" / "src" / "main" / "scala" +Compile / unmanagedSourceDirectories += + (ThisBuild / baseDirectory).value.getParentFile / + "plugin" / "src" / "main" / "scala-2.12" addSbtPlugin("com.github.sbt" % "sbt-dynver" % "5.0.1") addSbtPlugin("com.github.sbt" % "sbt-git" % "2.1.0") addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.3.0")