Skip to content

Commit

Permalink
Fix testing scb-cli
Browse files Browse the repository at this point in the history
  • Loading branch information
WojciechMazur committed Apr 7, 2023
1 parent 2edc101 commit 6226916
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
23 changes: 10 additions & 13 deletions cli/scb-cli.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
//> using scala "3.2"
//> using lib "org.json4s::json4s-native:4.0.6"
//> using lib "com.lihaoyi::requests:0.8.0"
//> using lib "com.lihaoyi::os-lib:0.9.0"
//> using lib "com.lihaoyi::os-lib:0.9.1"
//> using lib "io.get-coursier:coursier_2.13:2.0.16"
//> using lib "com.goyeau::kubernetes-client:0.8.1"
//> using lib "org.slf4j:slf4j-simple:2.0.6"
//> using lib "org.slf4j:slf4j-simple:2.0.7"
//> using lib "com.github.scopt::scopt:4.1.0"

import org.json4s.*
Expand Down Expand Up @@ -140,7 +140,7 @@ object Config:
}

case class ProjectBuildPlan(
name: String,
project: String,
dependencies: Array[String],
repoUrl: String,
revision: Option[String],
Expand Down Expand Up @@ -236,17 +236,13 @@ object BuildInfo:
val scalaVersion = config.customRun.scalaVersion
given StringManifest: Manifest[String] =
scala.reflect.ManifestFactory.classType(classOf[String])

def prepareBuildPlan(): JValue =
val configsDir = communityBuildDir / "env" / "prod" / "config"
val args = Seq[os.Shellable](
/* scalaBinaryVersion = */ 3,
/* minStartsCount = */ 0,
/* maxProjectsCount = */ 0,
/* requiredProjects = */ config.customRun.projectName,
/* replacedProjectsPath = */ "",
/* projectsConfigPath = */ configsDir / "projects-config.conf",
/* projectsFiterPath = */ ""
/* configsPath = */ communityBuildDir / "coordinator" / "configs",
)
val javaProps =
Seq("--java-prop", "opencb.coordinator.reproducer-mode=true")
Expand All @@ -256,11 +252,12 @@ object BuildInfo:
val buildPlanJson = os.read(coordinatorDir / "data" / "buildPlan.json")
parse(buildPlanJson)

val JArray(buildPlan) = prepareBuildPlan(): @unchecked
val buildPlan = prepareBuildPlan() match
case JArray(plan) => plan.filter(_ != JArray(Nil))
case t => sys.error("Unexpected build plan input: " + t)
val projects = for
case JArray(buildStage) <- buildPlan.take(
1
) // There should be only 1 stage
case JArray(buildStage) <- buildPlan.take(1)
// There should be only 1 stage
project <- buildStage.take(1) // There should be only 1 project
// Config is an object, though be default would be decoded to None when we expect Option[String]
// We don't care about its content so we treat it as opaque string value
Expand All @@ -279,7 +276,7 @@ object BuildInfo:
yield ProjectInfo(
id = jobId,
params = BuildParameters(
name = plan.name,
name = plan.project,
config = plan.config.filter(_.nonEmpty),
repositoryUrl = plan.repoUrl,
repositoryRevision = config.customRun.revisionOverride
Expand Down
2 changes: 1 addition & 1 deletion coordinator/src/main/scala/buildPlan.scala
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ def createGithubActionJob(
| repository-url: $${{ inputs.repository-url }}
| repository-branch: $${{ inputs.repository-branch }}
|""".stripMargin)
plan.zipWithIndex.foreach { case (projects, idx) if projects.nonEmpty =>
plan.filter(_.nonEmpty).zipWithIndex.foreach { case (projects, idx) =>
// stage 0 reserved for long running jobs, no other step depends on it
def hasExtendentBuildTime = idx == 0
val prevStageId = Option.when(idx > 1) { stageId(idx - 1) }
Expand Down
15 changes: 13 additions & 2 deletions coordinator/src/main/scala/encoding.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,23 @@ import java.time.OffsetDateTime
given Formats =
Serialization.formats(NoTypeHints) +
TestingModeEnumSerializer() + ProjectBuildDefSerializer +
UTCOffsetDateTimeSerializer()
UTCOffsetDateTimeSerializer() + ProjectSerializer()

object ProjectBuildDefSerializer
extends FieldSerializer[ProjectBuildDef]({
import FieldSerializer.ignore
ignore("project") orElse ignore("dependencies")
ignore("dependencies")
})

class ProjectSerializer
extends CustomSerializer[Project](format => {
def deserialize: PartialFunction[JValue, Project] = { case JString(stringValue) =>
Project.load(stringValue)
}
def serialize: PartialFunction[Any, JValue] = { case p: Project =>
JString(p.coordinates)
}
(deserialize, serialize)
})

class TestingModeEnumSerializer
Expand Down

0 comments on commit 6226916

Please sign in to comment.