-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathbuild.sc
367 lines (314 loc) · 10.8 KB
/
build.sc
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
import $file.project.deps, deps.{Deps, Versions}
import $ivy.`com.github.lolgab::mill-mima::0.1.0`
import $ivy.`de.tototec::de.tobiasroeser.mill.vcs.version::0.4.0`
import com.github.lolgab.mill.mima.Mima
import de.tobiasroeser.mill.vcs.version.VcsVersion
import mill._
import mill.scalalib._
import java.util.Arrays
import scala.concurrent.duration.DurationInt
// Tell mill modules are under modules/
implicit def millModuleBasePath: define.BasePath =
define.BasePath(super.millModuleBasePath.value / "modules")
trait AmmSparkPublishModule extends PublishModule {
import mill.scalalib.publish._
def publishVersion = T {
val v = VcsVersion.vcsState().format()
val dirtyIdx = v.indexOf("-DIRTY")
def endsWithCommitHash =
v.length > 6 && v.substring(v.length - 6).forall(c => c.isDigit || (c >= 'a' && c <= 'f'))
if (dirtyIdx >= 0) v.take(dirtyIdx) + "-SNAPSHOT"
else if (endsWithCommitHash) v + "-SNAPSHOT"
else v
}
def pomSettings = PomSettings(
description = artifactName(),
organization = "sh.almond",
url = "https://github.com/alexarchambault/ammonite-spark.git",
licenses = Seq(License.MIT),
versionControl = VersionControl.github("alexarchambault", "ammonite-spark"),
developers = Seq(
Developer("alexarchambault", "Alex Archambault", "https://github.com/alexarchambault")
)
)
}
trait AmmSparkMima extends Mima {
// same as https://github.com/lolgab/mill-mima/blob/de28f3e9fbe92867f98e35f8dfd3c3a777cc033d/mill-mima/src/com/github/lolgab/mill/mima/Mima.scala#L29-L44
// except we're ok if mimaPreviousVersions is empty
def mimaPreviousArtifacts = T {
val versions = mimaPreviousVersions().distinct
mill.api.Result.Success(
Agg.from(
versions.map(version =>
ivy"${pomSettings().organization}:${artifactId()}:$version"
)
)
)
}
}
trait WithPropertyFile extends JavaModule {
def versionInProperties: T[String]
def propertyFilePath: os.SubPath
def propResourcesDir = T.persistent {
import sys.process._
val dir = T.dest / "property-resources"
val ver = versionInProperties()
val f = dir / propertyFilePath
val contentStr =
s"""commit-hash=${Seq("git", "rev-parse", "HEAD").!!.trim}
|version=$ver
|""".stripMargin
val content = contentStr.getBytes("UTF-8")
if (!os.exists(f) || !Arrays.equals(content, os.read.bytes(f))) {
os.write.over(f, content, createFolders = true)
System.err.println(s"Wrote $f")
}
PathRef(dir)
}
def resources = T.sources {
super.resources() ++ Seq(propResourcesDir())
}
}
trait WithDependencyResourceFile extends JavaModule {
def dependencyResourcePath: os.SubPath
def dependencyFileResources = T.persistent {
val dir = T.dest / "dep-file"
val dest = dir / dependencyResourcePath
val deps0 = T.task(compileIvyDeps() ++ transitiveIvyDeps())()
val (_, res) = mill.modules.Jvm.resolveDependenciesMetadata(
repositoriesTask(),
deps0.map(resolveCoursierDependency().apply(_)),
deps0.filter(_.force).map(resolveCoursierDependency().apply(_)),
mapDependencies = Some(mapDependencies())
)
val content = res.minDependencies.toSeq
.map(dep => (dep.module.organization.value, dep.module.name.value, dep.version))
.sorted
.map {
case (org, name, ver) =>
s"$org:$name:$ver"
}
.mkString("\n")
.getBytes("UTF-8")
if (!os.exists(dest) || !Arrays.equals(content, os.read.bytes(dest))) {
os.write.over(dest, content, createFolders = true)
System.err.println(s"Wrote $dest")
}
Seq(PathRef(dir))
}
def resources = T.sources {
super.resources() ++ dependencyFileResources()
}
}
object `spark-stubs_24` extends SbtModule with AmmSparkPublishModule {
def scalaVersion = Versions.scala212
def ivyDeps = super.ivyDeps() ++ Agg(
Deps.sparkSql(scalaVersion())
)
}
object `spark-stubs_30` extends SbtModule with AmmSparkPublishModule {
def scalaVersion = Versions.scala212
def ivyDeps = super.ivyDeps() ++ Agg(
Deps.sparkSql3
)
}
object `spark-stubs_32` extends Cross[SparkStubs32](Versions.scala: _*)
class SparkStubs32(val crossScalaVersion: String) extends CrossSbtModule
with AmmSparkPublishModule {
def ivyDeps = super.ivyDeps() ++ Agg(
Deps.sparkSql32
)
}
object core extends Cross[Core](Versions.scala: _*)
class Core(val crossScalaVersion: String) extends CrossSbtModule with WithPropertyFile
with AmmSparkPublishModule with AmmSparkMima {
def artifactName = "ammonite-spark"
def compileIvyDeps = super.compileIvyDeps() ++ Agg(
Deps.ammoniteReplApi,
Deps.sparkSql(scalaVersion())
)
def ivyDeps = super.ivyDeps() ++ Agg(
Deps.classPathUtil,
Deps.jettyServer
)
def propertyFilePath =
os.sub / "org" / "apache" / "spark" / "sql" / "ammonitesparkinternals" / "ammonite-spark.properties"
def versionInProperties = publishVersion()
def propResourcesDir = T.persistent {
import sys.process._
val dir = T.dest / "property-resources"
val ver = publishVersion()
val f =
dir / "org" / "apache" / "spark" / "sql" / "ammonitesparkinternals" / "ammonite-spark.properties"
val contentStr =
s"""commit-hash=${Seq("git", "rev-parse", "HEAD").!!.trim}
|version=$ver
|""".stripMargin
val content = contentStr.getBytes("UTF-8")
val currentContentOpt = if (os.exists(f)) Some(os.read.bytes(f)) else None
if (!os.exists(f) || !Arrays.equals(content, os.read.bytes(f))) {
os.write.over(f, content, createFolders = true)
System.err.println(s"Wrote $f")
}
PathRef(dir)
}
def resources = T.sources {
super.resources() ++ Seq(propResourcesDir())
}
def mimaPreviousVersions = T {
val needs =
if (scalaVersion().startsWith("2.12.")) "v0.9.0"
else "v0.13.0"
os.proc("git", "tag", "--merged", "HEAD^", "--contains", needs)
.call()
.out.lines()
.map(_.trim)
.filter(_.startsWith("v"))
.map(_.stripPrefix("v"))
}
}
trait AmmSparkTests extends TestModule {
def testFramework = "utest.runner.Framework"
def forkArgs = super.forkArgs() ++ Seq("-Xmx3g", "-Dfoo=bzz")
}
object tests extends Cross[Tests](Versions.scala: _*)
class Tests(val crossScalaVersion: String) extends CrossSbtModule with WithPropertyFile
with WithDependencyResourceFile {
def propertyFilePath = os.sub / "ammonite" / "ammonite-spark.properties"
def versionInProperties = core().publishVersion()
def dependencyResourcePath = os.sub / "ammonite" / "spark" / "amm-test-dependencies.txt"
def ivyDeps = super.ivyDeps() ++ Agg(
Deps.ammoniteCompiler.exclude(("com.google.guava", "guava")),
Deps.ammoniteRepl.exclude(("com.google.guava", "guava")),
Deps.utest
)
object test extends Tests with AmmSparkTests
}
object `local-spark-distrib-tests` extends SbtModule {
private def sv = Versions.scala212
def scalaVersion = sv
def moduleDeps = super.moduleDeps ++ Seq(
tests(sv)
)
object test extends Tests with AmmSparkTests
}
object `standalone-tests` extends SbtModule {
private def sv = Versions.scala212
def scalaVersion = sv
def moduleDeps = super.moduleDeps ++ Seq(
tests(sv)
)
object test extends Tests with AmmSparkTests
}
object `yarn-tests` extends Cross[YarnTests](Versions.scala: _*)
class YarnTests(val crossScalaVersion: String) extends CrossSbtModule {
def moduleDeps = super.moduleDeps ++ Seq(
tests()
)
object test extends Tests with AmmSparkTests
}
object `yarn-spark-distrib-tests` extends SbtModule {
private def sv = Versions.scala212
def scalaVersion = sv
def moduleDeps = super.moduleDeps ++ Seq(
tests(sv)
)
object test extends Tests with AmmSparkTests
}
object `almond-spark` extends Cross[AlmondSpark](Versions.scala: _*)
class AlmondSpark(val crossScalaVersion: String) extends CrossSbtModule with AmmSparkPublishModule
with AmmSparkMima {
def moduleDeps = super.moduleDeps ++ Seq(
core()
)
def ivyDeps = super.ivyDeps() ++ Agg(
Deps.jsoniterScalaCore,
Deps.scalatags
)
def compileIvyDeps = super.compileIvyDeps() ++ Agg(
Deps.ammoniteReplApi,
Deps.jsoniterScalaMacros,
Deps.log4j2,
Deps.scalaKernelApi
.exclude(("com.lihaoyi", s"ammonite-compiler_$crossScalaVersion"))
.exclude(("com.lihaoyi", s"ammonite-repl-api_$crossScalaVersion")),
Deps.sparkSql(scalaVersion())
)
def repositoriesTask = T.task {
super.repositoriesTask() ++ Seq(
coursier.Repositories.jitpack
)
}
}
object `almond-toree-spark` extends Cross[AlmondToreeSpark](Versions.scala: _*)
class AlmondToreeSpark(val crossScalaVersion: String) extends CrossSbtModule
with AmmSparkPublishModule
with AmmSparkMima {
def moduleDeps = super.moduleDeps ++ Seq(
`almond-spark`()
)
def ivyDeps = super.ivyDeps() ++ Agg(
Deps.almondToreeHooks
)
def compileIvyDeps = super.compileIvyDeps() ++ Agg(
Deps.scalaKernelApi
.exclude(("com.lihaoyi", s"ammonite-compiler_$crossScalaVersion"))
.exclude(("com.lihaoyi", s"ammonite-repl-api_$crossScalaVersion")),
Deps.sparkSql(scalaVersion())
)
def repositoriesTask = T.task {
super.repositoriesTask() ++ Seq(
coursier.Repositories.jitpack
)
}
}
def publishSonatype(tasks: mill.main.Tasks[PublishModule.PublishData]) = T.command {
publishSonatype0(
data = define.Target.sequence(tasks.value)(),
log = T.ctx().log
)
}
def publishSonatype0(
data: Seq[PublishModule.PublishData],
log: mill.api.Logger
): Unit = {
val credentials = sys.env("SONATYPE_USERNAME") + ":" + sys.env("SONATYPE_PASSWORD")
val pgpPassword = sys.env("PGP_PASSPHRASE")
val timeout = 10.minutes
val artifacts = data.map {
case PublishModule.PublishData(a, s) =>
(s.map { case (p, f) => (p.path, f) }, a)
}
val isRelease = {
val versions = artifacts.map(_._2.version).toSet
val set = versions.map(!_.endsWith("-SNAPSHOT"))
assert(
set.size == 1,
s"Found both snapshot and non-snapshot versions: ${versions.toVector.sorted.mkString(", ")}"
)
set.head
}
val publisher = new scalalib.publish.SonatypePublisher(
uri = "https://oss.sonatype.org/service/local",
snapshotUri = "https://oss.sonatype.org/content/repositories/snapshots",
credentials = credentials,
signed = true,
// format: off
gpgArgs = Seq(
"--detach-sign",
"--batch=true",
"--yes",
"--pinentry-mode", "loopback",
"--passphrase", pgpPassword,
"--armor",
"--use-agent"
),
// format: on
readTimeout = timeout.toMillis.toInt,
connectTimeout = timeout.toMillis.toInt,
log = log,
awaitTimeout = timeout.toMillis.toInt,
stagingRelease = isRelease
)
publisher.publishAll(isRelease, artifacts: _*)
}