Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SbtScriptedScalaTest #38

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions project/Repo.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@

import sbt._
import sbt.Keys.isSnapshot
import sbt.librarymanagement.URLRepository

import codeartifact.{CodeArtifact, CodeArtifactPlugin}
import codeartifact.CodeArtifactKeys.{codeArtifactResolvers, codeArtifactUrl}
import codeartifact.InternalCodeArtifactKeys.{codeArtifactRepo, codeArtifactToken}

object Repo {

object Jfrog {
private val domain = "tubins.jfrog.io"
private val jFrogRoot = s"https://$domain"
object Tubins {
private val pathPrefix = "tubins"

lazy val sbtDev: MavenRepository = "sbt-dev" at s"$jFrogRoot/$pathPrefix/sbt-dev"

lazy val sbtRelease: MavenRepository = "sbt-release" at s"$jFrogRoot/$pathPrefix/sbt-release"

lazy val jvmSnapshot: MavenRepository = "jvm-snapshot" at s"$jFrogRoot/$pathPrefix/jvm-snapshots"

lazy val jvm: MavenRepository = "jvm-release" at s"$jFrogRoot/$pathPrefix/jvm"
}

object Artifactory {
private val pathPrefix = "artifactory"

lazy val jvmSnapshots: MavenRepository = "tubi-jvm-snapshot" at s"$jFrogRoot/$pathPrefix/jvm-snapshots"

lazy val jvm: MavenRepository = "tubi-jvm-release" at s"$jFrogRoot/$pathPrefix/jvm"
}

object Credential {
lazy val fromEnv: Either[String, Credentials] = {
sys.env
.get("ARTIFACTORY_USERNAME")
.zip(sys.env.get("ARTIFACTORY_PASSWORD"))
.map {
case (username, password) =>
Credentials("Artifactory Realm", domain, username, password)
}
.headOption
.toRight("could not build artifactory credentials from the env")
}

lazy val fromFile: Either[String, Credentials] = {
Credentials.loadCredentials(Path.userHome / ".artifactory" / "credentials") match {
case Right(credentials: DirectCredentials) =>
Right(credentials)
case Left(err: String) =>
Left(s"Could not build artifactory credentials from home directory: $err")
}
}
}
}

object Lightbend {
lazy val mvn: MavenRepository =
"lightbend-commercial-mvn" at "https://repo.lightbend.com/pass/3hizCqO4VcTjyyqZzmprpQ1Te4CEAdD7S6GZguIH1MjEh07v/commercial-releases"

lazy val ivy: URLRepository = Resolver.url(
"lightbend-commercial-ivy",
url("https://repo.lightbend.com/pass/3hizCqO4VcTjyyqZzmprpQ1Te4CEAdD7S6GZguIH1MjEh07v/commercial-releases")
)(Resolver.ivyStylePatterns)
}

object CodeArtifact {
val urlBase = "https://tubi-141644937959.d.codeartifact.us-east-2.amazonaws.com/maven"
val releaseRepo: MavenRepository = "codeartifact-jvm" at s"$urlBase/maven-jvm"
val snapshotRepo: MavenRepository = "codeartifact-jvm-dev" at s"$urlBase/maven-jvm-dev"
}
}

object TubiRepoPlugin extends AutoPlugin {

override def requires = plugins.JvmPlugin && CodeArtifactPlugin
override def trigger = allRequirements

override def projectSettings: Seq[Def.Setting[_]] = Seq(
codeArtifactUrl := (if (isSnapshot.value) Repo.CodeArtifact.snapshotRepo.root
else Repo.CodeArtifact.releaseRepo.root),
codeArtifactResolvers := List(Repo.CodeArtifact.snapshotRepo.root, Repo.CodeArtifact.releaseRepo.root),
codeArtifactToken := sys.env
.get("CODEARTIFACT_AUTH_TOKEN")
.orElse(
Credentials.loadCredentials(Path.userHome / ".codeartifact" / "tubi" / "credentials").toOption.map(_.passwd)
)
.getOrElse(CodeArtifact.getAuthToken(codeArtifactRepo.value))
)
}
53 changes: 53 additions & 0 deletions project/TubiCodeArtifact.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import sbt._
import sbt.Keys._

import codeartifact.CodeArtifactKeys.{codeArtifactPublish, codeArtifactUrl}
import codeartifact.CodeArtifactPlugin
import codeartifact.InternalCodeArtifactKeys.{codeArtifactPackage, codeArtifactToken}

