-
Notifications
You must be signed in to change notification settings - Fork 59
/
run
executable file
·119 lines (102 loc) · 4.18 KB
/
run
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/usr/local/bin/env -S scala-cli shebang -v -v -v
// TODO the `-v -v -v` above is to help troubleshoot the issues
// we've been having with the script intermittently failing to launch
// on Jenkins
// Usage:
// * ./run
// * ./run specs2 scalatest munit
// This script is suitable for local use.
// It is also invoked by Jenkins (from scripts/jobs/integrate/community-build).
// An older run script is in the Git history under the name `run.sh`.
// I didn't port every feature of that script to this version.
// We can add things back later as needed, I figure.
//> using scala 3.6.2-RC1
//> using option -source:future
//> using dep com.lihaoyi::os-lib:0.11.2
println(s"""JAVA_HOME=${sys.env("JAVA_HOME")}""")
print("which java: ")
os.proc("which", "java").call(stdout = os.Inherit)
os.proc("java", "-version").call(stdout = os.Inherit)
println()
val dbuildVersion = "0.9.20"
val dbuildScript = os.pwd / s"dbuild-$dbuildVersion" / "bin" / "dbuild"
println(s"dbuild version: $dbuildVersion")
def readNightly(): String =
val prop = new java.util.Properties
prop.load(os.read.inputStream(os.pwd / "nightly.properties"))
Option(prop.getProperty("nightly")).get
val scalaVersion = sys.env.get("version").getOrElse(readNightly())
println(s"Scala version: $scalaVersion")
println()
def removeProjectBuilds(): Unit =
println("removing temporary files...")
println()
os.remove.all(os.pwd / s"target-$dbuildVersion" / "project-builds")
// redundant to delete both at start and end, but just in case this was
// left lying around, let's free up the space (and inodes) now
removeProjectBuilds()
// Download and extract dbuild if we haven't already got it
if !os.isDir(os.pwd / s"dbuild-$dbuildVersion") then
val url = s"https://github.com/lightbend-labs/dbuild/releases/download/v$dbuildVersion/dbuild-$dbuildVersion.tgz"
os.proc("curl", "-L", "-O", url).call(stdout = os.Inherit)
os.proc("tar", "xfz", s"dbuild-$dbuildVersion.tgz").call(stdout = os.Inherit)
os.remove(os.pwd / s"dbuild-$dbuildVersion.tgz")
// use -n by default since running locally you don't want notifications sent,
// and on our Jenkins setup it doesn't actually work (for now anyway)
val dbuildArgs = Seq("-n", "community.conf")
// sigh, Ubuntu has `nodejs` but MacOS has `node`
def onPath(cmd: String): Boolean =
os.proc("sh", "-c", s"hash $cmd")
.call(stderr = os.Pipe, check = false)
.exitCode == 0
val node =
if onPath("nodejs")
then "nodejs"
else "node"
// work around https://github.com/lightbend-labs/dbuild/issues/241
os.write.over(dbuildScript,
os.read(dbuildScript).replaceFirst(
"(?m)^java .$", // (?m) enables multiline mode
"java -Xss16M \\\\"))
// we're ready to run dbuild
val command = Seq(
dbuildScript.toString,
"-n", "./community.conf",
args.mkString(","))
println(command.mkString(" "))
println()
val dbuildOut = s"dbuild-$dbuildVersion/dbuild.out"
val moreEnv =
if sys.env.get("jvmVersion").map(_.toInt).exists(_ < 17)
then Map()
else Map("SECURITY_MANAGER" -> "-Djava.security.manager=allow")
val dbuild =
os.proc(command).spawn(
stdout = os.Pipe,
mergeErrIntoOut = true,
env = moreEnv ++ Map(
"version" -> scalaVersion,
"NODE" -> node),
)
// we use `tee` so we can see the output live as well as redirecting it to a
// file for later reference. unfortunately the live output is buffered so we
// don't see it a line at a time, but in bursts. presumably that's fixable;
// the old shell script that this Scala script replaced didn't have this problem
val tee = os.proc("tee", dbuildOut).call(stdin = dbuild.stdout, stdout = os.Inherit)
dbuild.join()
// helpfully repeat the build's UUID at the end of the log
// [info] uuid = 03c94c9f9b185c7bbdb4b66be9ecf99b3cd8d73e
val idOption =
os.read.lines(os.pwd / os.SubPath(dbuildOut))
.collectFirst:
case s"[info] uuid = $id" => id
for id <- idOption do
println(s"The repeatable UUID of this build was: $id")
println()
// free up space (and inodes) on Jenkins
removeProjectBuilds()
// report summary information (line counts, green project counts, ...?)
val reporter = os.proc("./report", dbuildOut).call(check = false)
os.write.over(os.pwd / "report.html", reporter.out.text())
println(reporter.out.text())
sys.exit(reporter.exitCode)