Skip to content

Commit 7a77cea

Browse files
Avoid publishing the same project twice
1 parent bc3b813 commit 7a77cea

File tree

1 file changed

+63
-46
lines changed

1 file changed

+63
-46
lines changed

community-build/test/scala/dotty/communitybuild/CommunityBuildTest.scala

Lines changed: 63 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,30 @@ import org.junit.{Ignore, Test}
77
import org.junit.Assert.{assertEquals, fail}
88
import org.junit.experimental.categories.Category
99

10-
@Category(Array(classOf[TestCategory]))
11-
class CommunityBuildTest { suite =>
10+
case class MillCommunityProject(project: String, testCommand: String,
11+
publishCommand: String = "", extraArgs: List[String] = Nil,
12+
dependencies: List[MillCommunityProject] = Nil)
13+
import communityBuildCommons.{ log, exec, communitybuildDir }
14+
15+
private var published = false
16+
17+
final def test()(given suite: CommunityBuildTest) =
18+
dependencies.foreach(_.publish())
19+
suite.test(project, "./mill", extraArgs :+ testCommand)
20+
21+
final def publish() =
22+
if !published
23+
log(s"Publishing $project")
24+
val projectDir = communitybuildDir.resolve("community-projects").resolve(project)
25+
if publishCommand.isEmpty
26+
throw RuntimeException(s"Missing publish command for $project, project details:\n$this")
27+
val exitCode = exec(projectDir, "./mill", (extraArgs :+ publishCommand): _*)
28+
if exitCode != 0
29+
throw RuntimeException(s"Publish command exited with code $exitCode for project $project. Project details:\n$this")
30+
published = true
31+
end MillCommunityProject
32+
33+
object communityBuildCommons
1234
lazy val communitybuildDir: Path = Paths.get(sys.props("user.dir"))
1335

1436
lazy val compilerVersion: String = {
@@ -27,6 +49,45 @@ class CommunityBuildTest { suite =>
2749
val exitCode = process.waitFor()
2850
exitCode
2951
}
52+
end communityBuildCommons
53+
54+
object projects
55+
import communityBuildCommons._
56+
57+
val utest = MillCommunityProject(
58+
project = "utest",
59+
testCommand = s"utest.jvm[$compilerVersion].test",
60+
publishCommand = s"utest.jvm[$compilerVersion].publishLocal",
61+
extraArgs = List("-i", "-D", s"dottyVersion=$compilerVersion")
62+
)
63+
64+
val sourcecode = MillCommunityProject(
65+
project = "sourcecode",
66+
testCommand = s"sourcecode.jvm[$compilerVersion].test",
67+
publishCommand = s"sourcecode.jvm[$compilerVersion].publishLocal",
68+
extraArgs = List("-i", "-D", s"dottyVersion=$compilerVersion"),
69+
)
70+
71+
val oslib = MillCommunityProject(
72+
project = "os-lib",
73+
testCommand = s"os[$compilerVersion].test",
74+
extraArgs = List("-i", "-D", s"dottyVersion=$compilerVersion"),
75+
dependencies = List(utest, sourcecode)
76+
)
77+
78+
val oslibWatch = MillCommunityProject(
79+
project = "os-lib",
80+
testCommand = s"os.watch[$compilerVersion].test",
81+
extraArgs = List("-i", "-D", s"dottyVersion=$compilerVersion"),
82+
dependencies = List(utest, sourcecode)
83+
)
84+
end projects
85+
86+
@Category(Array(classOf[TestCategory]))
87+
class CommunityBuildTest {
88+
import communityBuildCommons._
89+
90+
given CommunityBuildTest = this
3091

3192
def testSbt(project: String, testCommand: String, updateCommand: String, extraSbtArgs: Seq[String] = Nil) = {
3293
// Workaround for https://github.com/sbt/sbt/issues/4395
@@ -95,50 +156,6 @@ class CommunityBuildTest { suite =>
95156
}
96157
}
97158

98-
case class MillCommunityProject(project: String, testCommand: String,
99-
publishCommand: String = "", extraArgs: List[String] = Nil,
100-
dependencies: List[MillCommunityProject] = Nil)
101-
final def test() =
102-
dependencies.foreach(_.publish())
103-
suite.test(project, "./mill", extraArgs :+ testCommand)
104-
105-
final def publish() =
106-
log(s"Publishing $project")
107-
val projectDir = communitybuildDir.resolve("community-projects").resolve(project)
108-
if publishCommand.isEmpty
109-
throw RuntimeException(s"Missing publish command for project $this")
110-
exec(projectDir, "./mill", (extraArgs :+ publishCommand): _*)
111-
112-
object projects {
113-
val utest = MillCommunityProject(
114-
project = "utest",
115-
testCommand = s"utest.jvm[$compilerVersion].test",
116-
publishCommand = s"utest.jvm[$compilerVersion].publishLocal",
117-
extraArgs = List("-i", "-D", s"dottyVersion=$compilerVersion")
118-
)
119-
120-
val sourcecode = MillCommunityProject(
121-
project = "sourcecode",
122-
testCommand = s"sourcecode.jvm[$compilerVersion].test",
123-
publishCommand = s"sourcecode.jvm[$compilerVersion].publishLocal",
124-
extraArgs = List("-i", "-D", s"dottyVersion=$compilerVersion"),
125-
)
126-
127-
val oslib = MillCommunityProject(
128-
project = "os-lib",
129-
testCommand = s"os[$compilerVersion].test",
130-
extraArgs = List("-i", "-D", s"dottyVersion=$compilerVersion"),
131-
dependencies = List(utest, sourcecode)
132-
)
133-
134-
val oslibWatch = MillCommunityProject(
135-
project = "os-lib",
136-
testCommand = s"os.watch[$compilerVersion].test",
137-
extraArgs = List("-i", "-D", s"dottyVersion=$compilerVersion"),
138-
dependencies = List(utest, sourcecode)
139-
)
140-
}
141-
142159
@Test def intent = testSbt(
143160
project = "intent",
144161
testCommand = "test",

0 commit comments

Comments
 (0)