object TubiCodeArtifactPlugin extends AutoPlugin {
override def requires = plugins.JvmPlugin && CodeArtifactPlugin

override def trigger = allRequirements

override def projectSettings: Seq[Def.Setting[_]] = Seq(
// Override the `codeArtifactPublish` task to upload artifacts using cURL. The task defined in
// `CodeArtifactPlugin` uploads artifacts using the `com.lihaoyi:requests` library, in which
// there may be some hidden bug that fails the upload on github runner.
codeArtifactPublish := {
val log = streams.value.log
val token = codeArtifactToken.value
val url = codeArtifactUrl.value.stripSuffix("/")
val pkg = codeArtifactPackage.value
val basePublishPath = pkg.basePublishPath
val versionPublishPath = pkg.versionPublishPath

val files = packagedArtifacts.value.toList
// Drop Artifact.
.map { case (_, file) => file }
// Convert to os.Path.
.map(file => os.Path(file))
// Create CodeArtifact file name.
.map(file => s"$versionPublishPath/${file.last}" -> file)

val metadataFile = {
val td = os.temp.dir()
os.write(td / "maven-metadata.xml", codeArtifactPackage.value.mavenMetadata)
val file = td / "maven-metadata.xml"
s"$basePublishPath/${file.last}" -> file
}

(files :+ metadataFile).foreach {
case (fileName, file) =>
import scala.sys.process._
log.info(s"Uploading $fileName")
val cmd = s"curl -sSLD - -u 'aws:***' -H 'Content-Type:application/octet-stream' -T $file $url/$fileName"
log.info(cmd)
Process(cmd.replace("aws:***", s"aws:$token")).run(log).exitValue() match {
case 0 => log.info("Upload succeeded.")
case exitValue => scala.sys.error(s"Upload failed with exit value: $exitValue")
}
}
}
)
}
1 change: 0 additions & 1 deletion project/bintray.sbt

This file was deleted.

2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version = 1.2.6
sbt.version = 1.7.1
2 changes: 2 additions & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// common settings used by both this project and the builder project
addSbtPlugin("io.github.bbstilson" % "sbt-codeartifact" % "0.2.6")
14 changes: 0 additions & 14 deletions publish.sbt

This file was deleted.

1 change: 0 additions & 1 deletion release.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ releaseProcess := Seq[ReleaseStep](
// don't tag, leave it to git flow
// tagRelease,
releaseStepCommandAndRemaining("^ publish"),
releaseStepTask(bintrayRelease),
setNextVersion,
commitNextVersion,
pushChanges
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,36 +39,37 @@ object SbtScriptedScalaTest extends AutoPlugin {
}
import autoImport._

private[this] lazy val logger = Def.task[Logger] {
streams.value.log
}

override def projectSettings: Seq[Setting[_]] = Seq(
scriptedScalaTestDurations := true,
scriptedScalaTestStacks := NoStacks,
scriptedScalaTestStats := true,
scriptedScalaTestSpec := None,
scriptedScalaTest := {
val duration = scriptedScalaTestDurations.value
val stacks = scriptedScalaTestStacks.value
val stats = scriptedScalaTestStats.value
val log = streams.value.log
// do nothing if not configured
scriptedScalaTestSpec.value match {
case Some(suite) => executeScriptedTestsTask(suite)
case Some(suite) =>
executeScriptedTestsTask(suite, duration, stacks, stats)
case None =>
logger.value.warn(
s"${scriptedScalaTestSpec.key.label} not configured, no tests will be run..."
)
log.warn(s"${scriptedScalaTestSpec.key.label} not configured, no tests will be run...")
}
}
)

private[this] def executeScriptedTestsTask(
suite: ScriptedScalaTestSuite
): Unit = Def.task {
val stacks = scriptedScalaTestStacks.value
suite: ScriptedScalaTestSuite,
showDuration: Boolean,
stacks: ScriptedTestStacks,
stats: Boolean,
): Unit = {
val status = suite.executeScripted(
durations = scriptedScalaTestDurations.value,
durations = showDuration,
shortstacks = stacks.shortstacks,
fullstacks = stacks.fullstacks,
stats = scriptedScalaTestStats.value
stats = stats
)
status.waitUntilCompleted()
if (!status.succeeds()) {
Expand Down
5 changes: 5 additions & 0 deletions src/sbt-test/sbt-1.0/testFailure/build.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import scala.sys.process._

import com.github.daniel.shuy.sbt.scripted.scalatest.ScriptedScalaTestSuiteMixin
import org.scalatest.Assertions._
import org.scalatest.wordspec.AnyWordSpec
Expand All @@ -23,6 +25,9 @@ lazy val testFailure = project

"scripted" should {
"fail on ScalaTest failure" in {
val pidFile = new File("target/pid")
(s"echo ${ProcessHandle.current.pid}" #> pidFile).!!

assertThrows[sbt.Incomplete](
Project.extract(sbtState)
.runInputTask(scripted, "", sbtState))
Expand Down
2 changes: 2 additions & 0 deletions src/sbt-test/sbt-1.0/testFailure/test
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
$ delete target/pid
> scriptedScalatest
$ exists target/pid