Skip to content

Commit 91b2ed2

Browse files
committed
Activate caching of tests in CI
1 parent 3f3a19a commit 91b2ed2

File tree

1 file changed

+34
-4
lines changed

1 file changed

+34
-4
lines changed

project/Build.scala

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import ScaladocGeneration._
66
import com.jsuereth.sbtpgp.PgpKeys
77
import sbt.Keys.*
88
import sbt.*
9+
import sbt.nio.FileStamper
10+
import sbt.nio.Keys.*
911
import complete.DefaultParsers._
1012
import pl.project13.scala.sbt.JmhPlugin
1113
import pl.project13.scala.sbt.JmhPlugin.JmhKeys.Jmh
@@ -279,6 +281,8 @@ object Build {
279281

280282
val fetchScalaJSSource = taskKey[File]("Fetch the sources of Scala.js")
281283

284+
val extraTestFiles = taskKey[Seq[Path]]("Extra files that affect test execution and caching")
285+
282286
lazy val SourceDeps = config("sourcedeps")
283287

284288
// Settings shared by the build (scoped in ThisBuild). Used in build.sbt
@@ -359,9 +363,14 @@ object Build {
359363
.withClassesFilter((className, _) => !noRetryTestClasses.contains(className))
360364
)
361365
},
362-
// Deactivate Develocity's test caching because it caches all tests or nothing.
363-
// Also at the moment, it does not take compilation files as inputs.
364-
Test / develocityBuildCacheClient := None,
366+
// Activate test caching on CI only
367+
Test / develocityBuildCacheClient := {
368+
if (insideCI.value) (Test / develocityBuildCacheClient).value else None
369+
},
370+
// base configuration of extraTestFiles to add as extra cache input
371+
// see https://docs.gradle.com/develocity/sbt-plugin/#declaring_inputs
372+
extraTestFiles / outputFileStamper := FileStamper.Hash,
373+
extraTestFiles := Seq.empty
365374
)
366375

367376
// Settings shared globally (scoped in Global). Used in build.sbt
@@ -442,7 +451,12 @@ object Build {
442451
Compile / packageBin / packageOptions +=
443452
Package.ManifestAttributes(
444453
"Automatic-Module-Name" -> s"${dottyOrganization.replaceAll("-",".")}.${moduleName.value.replaceAll("-",".")}"
445-
)
454+
),
455+
456+
// add stamps of extra test files in cache key
457+
Test / test / buildcache.develocityTaskCacheKeyComponents += (extraTestFiles / outputFileStamps).taskValue,
458+
Test / testOnly / buildcache.develocityInputTaskCacheKeyComponents += (extraTestFiles / outputFileStamps).taskValue,
459+
Test / testQuick / buildcache.develocityInputTaskCacheKeyComponents += (extraTestFiles / outputFileStamps).taskValue
446460
)
447461

448462
// Settings used for projects compiled only with Java
@@ -1023,6 +1037,12 @@ object Build {
10231037
sjsSources
10241038
} (Set(scalaJSIRSourcesJar)).toSeq
10251039
}.taskValue,
1040+
1041+
// declare extra test files to compute cache key
1042+
extraTestFiles ++= {
1043+
val directory = (ThisBuild / baseDirectory).value / "tests"
1044+
directory.allPaths.get.map(_.toPath)
1045+
}
10261046
)
10271047

10281048
def insertClasspathInArgs(args: List[String], cp: String): List[String] = {
@@ -1812,6 +1832,12 @@ object Build {
18121832
"-Ddotty.tests.classes.scalaJSLibrary=" + findArtifactPath(externalJSDeps, "scalajs-library_2.13"),
18131833
)
18141834
},
1835+
// declare extra test files to compute cache key
1836+
extraTestFiles ++= {
1837+
val testsDir = (ThisBuild / baseDirectory).value / "tests"
1838+
val directories = Seq(testsDir / "neg-scalajs", testsDir / "run")
1839+
directories.flatMap(_.allPaths.get).map(_.toPath)
1840+
}
18151841
)
18161842

18171843
lazy val `scala3-bench` = project.in(file("bench")).asDottyBench(NonBootstrapped)
@@ -2046,6 +2072,10 @@ object Build {
20462072
testDocumentationRoot := (baseDirectory.value / "test-documentations").getAbsolutePath,
20472073
Test / buildInfoPackage := "dotty.tools.scaladoc.test",
20482074
BuildInfoPlugin.buildInfoScopedSettings(Test),
2075+
extraTestFiles ++= {
2076+
val directory = (Test / Build.testcasesSourceRoot).value
2077+
file(directory).allPaths.get.map(_.toPath)
2078+
}
20492079
)
20502080

20512081
// various scripted sbt tests

0 commit comments

Comments
 (0)