-
-
Notifications
You must be signed in to change notification settings - Fork 59
/
build.mill
200 lines (173 loc) · 6.33 KB
/
build.mill
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
package build
import mill._, scalalib._, scalajslib._, publish._
import mill.scalalib.api.ZincWorkerUtil
import $packages._
import $file.ci.upload
import $ivy.`de.tototec::de.tobiasroeser.mill.vcs.version::0.4.0`
import $ivy.`com.github.lolgab::mill-mima::0.0.23`
import de.tobiasroeser.mill.vcs.version.VcsVersion
val scala213 = "2.13.15"
val scala212 = "2.12.20"
val scala3 = "3.3.4"
val scalaJS = "1.17.0"
val communityBuildDottyVersion = sys.props.get("dottyVersion").toList
val scalaVersions = List(scala212, scala213, scala3) ++ communityBuildDottyVersion
trait CaskModule extends CrossScalaModule with PublishModule{
def isScala3 = ZincWorkerUtil.isScala3(crossScalaVersion)
def publishVersion = VcsVersion.vcsState().format()
def pomSettings = PomSettings(
description = artifactName(),
organization = "com.lihaoyi",
url = "https://github.com/com-lihaoyi/cask",
licenses = Seq(License.MIT),
versionControl = VersionControl.github("com-lihaoyi", "cask"),
developers = Seq(
Developer("lihaoyi", "Li Haoyi","https://github.com/lihaoyi")
)
)
}
trait CaskMainModule extends CaskModule {
def ivyDeps = T{
Agg(
ivy"io.undertow:undertow-core:2.3.18.Final",
ivy"com.lihaoyi::upickle:4.0.2"
) ++
Agg.when(!isScala3)(ivy"org.scala-lang:scala-reflect:$crossScalaVersion")
}
def compileIvyDeps = Agg.when(!isScala3)(ivy"com.lihaoyi:::acyclic:0.3.15")
def scalacOptions = Agg.when(!isScala3)("-P:acyclic:force").toSeq
def scalacPluginIvyDeps = Agg.when(!isScala3)(ivy"com.lihaoyi:::acyclic:0.3.15")
object test extends ScalaTests with TestModule.Utest{
def ivyDeps = Agg(
ivy"com.lihaoyi::utest::0.8.4",
ivy"com.lihaoyi::requests::0.9.0"
)
}
def moduleDeps = Seq(cask.util.jvm(crossScalaVersion))
}
object cask extends Cross[CaskMainModule](scalaVersions) {
object util extends Module {
trait UtilModule extends CaskModule with PlatformScalaModule{
def ivyDeps = Agg(
ivy"com.lihaoyi::sourcecode:0.4.2",
ivy"com.lihaoyi::pprint:0.9.0",
ivy"com.lihaoyi::geny:1.1.1"
)
}
object jvm extends Cross[UtilJvmModule](scalaVersions)
trait UtilJvmModule extends UtilModule {
def ivyDeps = super.ivyDeps() ++ Agg(
ivy"com.lihaoyi::castor::0.3.0",
ivy"org.java-websocket:Java-WebSocket:1.5.3"
)
}
object js extends Cross[UtilJsModule](scala213)
trait UtilJsModule extends UtilModule with ScalaJSModule {
def scalaJSVersion = scalaJS
def ivyDeps = super.ivyDeps() ++ Agg(
ivy"com.lihaoyi::castor::0.3.0",
ivy"org.scala-js::scalajs-dom::2.4.0"
)
}
}
}
trait LocalModule extends CrossScalaModule{
override def millSourcePath = super.millSourcePath / "app"
def moduleDeps = Seq(cask(crossScalaVersion))
}
def zippedExamples = T {
val vcsState = VcsVersion.vcsState()
val releaseTag = vcsState.lastTag.getOrElse("")
val label = vcsState.format()
val examples = Seq(
build.example.compress.millSourcePath,
build.example.compress2.millSourcePath,
build.example.compress3.millSourcePath,
build.example.cookies.millSourcePath,
build.example.decorated.millSourcePath,
build.example.decorated2.millSourcePath,
build.example.decoratedContext.millSourcePath,
build.example.endpoints.millSourcePath,
build.example.formJsonPost.millSourcePath,
build.example.httpMethods.millSourcePath,
build.example.minimalApplication.millSourcePath,
build.example.minimalApplication2.millSourcePath,
build.example.redirectAbort.millSourcePath,
build.example.scalatags.millSourcePath,
build.example.staticFiles.millSourcePath,
build.example.staticFiles2.millSourcePath,
build.example.todo.millSourcePath,
build.example.todoApi.millSourcePath,
build.example.todoDb.millSourcePath,
build.example.twirl.millSourcePath,
build.example.variableRoutes.millSourcePath,
build.example.queryParams.millSourcePath,
build.example.websockets.millSourcePath,
build.example.websockets2.millSourcePath,
build.example.websockets3.millSourcePath,
build.example.websockets4.millSourcePath,
)
for (example <- examples) yield {
val f = T.ctx().dest
val last = example.last + "-" + label
os.copy(example, f / last)
os.copy(T.workspace / ".mill-version", f / last / ".mill-version")
os.write.over(f / last / "mill", os.read(T.workspace / "mill"))
os.proc("chmod", "+x", f / last / "mill").call(f / last)
os.move(f / last / "package.mill", f / last / "build.mill")
os.write.over(
f / last / "build.mill",
os.read(f / last / "build.mill")
.replaceAll("package build.*", "package build")
.replaceAll("def moduleDeps =.*", "")
.replaceAll("app =>", "")
.replaceFirst(
"object app extends.*\ntrait AppModule extends CrossScalaModule(.*)\\{",
s"object app extends ScalaModule $$1\\{\n def scalaVersion = \"${scala213}\"")
.replaceAll("build.scala3", s"\"${scala3}\"")
.replaceFirst(
"def ivyDeps = Agg\\[Dep\\]\\(",
"def ivyDeps = Agg(\n ivy\"com.lihaoyi::cask:" + releaseTag + "\","
)
)
os.zip(f / s"$last.zip", Seq(f / last))
PathRef(f / s"$last.zip")
}
}
def testExamples() = T.command{
for(example <- zippedExamples()){
println("Testing " + example.path.last)
val base = T.dest / example.path.baseName
os.unzip(example.path, base)
os.perms.set(base / "mill", "rwxrwxrwx")
os.write.over(
base / "build.mill",
os.read(base / "build.mill").replaceAll(
"ivy\"com.lihaoyi::cask:.*\"",
s"""ivy"com.lihaoyi::cask:${VcsVersion.vcsState().format()}""""
)
)
os.proc("./mill", "app.test").call(cwd = base, stdout = os.Inherit)
}
}
def uploadToGithub() = T.command{
val vcsState = VcsVersion.vcsState()
val authKey = T.env.apply("AMMONITE_BOT_AUTH_TOKEN")
val releaseTag = vcsState.lastTag.getOrElse("")
val label = vcsState.format()
if (releaseTag == label) {
requests.post(
"https://api.github.com/repos/com-lihaoyi/cask/releases",
data = ujson.write(
ujson.Obj(
"tag_name" -> releaseTag,
"name" -> releaseTag
)
),
headers = Seq("Authorization" -> s"token $authKey")
)
}
for(example <- zippedExamples()){
upload.apply(example.path, releaseTag, example.path.last, authKey)
}
}