Skip to content

Commit

Permalink
Enable sbt 2.x cross building (#321)
Browse files Browse the repository at this point in the history
  • Loading branch information
eed3si9n authored Oct 13, 2024
1 parent 8bfaa39 commit b1fc142
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ jobs:
java-version: 8
cache: sbt
- uses: sbt/setup-sbt@v1
- run: sbt compile
- run: sbt +compile
12 changes: 9 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
27 changes: 27 additions & 0 deletions plugin/src/main/scala-3/com/geirsson/PipeFail.scala
Original file line number Diff line number Diff line change
@@ -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
16 changes: 9 additions & 7 deletions plugin/src/main/scala/com/geirsson/CiReleasePlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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")).!
}
}

Expand Down
3 changes: 3 additions & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -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")
Expand Down

0 comments on commit b1fc142

Please sign in to comment.