Skip to content

Commit

Permalink
Fix failing tests in CI
Browse files Browse the repository at this point in the history
- incorrect resource paths
- cleaner build matrix
- support multiple steps in the same job
  • Loading branch information
Olafur Pall Geirsson committed Sep 24, 2019
1 parent b4c90f2 commit 12cf576
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 81 deletions.
112 changes: 60 additions & 52 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,51 +6,6 @@
"pull_request"
],
"jobs": {
"Scalafmt": {
"runs-on": "ubuntu-latest",
"steps": [
{
"uses": "actions/checkout@v1"
},
{
"uses": "olafurpg/setup-scala@v2"
},
{
"name": "Formatting",
"run": "./bin/scalafmt --test"
}
]
},
"Scalafix": {
"runs-on": "ubuntu-latest",
"steps": [
{
"uses": "actions/checkout@v1"
},
{
"uses": "olafurpg/setup-scala@v2"
},
{
"name": "Linting",
"run": "csbt scalafixCheck githubActionsCheck"
}
]
},
"Docusaurus": {
"runs-on": "ubuntu-latest",
"steps": [
{
"uses": "actions/checkout@v1"
},
{
"uses": "olafurpg/setup-scala@v2"
},
{
"name": "Website",
"run": "csbt docs/docusaurusCreateSite"
}
]
},
"Metals": {
"runs-on": "ubuntu-latest",
"steps": [
Expand All @@ -69,9 +24,9 @@
"fail-fast": false,
"matrix": {
"test": [
"{foldingrange,filewatch,hover,metals,references,statusbar,completions}",
"{ansi,workspacesymbol,bsp,builds,applyedit,compile,definition}",
"{http,formatting,documentsymbol,documenthighlight,codelens,tvp,mtags}"
"{ansi,applyedit,bsp,builds,codelens,compile,completions}",
"{definition,documenthighlight,documentsymbol,filewatch,foldingrange,formatting,hover}",
"{http,metals,mtags,references,statusbar,tvp,workspacesymbol}"
]
}
}
Expand Down Expand Up @@ -123,14 +78,67 @@
"fail-fast": false,
"matrix": {
"test": [
"mill",
"maven",
"feature",
"gradle",
"sbt",
"feature"
"maven",
"mill",
"sbt"
]
}
}
},
"Scalafmt": {
"runs-on": "ubuntu-latest",
"steps": [
{
"uses": "actions/checkout@v1"
},
{
"uses": "olafurpg/setup-scala@v2"
},
{
"name": "Run Scalafmt",
"run": "./bin/scalafmt --test"
}
]
},
"Scalafix": {
"runs-on": "ubuntu-latest",
"steps": [
{
"uses": "actions/checkout@v1"
},
{
"uses": "olafurpg/setup-scala@v2"
},
{
"name": "Run Scalafix",
"run": "csbt scalafixCheck"
}
]
},
"Miscellaneous": {
"runs-on": "ubuntu-latest",
"steps": [
{
"uses": "actions/checkout@v1"
},
{
"uses": "olafurpg/setup-scala@v2"
},
{
"name": "Run Scalafix",
"run": "csbt scalafixCheck"
},
{
"name": "Generate Website",
"run": "csbt docs/docusaurusCreateSite"
},
{
"name": "Check Build Matrix",
"run": "csbt githubActions"
}
]
}
}
}
35 changes: 19 additions & 16 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -109,19 +109,7 @@ inThisBuild(
"name" -> Str("CI"),
"on" -> Arr(Str("push"), Str("pull_request")),
"jobs" -> Obj(
"Scalafmt" -> githubActionsJob(
"Formatting",
"./bin/scalafmt --test"
),
"Scalafix" -> githubActionsJob(
"Linting",
"csbt scalafixCheck githubActionsCheck"
),
"Docusaurus" -> githubActionsJob(
"Website",
"csbt docs/docusaurusCreateSite"
),
"Metals" -> githubActionsJob(
"Metals" -> githubActionsStep(
"Run tests",
"csbt 'unit/testOnly -- tests.${{ matrix.test }}'",
githubActionsMatrix(
Expand All @@ -133,12 +121,12 @@ inThisBuild(
)
)
),
"Mtags" -> githubActionsJob(
"Mtags" -> githubActionsStep(
"Run tests",
"csbt ++${{ matrix.scala }} cross/test",
githubActionsMatrix("scala", V.supportedScalaVersions)
),
"Build" -> githubActionsJob(
"Build" -> githubActionsStep(
"Run tests",
"csbt 'slow/testOnly -- tests.${{ matrix.test }}'",
githubActionsMatrix(
Expand All @@ -148,6 +136,21 @@ inThisBuild(
"tests" / "slow" / "src" / "test" / "scala" / "tests"
)
)
),
"Scalafmt" -> githubActionsStep(
"Run Scalafmt",
"./bin/scalafmt --test"
),
"Scalafix" -> githubActionsStep(
"Run Scalafix",
"csbt scalafixCheck"
),
"Miscellaneous" -> githubActionsSteps(
List(
"Run Scalafix" -> "csbt scalafixCheck",
"Generate Website" -> "csbt docs/docusaurusCreateSite",
"Check Build Matrix" -> "csbt githubActions"
)
)
)
)
Expand Down Expand Up @@ -364,7 +367,7 @@ lazy val `sbt-metals` = project
),
buildInfoResourceValue := {
val paths = V.supportedScalaVersions.mkString(java.io.File.pathSeparator)
s"""|scalametaVersion=V.scalameta
s"""|scalametaVersion=${V.scalameta}
|supportedScalaVersions=${paths}
|""".stripMargin
}
Expand Down
2 changes: 1 addition & 1 deletion project/BuildInfoResourcePlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ object BuildInfoResourcePlugin extends AutoPlugin {
buildInfoResourceFilename := thisProject.value.id + "-buildinfo.json",
resourceGenerators.in(Compile) += Def.taskDyn[Seq[File]] {
cache.synchronized {
val key = thisProject.value.id
val key = thisProject.value.id + scalaVersion.value
cache.get(key) match {
case Some(value) if value.isFile => Def.task(List(value))
case _ => generateResource(key)
Expand Down
33 changes: 22 additions & 11 deletions project/GitHubActionsPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,27 @@ object GitHubActionsPlugin extends AutoPlugin {
lazy val githubActionsWorkflow = settingKey[ujson.Obj](
"Settings to describe the CI build matrix."
)
def githubActionsJob(
def githubActionsStep(
name: String,
run: String,
matrix: Obj = Obj()
): Obj = {
githubActionsSteps(List(name -> run), matrix)
}
def githubActionsSteps(
namedSteps: List[(String, String)],
matrix: Obj = Obj()
): Obj = {
val steps =
Obj("uses" -> Str("actions/checkout@v1")) +:
Obj("uses" -> Str("olafurpg/setup-scala@v2")) +:
namedSteps.map {
case (name, run) =>
Obj("name" -> Str(name), "run" -> Str(run))
}
val result = Obj(
"runs-on" -> "ubuntu-latest",
"steps" -> Arr(
Obj("uses" -> Str("actions/checkout@v1")),
Obj("uses" -> Str("olafurpg/setup-scala@v2")),
Obj("name" -> Str(name), "run" -> Str(run))
)
"steps" -> Arr(steps.value)
)
result.value ++= matrix.value
result
Expand All @@ -55,6 +64,7 @@ object GitHubActionsPlugin extends AutoPlugin {
.listFiles(dir)
.filter(_.isDirectory)
.map(_.toPath.getFileName.toString)
.sorted
val count = partitionCount.getOrElse(names.length)
require(names.nonEmpty, "no tests to partition!")
val groupSizes = math.ceil(names.length.toDouble / count).toInt
Expand All @@ -69,11 +79,12 @@ object GitHubActionsPlugin extends AutoPlugin {
githubActionsCheck := {
githubActionsGenerate.value
val exit = List("git", "diff", "--exit-code", ".github/workflows").!
require(
exit == 0,
"build is not in sync with the CI matrix. " +
"Run 'sbt githubActionsGenerate' to fix this problem."
)
if (exit != 0) {
throw new RuntimeException(
"build is not in sync with the CI matrix. " +
"Run 'sbt githubActionsGenerate' to fix this problem."
) with sbt.internal.util.FeedbackProvidedException
}
},
githubActionsGenerate := {
val workflow = githubActionsWorkflow.in(ThisBuild).value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import java.{util => ju}
object BuildInfo {
lazy val props: ju.Properties = {
val p = new ju.Properties()
val path = "metals-input.properties"
val path = "sbt-metals-buildinfo.json"
val in = this.getClass.getClassLoader.getResourceAsStream(path)
assert(in != null, s"no such resource: $path")
try p.load(in)
Expand Down

0 comments on commit 12cf576

Please sign in to comment.