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

Enable caching of tests on CI #22763

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
39 changes: 35 additions & 4 deletions project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import ScaladocGeneration._
import com.jsuereth.sbtpgp.PgpKeys
import sbt.Keys.*
import sbt.*
import sbt.nio.FileStamper
import sbt.nio.Keys.*
import complete.DefaultParsers._
import pl.project13.scala.sbt.JmhPlugin
import pl.project13.scala.sbt.JmhPlugin.JmhKeys.Jmh
Expand Down Expand Up @@ -279,6 +281,8 @@ object Build {

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

val extraTestFiles = taskKey[Seq[Path]]("Extra files that affect test execution and caching")

lazy val SourceDeps = config("sourcedeps")

// Settings shared by the build (scoped in ThisBuild). Used in build.sbt
Expand Down Expand Up @@ -349,6 +353,7 @@ object Build {
buildCache
.withLocal(buildCache.local.withEnabled(true).withStoreEnabled(true))
.withRemote(buildCache.remote.withEnabled(true).withStoreEnabled(isInsideCI))
.withRequireClean(!isInsideCI)
)
.withTestRetry(
config.testRetry
Expand All @@ -358,9 +363,14 @@ object Build {
.withClassesFilter((className, _) => !noRetryTestClasses.contains(className))
)
},
// Deactivate Develocity's test caching because it caches all tests or nothing.
// Also at the moment, it does not take compilation files as inputs.
Test / develocityBuildCacheClient := None,
// Activate test caching on CI only
Test / develocityBuildCacheClient := {
if (insideCI.value) (Test / develocityBuildCacheClient).value else None
},
// base configuration of extraTestFiles to add as extra cache input
// see https://docs.gradle.com/develocity/sbt-plugin/#declaring_inputs
extraTestFiles / outputFileStamper := FileStamper.Hash,
extraTestFiles := Seq.empty
)

// Settings shared globally (scoped in Global). Used in build.sbt
Expand Down Expand Up @@ -441,7 +451,12 @@ object Build {
Compile / packageBin / packageOptions +=
Package.ManifestAttributes(
"Automatic-Module-Name" -> s"${dottyOrganization.replaceAll("-",".")}.${moduleName.value.replaceAll("-",".")}"
)
),

// add stamps of extra test files in cache key
Test / test / buildcache.develocityTaskCacheKeyComponents += (extraTestFiles / outputFileStamps).taskValue,
Test / testOnly / buildcache.develocityInputTaskCacheKeyComponents += (extraTestFiles / outputFileStamps).taskValue,
Test / testQuick / buildcache.develocityInputTaskCacheKeyComponents += (extraTestFiles / outputFileStamps).taskValue
)

// Settings used for projects compiled only with Java
Expand Down Expand Up @@ -1022,6 +1037,12 @@ object Build {
sjsSources
} (Set(scalaJSIRSourcesJar)).toSeq
}.taskValue,

// declare extra test files to compute cache key
extraTestFiles ++= {
val directory = (ThisBuild / baseDirectory).value / "tests"
directory.allPaths.get.map(_.toPath)
}
)

def insertClasspathInArgs(args: List[String], cp: String): List[String] = {
Expand Down Expand Up @@ -1811,6 +1832,12 @@ object Build {
"-Ddotty.tests.classes.scalaJSLibrary=" + findArtifactPath(externalJSDeps, "scalajs-library_2.13"),
)
},
// declare extra test files to compute cache key
extraTestFiles ++= {
val testsDir = (ThisBuild / baseDirectory).value / "tests"
val directories = Seq(testsDir / "neg-scalajs", testsDir / "run")
directories.flatMap(_.allPaths.get).map(_.toPath)
}
)

lazy val `scala3-bench` = project.in(file("bench")).asDottyBench(NonBootstrapped)
Expand Down Expand Up @@ -2045,6 +2072,10 @@ object Build {
testDocumentationRoot := (baseDirectory.value / "test-documentations").getAbsolutePath,
Test / buildInfoPackage := "dotty.tools.scaladoc.test",
BuildInfoPlugin.buildInfoScopedSettings(Test),
extraTestFiles ++= {
val directory = (Test / Build.testcasesSourceRoot).value
file(directory).allPaths.get.map(_.toPath)
}
)

// various scripted sbt tests
Expand Down
Loading