Skip to content

Commit 58dde02

Browse files
Automatically initialize git submodule
1 parent 32bdf18 commit 58dde02

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

build.sbt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ lazy val tests = project
106106
shared,
107107
dontPublish,
108108
plotlyPrefix,
109+
fetchTestData,
109110
libraryDependencies ++= Seq(
110111
Deps.scalaTest % "test",
111112
Deps.rhino % "test"

project/Settings.scala

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,35 @@ object Settings {
118118
testFrameworks += new TestFramework("utest.runner.Framework")
119119
)
120120

121+
val gitLock = new Object
122+
123+
def runCommand(cmd: Seq[String], dir: File): Unit = {
124+
val b = new ProcessBuilder(cmd: _*)
125+
b.directory(dir)
126+
b.inheritIO()
127+
val p = b.start()
128+
val retCode = p.waitFor()
129+
if (retCode != 0)
130+
sys.error(s"Command ${cmd.mkString(" ")} failed (return code $retCode)")
131+
}
132+
133+
134+
lazy val fetchTestData = {
135+
unmanagedResources.in(Test) ++= {
136+
val log = streams.value.log
137+
val baseDir = baseDirectory.in(LocalRootProject).value
138+
val testsPostsDir = baseDir / "plotly-documentation" / "_posts"
139+
if (!testsPostsDir.exists())
140+
gitLock.synchronized {
141+
if (!testsPostsDir.exists()) {
142+
val cmd = Seq("git", "submodule", "update", "--init", "--recursive", "--", "plotly-documentation")
143+
log.info("Fetching submodule plotly-documentation (this may take some time)")
144+
runCommand(cmd, baseDir)
145+
log.info("Successfully fetched submodule plotly-documentation")
146+
}
147+
}
148+
Nil
149+
}
150+
}
151+
121152
}

0 commit comments

Comments
 (0)