-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbuild.sbt
390 lines (348 loc) · 12.1 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
import Dependencies.*
import org.scalajs.linker.interface.ModuleSplitStyle
import scala.sys.process.*
ThisBuild / ScalafixConfig / bspEnabled.withRank(KeyRanks.Invisible) := false
ThisBuild / evictionErrorLevel := Level.Info
ThisBuild / resolvers ++= Resolver.sonatypeOssRepos("snapshots")
ThisBuild / lucumaCssExts += "svg"
addCommandAlias(
"quickTest",
"modelTestsJVM/test"
)
addCommandAlias(
"fixImports",
"; scalafix OrganizeImports; Test/scalafix OrganizeImports"
)
addCommandAlias(
"fix",
"; prePR; fixCSS"
)
ThisBuild / description := "Explore"
Global / onChangedBuildSource := ReloadOnSourceChanges
ThisBuild / scalafixDependencies += "edu.gemini" % "lucuma-schemas_3" % Versions.lucumaSchemas
ThisBuild / scalaVersion := "3.6.3"
ThisBuild / crossScalaVersions := Seq("3.6.3")
ThisBuild / scalacOptions ++= Seq("-language:implicitConversions")
ThisBuild / scalafixResolvers += coursierapi.MavenRepository.of(
"https://s01.oss.sonatype.org/content/repositories/snapshots/"
)
val stage = taskKey[Unit]("Prepare static files to deploy to Firebase")
// For simplicity, the build's stage only deals with the explore app.
stage := {
val jsFiles = (explore / Compile / fullLinkJS).value
if (sys.env.getOrElse("POST_STAGE_CLEAN", "false").equals("true")) {
println("Cleaning up...")
// Remove coursier cache
val coursierCacheDir = csrCacheDirectory.value
sbt.IO.delete(coursierCacheDir)
}
}
lazy val root = tlCrossRootProject
.aggregate(model, modelTests, common, explore, workers)
.settings(name := "explore-root")
lazy val model = crossProject(JVMPlatform, JSPlatform)
.crossType(CrossType.Full)
.in(file("model"))
.settings(commonSettings: _*)
.settings(commonLibSettings: _*)
.jvmSettings(commonJVMSettings)
.jsSettings(commonJsLibSettings)
lazy val modelTestkit = crossProject(JVMPlatform, JSPlatform)
.crossType(CrossType.Full)
.in(file("model-testkit"))
.dependsOn(model)
.settings(commonSettings: _*)
.settings(commonLibSettings: _*)
.settings(testkitLibSettings: _*)
.jsSettings(commonModuleTest: _*)
.jvmSettings(commonJVMSettings)
lazy val modelTests = crossProject(JVMPlatform, JSPlatform)
.crossType(CrossType.Full)
.in(file("model-tests"))
.dependsOn(modelTestkit)
.settings(commonSettings: _*)
.settings(commonLibSettings: _*)
.jsSettings(commonModuleTest: _*)
.jvmSettings(commonJVMSettings)
lazy val workers = project
.in(file("workers"))
.settings(commonSettings: _*)
.settings(commonJsLibSettings: _*)
.settings(commonLibSettings: _*)
.settings(esModule: _*)
.settings(
libraryDependencies ++= LucumaCatalog.value ++
Http4sDom.value ++
Log4Cats.value,
Test / scalaJSLinkerConfig ~= {
import org.scalajs.linker.interface.OutputPatterns
_.withOutputPatterns(OutputPatterns.fromJSFile("%s.mjs"))
}
)
.enablePlugins(ScalaJSPlugin)
.dependsOn(model.js)
lazy val common = project
.in(file("common"))
.dependsOn(model.js, modelTestkit.js % Test)
.settings(commonSettings: _*)
.settings(commonJsLibSettings: _*)
.settings(commonModuleTest: _*)
.settings(
libraryDependencies ++=
LucumaSSO.value ++
LucumaCatalog.value ++
LucumaSchemas.value ++
LucumaReact.value ++
In(Test)(LucumaUITestKit.value),
buildInfoKeys := Seq[BuildInfoKey](
scalaVersion,
sbtVersion,
git.gitHeadCommit,
"buildDateTime" -> System.currentTimeMillis()
),
buildInfoPackage := "explore"
)
.enablePlugins(ScalaJSPlugin, BuildInfoPlugin)
lazy val explore: Project = project
.in(file("explore"))
.dependsOn(model.js, common)
.settings(commonSettings: _*)
.settings(commonJsLibSettings: _*)
.settings(esModule: _*)
.enablePlugins(ScalaJSPlugin, LucumaCssPlugin, CluePlugin)
.settings(
Test / test := {},
coverageEnabled := false,
libraryDependencies ++=
GeminiLocales.value ++
ReactAladin.value ++
LucumaReact.value,
// Build workers when you build explore
Compile / fastLinkJS := (Compile / fastLinkJS)
.dependsOn(workers / Compile / fastLinkJS)
.value,
Compile / fullLinkJS := (Compile / fullLinkJS).dependsOn(workers / Compile / fullLinkJS).value
)
lazy val commonSettings = lucumaGlobalSettings ++ Seq(
scalacOptions ~= (_.filterNot(Set("-Vtype-diffs")))
)
lazy val commonLibSettings = Seq(
libraryDependencies ++=
Cats.value ++
CatsEffect.value ++
CatsRetry.value ++
Circe.value ++
Clue.value ++
CoulombRefined.value ++
Crystal.value ++
FS2.value ++
Http4sCore.value ++
Kittens.value ++
LucumaCore.value ++
LucumaSchemas.value ++
LucumaOdbSchema.value ++
LucumaRefined.value ++
LucumaAgs.value ++
LucumaITCClient.value ++
RefinedAlgebra.value ++
Monocle.value ++
Mouse.value ++
Boopickle.value ++
In(Test)(
MUnit.value ++
MUnitScalaCheck.value ++
Discipline.value ++
CatsTimeTestkit.value ++
CatsEffectTestkit.value ++
MUnitCatsEffect.value ++
MonocleLaw.value
),
testFrameworks += new TestFramework("munit.Framework")
)
lazy val testkitLibSettings = Seq(
libraryDependencies ++= Discipline.value ++
MonocleLaw.value ++
CatsTimeTestkit.value ++
CatsEffectTestkit.value ++
LucumaCoreTestKit.value ++
LucumaCatalogTestKit.value ++
LucumaSchemasTestkit.value
)
lazy val commonJVMSettings = Seq(
libraryDependencies ++=
FS2IO.value
)
lazy val commonJsLibSettings = commonLibSettings ++ Seq(
libraryDependencies ++=
ClueScalaJS.value ++
Http4sDom.value ++
FS2Dom.value ++
Log4Cats.value ++
ScalaCollectionContrib.value ++
ScalaJsReact.value ++
ScalaJSDom.value ++
LucumaUI.value ++
In(Test)(
ScalaJsReactTest.value
),
dependencyOverrides ++= ScalaJsReact.value
)
lazy val commonModuleTest = Seq(
Test / scalaJSLinkerConfig ~= { _.withModuleKind(ModuleKind.CommonJSModule) }
)
lazy val esModule = Seq(
scalaJSLinkerConfig ~= { _.withModuleKind(ModuleKind.ESModule) },
Compile / fastLinkJS / scalaJSLinkerConfig ~= { _.withSourceMap(false) },
Compile / fullLinkJS / scalaJSLinkerConfig ~= { _.withSourceMap(false) },
Compile / fullLinkJS / scalaJSLinkerConfig ~= { _.withMinify(true) },
Compile / fastLinkJS / scalaJSLinkerConfig ~= (_.withModuleSplitStyle(
// Linking with smaller modules seems to take way longer.
// ModuleSplitStyle.SmallModulesFor(List("explore"))
ModuleSplitStyle.FewestModules
)),
Compile / fullLinkJS / scalaJSLinkerConfig ~= (_.withModuleSplitStyle(
ModuleSplitStyle.FewestModules
))
)
val lintCSS = TaskKey[Unit]("lintCSS", "Lint CSS files")
lintCSS := {
if (("npm run lint-dark" #&& "npm run lint-light" !) != 0)
throw new Exception("Error in CSS format")
}
val fixCSS = TaskKey[Unit]("fixCSS", "Fix CSS files")
fixCSS := {
if (("npm run fix-dark" #&& "npm run fix-light" !) != 0)
throw new Exception("Error in CSS fix")
}
val pushCond = "github.event_name == 'push'"
val prCond = "github.event_name == 'pull_request'"
val mainCond = "github.ref == 'refs/heads/main'"
val notMainCond = "github.ref != 'refs/heads/main'"
val geminiRepoCond = "startsWith(github.repository, 'gemini')"
val notDependabotCond = "github.actor != 'dependabot[bot]'"
def allConds(conds: String*) = conds.mkString("(", " && ", ")")
def anyConds(conds: String*) = conds.mkString("(", " || ", ")")
val faNpmAuthToken = "FONTAWESOME_NPM_AUTH_TOKEN" -> "${{ secrets.FONTAWESOME_NPM_AUTH_TOKEN }}"
// https://github.com/actions/setup-node/issues/835#issuecomment-1753052021
lazy val setupNodeNpmInstall =
List(
WorkflowStep.Use(
UseRef.Public("actions", "setup-node", "v4"),
name = Some("Setup Node.js"),
params = Map("node-version" -> "20", "cache" -> "npm")
),
WorkflowStep.Use(
UseRef.Public("actions", "cache", "v4"),
name = Some("Cache node_modules"),
id = Some("cache-node_modules"),
params = {
val prefix = "node_modules"
val key = s"$prefix-$${{ hashFiles('package-lock.json') }}"
Map("path" -> "node_modules", "key" -> key, "restore-keys" -> prefix)
}
),
WorkflowStep.Run(
List("npm clean-install --verbose"),
name = Some("npm clean-install"),
cond = Some("steps.cache-node_modules.outputs.cache-hit != 'true'")
)
)
lazy val sbtStage = WorkflowStep.Sbt(List("stage"), name = Some("Stage"))
lazy val lucumaCssStep = WorkflowStep.Sbt(List("lucumaCss"), name = Some("Extract CSS files"))
lazy val npmBuild = WorkflowStep.Run(
List("npm run build"),
name = Some("Build application"),
env = Map(
"NODE_OPTIONS" -> "--max-old-space-size=8192"
)
)
// https://frontside.com/blog/2020-05-26-github-actions-pull_request/#how-does-pull_request-affect-actionscheckout
lazy val overrideCiCommit = WorkflowStep.Run(
List("""echo "CI_COMMIT_SHA=${{ github.event.pull_request.head.sha}}" >> $GITHUB_ENV"""),
name = Some("override CI_COMMIT_SHA"),
cond = Some(prCond)
)
lazy val bundlemon = WorkflowStep.Use(
UseRef.Public("lironer", "bundlemon-action", "v1"),
name = Some("Run BundleMon")
)
def firebaseDeploy(name: String, cond: String, live: Boolean) = WorkflowStep.Use(
UseRef.Public("FirebaseExtended", "action-hosting-deploy", "v0"),
name = Some(name),
cond = Some(cond),
params = Map(
"repoToken" -> "${{ secrets.GITHUB_TOKEN }}",
"firebaseServiceAccount" -> "${{ secrets.FIREBASE_SERVICE_ACCOUNT_EXPLORE_GEMINI }}",
"projectId" -> "explore-gemini",
"target" -> "dev"
) ++ (if (live) Map("channelId" -> "live") else Map.empty)
)
lazy val firebaseDeployReview = firebaseDeploy(
"Deploy review app to Firebase",
allConds(prCond,
notDependabotCond,
"github.event.pull_request.head.repo.full_name == github.repository"
),
live = false
)
lazy val firebaseDeployDev = firebaseDeploy(
"Deploy staging app to Firebase",
mainCond,
live = true
)
def setupVars(mode: String) = WorkflowStep.Run(
List(
// Removes all lines that don't define a variable, thus building a viable CSS file for linting
raw"""sed '/^[[:blank:]]*[\\.\\}\\@]/d;/^[[:blank:]]*\..*/d;/^[[:blank:]]*$$/d;/\/\/.*/d' explore/target/lucuma-css/lucuma-ui-variables-$mode.scss > vars.css""",
"cat vars.css"
),
name = Some(s"Setup and expand vars $mode"),
cond = if (mode == "dark") None else Some("github.event_name != 'pull_request'")
)
def runLinters(mode: String) = WorkflowStep.Run(
List(
"npx prettier --check .",
"npx stylelint --formatter github common/src/main/webapp/sass"
),
name = Some(s"Run linters in $mode mode"),
cond = if (mode == "dark") None else Some("github.event_name != 'pull_request'")
)
ThisBuild / githubWorkflowGeneratedUploadSteps := Seq.empty
ThisBuild / githubWorkflowSbtCommand := "sbt -v -J-Xmx6g"
ThisBuild / githubWorkflowBuildPreamble ++= setupNodeNpmInstall
ThisBuild / githubWorkflowEnv += faNpmAuthToken
ThisBuild / githubWorkflowAddedJobs +=
WorkflowJob(
"full",
"full",
githubWorkflowJobSetup.value.toList :::
setupNodeNpmInstall :::
sbtStage ::
npmBuild ::
overrideCiCommit ::
bundlemon ::
// firebaseDeployReview ::
firebaseDeployDev ::
Nil,
// Only 1 scalaVersion, so no need for matrix
sbtStepPreamble = Nil,
scalas = Nil,
javas = githubWorkflowJavaVersions.value.toList.take(1),
cond = Some(allConds(anyConds(mainCond, prCond), geminiRepoCond))
)
ThisBuild / githubWorkflowAddedJobs +=
WorkflowJob(
"lint",
"Run linters",
githubWorkflowJobSetup.value.toList :::
setupNodeNpmInstall :::
lucumaCssStep ::
setupVars("dark") ::
runLinters("dark") ::
setupVars("light") ::
runLinters("light") ::
Nil,
scalas = List(scalaVersion.value),
javas = githubWorkflowJavaVersions.value.toList.take(1),
cond = Some(allConds(anyConds(mainCond, prCond), geminiRepoCond, notDependabotCond))
)