forked from scala-steward-org/scala-steward
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sbt
501 lines (466 loc) · 17 KB
/
build.sbt
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
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
import scala.util.Properties
import scala.reflect.io.Path
import com.typesafe.sbt.packager.docker._
import sbtcrossproject.{CrossProject, CrossType, Platform}
import org.typelevel.sbt.gha.JavaSpec.Distribution.Temurin
/// variables
val groupId = "org.scala-steward"
val projectName = "scala-steward"
val rootPkg = groupId.replace("-", "")
val gitHubOwner = "scala-steward-org"
val gitHubUrl = s"https://github.com/$gitHubOwner/$projectName"
val mainBranch = "main"
val gitHubUserContent = s"https://raw.githubusercontent.com/$gitHubOwner/$projectName/$mainBranch"
val moduleCrossPlatformMatrix: Map[String, List[Platform]] = Map(
"benchmark" -> List(JVMPlatform),
"core" -> List(JVMPlatform),
"docs" -> List(JVMPlatform),
"dummy" -> List(JVMPlatform)
)
val Scala213 = "2.13.12"
/// sbt-typelevel configuration
ThisBuild / crossScalaVersions := Seq(Scala213)
ThisBuild / githubWorkflowTargetTags ++= Seq("v*")
ThisBuild / githubWorkflowPublishTargetBranches := Seq(
RefPredicate.Equals(Ref.Branch(mainBranch)),
RefPredicate.StartsWith(Ref.Tag("v"))
)
ThisBuild / githubWorkflowPublish := Seq(
WorkflowStep.Run(
List("sbt ci-release"),
name = Some("Publish JARs"),
env = Map(
"PGP_PASSPHRASE" -> "${{ secrets.PGP_PASSPHRASE }}",
"PGP_SECRET" -> "${{ secrets.PGP_SECRET }}",
"SONATYPE_PASSWORD" -> "${{ secrets.SONATYPE_PASSWORD }}",
"SONATYPE_USERNAME" -> "${{ secrets.SONATYPE_USERNAME }}"
)
),
WorkflowStep.Run(
List(
"docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}",
"sbt core/Docker/publish"
),
name = Some("Publish Docker image")
)
)
ThisBuild / githubWorkflowJavaVersions := Seq(JavaSpec(Temurin, "17"), JavaSpec(Temurin, "11"))
ThisBuild / githubWorkflowBuild :=
Seq(
WorkflowStep
.Use(UseRef.Public("coursier", "setup-action", "v1"), params = Map("apps" -> "scalafmt")),
WorkflowStep.Sbt(List("validate"), name = Some("Build project")),
WorkflowStep.Use(
UseRef.Public("codecov", "codecov-action", "v3"),
name = Some("Codecov")
)
)
ThisBuild / mergifyPrRules := {
val authorCondition = MergifyCondition.Or(
List(
MergifyCondition.Custom("author=scala-steward"),
MergifyCondition.Custom("author=scala-steward-dev")
)
)
Seq(
MergifyPrRule(
"label scala-steward's PRs",
List(authorCondition),
List(MergifyAction.Label(List("dependency-update")))
),
MergifyPrRule(
"merge scala-steward's PRs",
List(authorCondition) ++ mergifySuccessConditions.value,
List(MergifyAction.Merge(Some("merge")))
)
)
}
/// global build settings
ThisBuild / dynverSeparator := "-"
ThisBuild / evictionErrorLevel := Level.Info
ThisBuild / tpolecatDefaultOptionsMode := {
if (insideCI.value) org.typelevel.sbt.tpolecat.CiMode else org.typelevel.sbt.tpolecat.DevMode
}
/// projects
lazy val root = project
.in(file("."))
.aggregate(benchmark.jvm, core.jvm, docs.jvm, dummy.jvm)
.settings(commonSettings)
.settings(noPublishSettings)
lazy val benchmark = myCrossProject("benchmark")
.dependsOn(core)
.enablePlugins(JmhPlugin)
.settings(noPublishSettings)
.settings(
scalacOptions -= "-Wnonunit-statement",
coverageEnabled := false,
unusedCompileDependencies := Set.empty
)
lazy val core = myCrossProject("core")
.enablePlugins(BuildInfoPlugin, JavaAppPackaging, DockerPlugin)
.settings(dockerSettings)
.settings(
libraryDependencies ++= Seq(
Dependencies.bcprovJdk15to18,
Dependencies.betterFiles,
Dependencies.catsCore,
Dependencies.catsEffect,
Dependencies.catsParse,
Dependencies.circeConfig,
Dependencies.circeGeneric,
Dependencies.circeGenericExtras,
Dependencies.circeParser,
Dependencies.circeRefined,
Dependencies.commonsIo,
Dependencies.coursierCore,
Dependencies.coursierSbtMaven,
Dependencies.cron4sCore,
Dependencies.decline,
Dependencies.fs2Core,
Dependencies.fs2Io,
Dependencies.http4sCirce,
Dependencies.http4sClient,
Dependencies.http4sCore,
Dependencies.http4sJdkhttpClient,
Dependencies.jjwtApi,
Dependencies.jjwtImpl % Runtime,
Dependencies.jjwtJackson % Runtime,
Dependencies.log4catsSlf4j,
Dependencies.monocleCore,
Dependencies.refined,
Dependencies.scalacacheCaffeine,
Dependencies.logbackClassic % Runtime,
Dependencies.catsLaws % Test,
Dependencies.circeLiteral % Test,
Dependencies.disciplineMunit % Test,
Dependencies.http4sDsl % Test,
Dependencies.http4sEmberServer % Test,
Dependencies.munit % Test,
Dependencies.munitCatsEffect % Test,
Dependencies.munitScalacheck % Test,
Dependencies.refinedScalacheck % Test,
Dependencies.scalacheck % Test
),
assembly / test := {},
assembly / assemblyMergeStrategy := {
case PathList("META-INF", "versions", "9", "module-info.class") =>
// (core / assembly) deduplicate: different file contents found in the following:
// https/repo1.maven.org/maven2/org/jetbrains/kotlin/kotlin-stdlib/1.4.20/kotlin-stdlib-1.4.20.jar:META-INF/versions/9/module-info.class
// https/repo1.maven.org/maven2/org/tukaani/xz/1.9/xz-1.9.jar:META-INF/versions/9/module-info.class
MergeStrategy.first
case PathList("module-info.class") =>
// (core / assembly) deduplicate: different file contents found in the following:
// https/repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-annotations/2.12.6/jackson-annotations-2.12.6.jar:module-info.class
// https/repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-core/2.12.6/jackson-core-2.12.6.jar:module-info.class
// https/repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-databind/2.12.6.1/jackson-databind-2.12.6.1.jar:module-info.class
MergeStrategy.discard
case PathList("META-INF", "sisu", "javax.inject.Named") =>
// (core / assembly) deduplicate: different file contents found in the following:
// https/repo1.maven.org/maven2/org/codehaus/plexus/plexus-archiver/4.5.0/plexus-archiver-4.5.0.jar:META-INF/sisu/javax.inject.Named
// https/repo1.maven.org/maven2/org/codehaus/plexus/plexus-io/3.4.0/plexus-io-3.4.0.jar:META-INF/sisu/javax.inject.Named
MergeStrategy.first
case otherwise =>
val defaultStrategy = (assembly / assemblyMergeStrategy).value
defaultStrategy(otherwise)
},
buildInfoKeys := Seq[BuildInfoKey](
organization,
version,
scalaVersion,
scalaBinaryVersion,
sbtVersion,
BuildInfoKey("gitHubUrl" -> gitHubUrl),
BuildInfoKey("gitHubUserContent" -> gitHubUserContent),
BuildInfoKey("mainBranch" -> mainBranch),
BuildInfoKey.map(git.gitHeadCommit) { case (k, v) => k -> v.getOrElse(mainBranch) },
BuildInfoKey("millPluginArtifactName" -> Dependencies.scalaStewardMillPluginArtifactName),
BuildInfoKey("millPluginVersion" -> Dependencies.scalaStewardMillPlugin.revision)
),
buildInfoPackage := moduleRootPkg.value,
initialCommands += s"""
import ${moduleRootPkg.value}._
import ${moduleRootPkg.value}.data._
import ${moduleRootPkg.value}.util._
import better.files.File
import cats.effect.IO
import org.http4s.client.Client
import org.typelevel.log4cats.Logger
import org.typelevel.log4cats.slf4j.Slf4jLogger
implicit val logger: Logger[IO] = Slf4jLogger.getLogger[IO]
""",
// Inspired by https://stackoverflow.com/a/41978937/460387
Test / sourceGenerators += Def.task {
val file = (Test / sourceManaged).value / "InitialCommandsTest.scala"
val content =
s"""object InitialCommandsTest {
| ${initialCommands.value}
| // prevent warnings
| intellijThisImportIsUsed(Client); intellijThisImportIsUsed(File);
| intellijThisImportIsUsed(Nel); intellijThisImportIsUsed(Repo);
| intellijThisImportIsUsed(Main);
|}""".stripMargin
IO.write(file, content)
Seq(file)
}.taskValue,
run / fork := true,
// Uncomment for remote debugging:
// run / javaOptions += "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005",
Test / fork := true,
Compile / resourceGenerators += Def.task {
val outDir = (Compile / resourceManaged).value
def downloadPlugin(v: String): File = {
val outFile = outDir / s"StewardPlugin_$v.scala"
if (!outFile.exists()) {
val u =
s"https://raw.githubusercontent.com/scala-steward-org/sbt-plugin/main/modules/sbt-plugin-$v/src/main/scala/org/scalasteward/sbt/plugin/StewardPlugin_$v.scala"
val content = scala.util.Using(scala.io.Source.fromURL(u))(_.mkString).get
IO.write(outFile, content)
}
outFile
}
Seq(downloadPlugin("1_0_0"), downloadPlugin("1_3_11"))
}.taskValue
)
lazy val docs = myCrossProject("docs")
.dependsOn(core)
.enablePlugins(MdocPlugin)
.settings(noPublishSettings)
.settings(
mdocIn := baseDirectory.value / ".." / "mdoc",
mdocOut := (LocalRootProject / baseDirectory).value / "docs",
mdocVariables := Map(
"GITHUB_URL" -> gitHubUrl,
"MAIN_BRANCH" -> mainBranch
),
checkDocs := {
val inDir = mdocIn.value.getCanonicalPath
val outDir = mdocOut.value.getCanonicalPath
val rootDir = (LocalRootProject / baseDirectory).value
try git.runner.value.apply("diff", "--quiet", outDir)(rootDir, streams.value.log)
catch {
case t: Throwable =>
val diff = git.runner.value.apply("diff", outDir)(rootDir, streams.value.log)
val msg = s"""|Docs in $inDir and $outDir are out of sync.
|Run 'sbt docs/mdoc' and commit the changes to fix this.
|The diff is:
|$diff
|""".stripMargin
throw new Throwable(msg, t)
}
()
},
coverageEnabled := false,
unusedCompileDependencies := Set.empty
)
// Dummy project to receive updates from @scala-steward for this project's
// libraryDependencies.
lazy val dummy = myCrossProject("dummy")
.disablePlugins(ExplicitDepsPlugin)
.settings(noPublishSettings)
.settings(
libraryDependencies ++= Seq(
Dependencies.scalaStewardMillPlugin
)
)
/// settings
def myCrossProject(name: String): CrossProject =
CrossProject(name, file(name))(moduleCrossPlatformMatrix(name): _*)
.crossType(CrossType.Pure)
.withoutSuffixFor(JVMPlatform)
.in(file(s"modules/$name"))
.settings(
moduleName := s"$projectName-$name",
moduleRootPkg := s"$rootPkg.${name.replace('-', '.')}"
)
.settings(commonSettings)
lazy val commonSettings = Def.settings(
compileSettings,
metadataSettings,
scaladocSettings
)
lazy val compileSettings = Def.settings(
scalaVersion := Scala213,
doctestTestFramework := DoctestTestFramework.Munit
)
lazy val metadataSettings = Def.settings(
name := projectName,
organization := groupId,
homepage := Some(url(gitHubUrl)),
startYear := Some(2018),
licenses := List("Apache-2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0")),
scmInfo := Some(ScmInfo(homepage.value.get, s"scm:git:$gitHubUrl.git")),
headerLicense := Some(HeaderLicense.ALv2("2018-2023", "Scala Steward contributors")),
developers := List(
Developer(
id = "alejandrohdezma",
name = "Alejandro Hernández",
email = "",
url = url("https://github.com/alejandrohdezma")
),
Developer(
id = "exoego",
name = "TATSUNO Yasuhiro",
email = "",
url = url("https://github.com/exoego")
),
Developer(
id = "fthomas",
name = "Frank S. Thomas",
email = "",
url = url("https://github.com/fthomas")
),
Developer(
id = "mzuehlke",
name = "Marco Zühlke",
email = "",
url = url("https://github.com/mzuehlke")
)
)
)
lazy val dockerSettings = Def.settings(
dockerBaseImage := Option(System.getenv("DOCKER_BASE_IMAGE"))
.getOrElse("eclipse-temurin:11-alpine"),
dockerCommands ++= {
val curl = "curl -fL --output"
val binDir = "/usr/local/bin"
val sbtVer = sbtVersion.value
val sbtTgz = s"sbt-$sbtVer.tgz"
val installSbt = Seq(
s"$curl $sbtTgz https://github.com/sbt/sbt/releases/download/v$sbtVer/$sbtTgz",
s"tar -xf $sbtTgz",
s"rm -f $sbtTgz"
).mkString(" && ")
val millVer = Dependencies.millScriptVersion
val millBin = s"$binDir/mill"
val releasePageVersion = millVer.split("-") match {
case Array(v, m, _*) if m.startsWith("M") => s"${v}-${m}"
case Array(v, _*) => v
}
val installMill = Seq(
s"$curl $millBin https://github.com/lihaoyi/mill/releases/download/${releasePageVersion}/$millVer",
s"chmod +x $millBin"
).mkString(" && ")
val csBin = s"$binDir/cs"
val installCoursier = Seq(
s"$curl $csBin.gz https://github.com/coursier/coursier/releases/download/v${Dependencies.coursierCore.revision}/cs-x86_64-pc-linux-static.gz",
s"gunzip $csBin.gz",
s"chmod +x $csBin"
).mkString(" && ")
val scalaCliBin = s"$binDir/scala-cli"
val installScalaCli = Seq(
s"$curl $scalaCliBin.gz https://github.com/Virtuslab/scala-cli/releases/latest/download/scala-cli-x86_64-pc-linux-static.gz",
s"gunzip $scalaCliBin.gz",
s"chmod +x $scalaCliBin"
).mkString(" && ")
Seq(
Cmd("USER", "root"),
Cmd(
"RUN",
"apk --no-cache add bash git ca-certificates curl maven openssh nodejs npm ncurses"
),
Cmd("RUN", installSbt),
Cmd("RUN", installMill),
Cmd("RUN", installCoursier),
Cmd("RUN", installScalaCli),
Cmd("RUN", s"$csBin install --install-dir $binDir scalafix scalafmt"),
Cmd("RUN", "npm install --global yarn"),
// Ensure binaries are in PATH
Cmd("RUN", "echo $PATH"),
Cmd("RUN", "which cs mill mvn node npm sbt scala-cli scalafix scalafmt yarn")
)
},
Docker / packageName := s"fthomas/${name.value}",
dockerUpdateLatest := true,
dockerAliases ++= {
if (!isSnapshot.value) Seq(dockerAlias.value.withTag(Option("latest-release"))) else Nil
},
dockerEnvVars := Map(
"PATH" -> "/opt/docker/sbt/bin:${PATH}",
"COURSIER_PROGRESS" -> "false"
)
)
lazy val noPublishSettings = Def.settings(
publish / skip := true
)
lazy val scaladocSettings = Def.settings(
Compile / doc / scalacOptions ++= {
val tag = s"v${version.value}"
val tree = if (isSnapshot.value) git.gitHeadCommit.value.getOrElse(mainBranch) else tag
Seq(
"-doc-source-url",
s"${scmInfo.value.get.browseUrl}/blob/$tree€{FILE_PATH}.scala",
"-sourcepath",
(LocalRootProject / baseDirectory).value.getAbsolutePath
)
}
)
/// setting keys
lazy val checkDocs = taskKey[Unit]("")
lazy val moduleRootPkg = settingKey[String]("").withRank(KeyRanks.Invisible)
moduleRootPkg := rootPkg
// Run Scala Steward from sbt for development and testing.
// Members of the @scala-steward-org/core team can request an access token
// of @scala-steward-dev for local development from @fthomas.
lazy val runSteward = taskKey[Unit]("")
runSteward := Def.taskDyn {
val home = System.getenv("HOME")
val projectDir = (LocalRootProject / baseDirectory).value
val gitHubLogin = projectName + "-dev"
// val gitHubAppDir = projectDir.getParentFile / "gh-app"
val args = Seq(
Seq("--workspace", s"$projectDir/workspace"),
Seq("--repos-file", s"$projectDir/repos.md"),
Seq("--git-author-email", s"dev@$projectName.org"),
Seq("--forge-login", gitHubLogin),
Seq("--git-ask-pass", s"$home/.github/askpass/$gitHubLogin.sh"),
// Seq("--github-app-id", IO.read(gitHubAppDir / "scala-steward.app-id.txt").trim),
// Seq("--github-app-key-file", s"$gitHubAppDir/scala-steward.private-key.pem"),
Seq("--whitelist", s"$home/.cache/coursier"),
Seq("--whitelist", s"$home/.cache/JNA"),
Seq("--whitelist", s"$home/.cache/mill"),
Seq("--whitelist", s"$home/.ivy2"),
Seq("--whitelist", s"$home/.m2"),
Seq("--whitelist", s"$home/.mill"),
Seq("--whitelist", s"$home/.sbt")
).flatten.mkString(" ", " ", "")
(core.jvm / Compile / run).toTask(args)
}.value
lazy val runValidateRepoConfig = taskKey[Unit]("")
runValidateRepoConfig := Def.taskDyn {
val projectDir = (LocalRootProject / baseDirectory).value
val args = Seq(
Seq("validate-repo-config", s"$projectDir/.scala-steward.conf")
).flatten.mkString(" ", " ", "")
(core.jvm / Compile / run).toTask(args)
}.value
/// commands
def addCommandsAlias(name: String, cmds: Seq[String]) =
addCommandAlias(name, cmds.mkString(";", ";", ""))
addCommandsAlias(
"validate",
Seq(
"clean",
"headerCheck",
"scalafmtCheckAll",
"scalafmtSbtCheck",
"unusedCompileDependenciesTest",
"coverage",
"test",
"coverageReport",
"doc",
"docs/mdoc",
"docs/checkDocs",
"package",
"packageSrc",
"core/assembly",
"Docker/publishLocal"
)
)
addCommandsAlias(
"fmt",
Seq(
"headerCreate",
"scalafmtAll",
"scalafmtSbt"
)
)