Permalink
Browse files

Automatically initialize git submodule

  • Loading branch information...
alexarchambault committed Oct 5, 2018
1 parent 32bdf18 commit 58dde021fbe75bcac4f30eaafdd82c30f0d6558c
Showing with 32 additions and 0 deletions.
  1. +1 −0 build.sbt
  2. +31 −0 project/Settings.scala
View
@@ -106,6 +106,7 @@ lazy val tests = project
shared,
dontPublish,
plotlyPrefix,
fetchTestData,
libraryDependencies ++= Seq(
Deps.scalaTest % "test",
Deps.rhino % "test"
View
@@ -118,4 +118,35 @@ object Settings {
testFrameworks += new TestFramework("utest.runner.Framework")
)
val gitLock = new Object
def runCommand(cmd: Seq[String], dir: File): Unit = {
val b = new ProcessBuilder(cmd: _*)
b.directory(dir)
b.inheritIO()
val p = b.start()
val retCode = p.waitFor()
if (retCode != 0)
sys.error(s"Command ${cmd.mkString(" ")} failed (return code $retCode)")
}
lazy val fetchTestData = {
unmanagedResources.in(Test) ++= {
val log = streams.value.log
val baseDir = baseDirectory.in(LocalRootProject).value
val testsPostsDir = baseDir / "plotly-documentation" / "_posts"
if (!testsPostsDir.exists())
gitLock.synchronized {
if (!testsPostsDir.exists()) {
val cmd = Seq("git", "submodule", "update", "--init", "--recursive", "--", "plotly-documentation")
log.info("Fetching submodule plotly-documentation (this may take some time)")
runCommand(cmd, baseDir)
log.info("Successfully fetched submodule plotly-documentation")
}
}
Nil
}
}
}

0 comments on commit 58dde02

Please sign in to comment.