-
Notifications
You must be signed in to change notification settings - Fork 5
/
build.sbt
277 lines (251 loc) · 8.96 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
import sbt.internal.ProjectMatrix
import sbtghactions.JavaSpec
import complete.DefaultParsers._
import sbt.Reference.display
import org.typelevel.sbt.tpolecat.{CiMode, DevMode}
val munitVersion = "1.0.2"
val munitScalacheckVersion = "1.0.0"
val catsVersion = "2.12.0"
val scalatestVersion = "3.2.19"
val weaverVersion = "0.8.4"
val isScala3 = Def.setting {
// doesn't work well with >= 3.0.0 for `3.0.0-M1`
scalaVersion.value.startsWith("3")
}
val mainScalaVersion = Build.Scala213
val jvmScalaVersions = Seq(Build.Scala213, Build.Scala3)
inThisBuild(
List(
scalaVersion := mainScalaVersion,
organization := "com.github.jatcwang",
homepage := Some(url("https://github.com/jatcwang/difflicious")),
licenses := List("Apache-2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0")),
developers := List(
Developer(
"jatcwang",
"Jacob Wang",
"jatcwang@gmail.com",
url("https://almostfunctional.com"),
),
),
commands ++= Build.createBuildCommands(allModules),
tpolecatDefaultOptionsMode := (if (sys.env.contains("CI")) CiMode else DevMode),
),
)
lazy val allModules = Seq(core, coretest, munit, scalatest, weaver, cats, benchmarks, docs).flatMap(_.projectRefs)
lazy val difflicious = Project("difflicious", file("."))
.aggregate(allModules: _*)
.settings(commonSettings, noPublishSettings)
lazy val core = projectMatrix
.in(file("modules/core"))
.settings(commonSettings)
.settings(
name := "difflicious-core",
libraryDependencies ++= Seq(
"dev.zio" %% "izumi-reflect" % "2.3.10",
"com.lihaoyi" %% "fansi" % "0.5.0",
) ++ (if (isScala3.value) {
Seq("com.softwaremill.magnolia1_3" %% "magnolia" % "1.3.7")
} else
Seq(
"com.softwaremill.magnolia1_2" %% "magnolia" % "1.1.10",
"org.scala-lang" % "scala-reflect" % Build.Scala213,
)),
Compile / sourceGenerators += Def.task {
val file = (Compile / sourceManaged).value / "difflicious" / "TupleDifferInstances.scala"
IO.write(file, TupleDifferInstancesGen.fileContent)
Seq(file)
}.taskValue,
)
.jvmPlatform(jvmScalaVersions)
lazy val munit = projectMatrix
.in(file("modules/munit"))
.dependsOn(core)
.settings(commonSettings)
.settings(
name := "difflicious-munit",
libraryDependencies ++= Seq(
"org.scalameta" %% "munit" % munitVersion,
),
)
.jvmPlatform(jvmScalaVersions)
lazy val scalatest = projectMatrix
.in(file("modules/scalatest"))
.dependsOn(core)
.settings(commonSettings)
.settings(
name := "difflicious-scalatest",
libraryDependencies ++= Seq(
"org.scalatest" %% "scalatest-core" % scalatestVersion,
),
)
.jvmPlatform(jvmScalaVersions)
lazy val weaver = projectMatrix
.in(file("modules/weaver"))
.dependsOn(core)
.settings(commonSettings)
.settings(
name := "difflicious-weaver",
libraryDependencies ++= Seq(
"com.disneystreaming" %% "weaver-core" % weaverVersion,
),
)
.jvmPlatform(jvmScalaVersions)
lazy val cats = projectMatrix
.in(file("modules/cats"))
.dependsOn(core, coretest % "test->test")
.settings(commonSettings)
.settings(
name := "difflicious-cats",
libraryDependencies ++= Seq(
"org.typelevel" %% "cats-core" % catsVersion,
),
libraryDependencies ++= Seq(
"org.typelevel" %% "cats-laws" % catsVersion,
).map(_ % Test),
)
.jvmPlatform(jvmScalaVersions)
lazy val coretest = projectMatrix
.in(file("modules/coretest"))
.dependsOn(core)
.settings(commonSettings, noPublishSettings)
.settings(
name := "coretest",
libraryDependencies ++= Seq(
"org.typelevel" %% "cats-core" % catsVersion,
),
// Test deps
libraryDependencies ++= Seq(
"org.scalameta" %% "munit" % munitVersion,
"org.scalameta" %% "munit-scalacheck" % munitScalacheckVersion,
).map(_ % Test),
)
.jvmPlatform(jvmScalaVersions)
lazy val docs: ProjectMatrix = projectMatrix
.dependsOn(core, coretest, cats, munit, scalatest, weaver)
.enablePlugins(MicrositesPlugin)
.settings(
name := "docs",
commonSettings,
publish / skip := true,
)
.settings(
libraryDependencies ++= Seq(
"org.scalatest" %% "scalatest" % scalatestVersion,
"com.disneystreaming" %% "weaver-cats" % weaverVersion,
),
makeMicrosite := Def.taskDyn {
val orig = (ThisProject / makeMicrosite).taskValue
if (isScala3.value) Def.task({})
else Def.task(orig.value)
}.value,
)
.settings(
mdocIn := file("docs/docs"),
mdocExtraArguments ++= Seq("--noLinkHygiene"),
micrositeName := "Difflicious",
micrositeDescription := "Diffs for human consumption",
micrositeUrl := "https://jatcwang.github.io",
micrositeBaseUrl := "/difflicious",
micrositeDocumentationUrl := s"${micrositeBaseUrl.value}/docs/introduction",
micrositeAuthor := "Jacob Wang",
micrositeGithubOwner := "jatcwang",
micrositeGithubRepo := "difflicious",
micrositeHighlightTheme := "a11y-light",
micrositePushSiteWith := GitHub4s,
micrositeGithubToken := sys.env.get("GITHUB_TOKEN"),
)
.settings(
// Disable any2stringAdd deprecation in md files. Seems like mdoc macro generates code which
// use implicit conversion to string
scalacOptions ~= { opts =>
val extraOpts =
Seq(
"-Wconf:msg=\".*method any2stringadd.*\":i",
"-Wconf:msg=\".*The outer reference in this type test.*\":s", // This warning shows up if we use *final* case class in code blocks
"-Wconf:msg=\".*method right in class Either.*\":s",
"-Wconf:msg=\".*method get in class RightProjection.*\":s",
"-Wconf:msg=\".*local (object|class).+?is never used\":s",
)
val removes = Set("-Wdead-code", "-Ywarn-dead-code", "-Wnonunit-statement") // we use ??? in various places
(opts ++ extraOpts).filterNot(removes)
},
)
.jvmPlatform(Seq(Build.Scala213))
lazy val benchmarks = projectMatrix
.in(file("modules/benchmarks"))
.dependsOn(coretest)
.enablePlugins(JmhPlugin)
.settings(commonSettings)
.settings(noPublishSettings)
.jvmPlatform(jvmScalaVersions)
lazy val commonSettings = Seq(
versionScheme := Some("early-semver"),
scalacOptions ++= (if (isScala3.value) Seq.empty[String] else Seq("-Wmacros:after")),
// TODO: Not sure why but having these scalac options seems to crash the compiler complaining about
// magnoalia class files having duplicate top level definitions..
// Maybe related to https://github.com/scala/scala3/issues/18674
scalacOptions --= (if (isScala3.value)
Seq(
"-Wunused:implicits",
"-Wunused:explicits",
"-Wunused:imports",
"-Wunused:locals",
"-Wunused:params",
"-Wunused:privates",
)
else Seq.empty),
libraryDependencies ++= Seq(
compilerPlugin("org.typelevel" %% "kind-projector" % "0.13.3" cross CrossVersion.full),
compilerPlugin("com.olegpy" %% "better-monadic-for" % "0.3.1"),
).filterNot(_ => isScala3.value),
)
lazy val noPublishSettings = Seq(
publish / skip := true,
)
ThisBuild / githubWorkflowJavaVersions := Seq(JavaSpec.temurin("11"))
ThisBuild / githubWorkflowTargetTags ++= Seq("v*")
ThisBuild / githubWorkflowPublishTargetBranches :=
Seq(RefPredicate.StartsWith(Ref.Tag("v")))
ThisBuild / githubWorkflowPublish := Seq(
WorkflowStep.Sbt(
List("ci-release", "publishMicrosite"),
env = Map(
"PGP_PASSPHRASE" -> "${{ secrets.PGP_PASSPHRASE }}",
"PGP_SECRET" -> "${{ secrets.PGP_SECRET }}",
"SONATYPE_PASSWORD" -> "${{ secrets.SONATYPE_PASSWORD }}",
"SONATYPE_USERNAME" -> "${{ secrets.SONATYPE_USERNAME }}",
),
),
)
val setupJekyllSteps = Seq(
WorkflowStep.Use(
UseRef.Public("ruby", "setup-ruby", "v1"),
name = Some("Setup ruby"),
params = Map("ruby-version" -> "3.3"),
),
WorkflowStep.Run(
List("gem install jekyll -v 4.3.3"),
name = Some("Install Jekyll (to build microsite)"),
),
)
ThisBuild / githubWorkflowBuildMatrixAdditions += ("scalaPlatform", List("jvm"))
ThisBuild / githubWorkflowBuildPreamble ++= setupJekyllSteps
ThisBuild / githubWorkflowPublishPreamble ++= setupJekyllSteps
ThisBuild / githubWorkflowScalaVersions := Seq("2_13", "3_0")
ThisBuild / githubWorkflowBuildSbtStepPreamble := Seq.empty
ThisBuild / githubWorkflowArtifactUpload := false
// Add makeMicrosite to the build step
ThisBuild / githubWorkflowBuild ~= { steps =>
steps.map {
case w: WorkflowStep.Sbt if w.commands == List("test") =>
w.copy(commands =
List("test", "publishLocal").map(_ + "_${{ matrix.scala }}_${{ matrix.scalaPlatform }}") :+ "makeMicrosite",
)
case w => w
}
}
// Filter out MacOS and Windows cache steps to make yaml less noisy
ThisBuild / githubWorkflowGeneratedCacheSteps ~= { currentSteps =>
currentSteps.filterNot(wf => wf.cond.exists(str => str.contains("macos") || str.contains("windows")))
}