-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.sbt
239 lines (216 loc) · 9.59 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
import org.scalajs.linker.interface.ESVersion
import org.openqa.selenium.WebDriver
import org.openqa.selenium.chrome.ChromeDriver
import org.openqa.selenium.chrome.ChromeOptions
import org.openqa.selenium.firefox.FirefoxOptions
import org.openqa.selenium.firefox.FirefoxProfile
import org.openqa.selenium.remote.server.DriverFactory
import org.openqa.selenium.remote.server.DriverProvider
import org.scalajs.jsenv.jsdomnodejs.JSDOMNodeJSEnv
import org.scalajs.jsenv.selenium.SeleniumJSEnv
import java.util.concurrent.TimeUnit
import org.commonmark.parser.Parser
import org.commonmark.renderer.html.HtmlRenderer
val disableWebsiteOnCI = false
val ciVariants = List("ciFirefox", "ciChrome", "ciJSDOMNodeJS")
lazy val useJSEnv =
settingKey[JSEnv]("Use Node.js or a headless browser for running Scala.js tests")
addCommandAlias("ci", ciVariants.mkString("; ", "; ", ""))
addCommandAlias("ciFirefox", "; set Global / useJSEnv := JSEnv.Firefox; compile; set Global / useJSEnv := JSEnv.NodeJS")
addCommandAlias("ciChrome", "; set Global / useJSEnv := JSEnv.Chrome; compile; set Global / useJSEnv := JSEnv.NodeJS")
addCommandAlias("ciJSDOMNodeJS", "; set Global / useJSEnv := JSEnv.JSDOMNodeJS; compile; set Global / useJSEnv := JSEnv.NodeJS")
//addCommandAlias("ciFirefox", "; set Global / useJSEnv := JSEnv.Firefox; test; set Global / useJSEnv := JSEnv.NodeJS")
//addCommandAlias("ciChrome", "; set Global / useJSEnv := JSEnv.Chrome; test; set Global / useJSEnv := JSEnv.NodeJS")
//addCommandAlias("ciJSDOMNodeJS", "; set Global / useJSEnv := JSEnv.JSDOMNodeJS; test; set Global / useJSEnv := JSEnv.NodeJS")
Global / useJSEnv := JSEnv.NodeJS
inThisBuild(
List(
resolvers ++= Resolver.sonatypeOssRepos("snapshots"),
organization := "io.frontroute",
homepage := Some(url("https://github.com/tulz-app/frontroute-calico")),
licenses := List("MIT" -> url("https://github.com/tulz-app/frontroute-calico/blob/main/LICENSE.md")),
scmInfo := Some(ScmInfo(url("https://github.com/tulz-app/frontroute-calico"), "scm:git@github.com/tulz-app/frontroute.git")),
developers := List(Developer("yurique", "Iurii Malchenko", "i@yurique.com", url("https://github.com/yurique"))),
description := "Router library for Calico with DSL inspired by Akka HTTP.",
Test / publishArtifact := false,
scalafmtOnCompile := false,
versionScheme := Some("early-semver"),
scalaVersion := ScalaVersions.v3,
crossScalaVersions := Seq(
ScalaVersions.v3,
),
versionPolicyIntention := Compatibility.BinaryCompatible,
sonatypeCredentialHost := "oss.sonatype.org",
githubWorkflowJavaVersions := Seq(JavaSpec.temurin("17")),
// githubWorkflowBuild += WorkflowStep.Sbt(List("versionPolicyCheck")),
githubWorkflowTargetTags ++= Seq("v*"),
githubWorkflowArtifactUpload := false,
githubWorkflowPublishTargetBranches := Seq(RefPredicate.StartsWith(Ref.Tag("v"))),
githubWorkflowPublish := Seq(WorkflowStep.Sbt(List("ci-release"))),
githubWorkflowBuild := Seq(
WorkflowStep.Sbt(
List("${{ matrix.ci }}")
)
) ++ Seq(
WorkflowStep.Sbt(
List("website/fastLinkJS"),
name = Some("build website"),
cond = Some("matrix.ci == 'ciJSDOMNodeJS'")
)
).filterNot(_ => disableWebsiteOnCI),
githubWorkflowEnv ~= (_ ++ Map(
"PGP_PASSPHRASE" -> s"$${{ secrets.PGP_PASSPHRASE }}",
"PGP_SECRET" -> s"$${{ secrets.PGP_SECRET }}",
"SONATYPE_PASSWORD" -> s"$${{ secrets.SONATYPE_PASSWORD }}",
"SONATYPE_USERNAME" -> s"$${{ secrets.SONATYPE_USERNAME }}"
)),
githubWorkflowBuildPreamble ++= Seq(
WorkflowStep.Use(
UseRef.Public("actions", "setup-node", "v3"),
name = Some("Setup NodeJS v18 LTS"),
params = Map("node-version" -> "18", "cache" -> "npm"),
cond = Some("matrix.ci == 'ciJSDOMNodeJS'"),
),
WorkflowStep.Run(
List("npm install"),
name = Some("Install jsdom"),
cond = Some("matrix.ci == 'ciJSDOMNodeJS'")
),
),
githubWorkflowBuildMatrixAdditions += "ci" -> ciVariants,
Test / jsEnv := {
import JSEnv._
val old = (Test / jsEnv).value
useJSEnv.value match {
case NodeJS => old
case JSDOMNodeJS => new JSDOMNodeJSEnv()
case Firefox =>
val profile = new FirefoxProfile()
profile.setPreference("privacy.file_unique_origin", false)
val options = new FirefoxOptions()
options.setProfile(profile)
options.setHeadless(true)
new SeleniumJSEnv(options)
case Chrome =>
val options = new ChromeOptions()
options.setHeadless(true)
options.addArguments("--allow-file-access-from-files")
val factory = new DriverFactory {
val defaultFactory = SeleniumJSEnv.Config().driverFactory
def newInstance(capabilities: org.openqa.selenium.Capabilities): WebDriver = {
val driver = defaultFactory.newInstance(capabilities).asInstanceOf[ChromeDriver]
driver.manage().timeouts().pageLoadTimeout(1, TimeUnit.HOURS)
driver.manage().timeouts().setScriptTimeout(1, TimeUnit.HOURS)
driver
}
def registerDriverProvider(provider: DriverProvider): Unit =
defaultFactory.registerDriverProvider(provider)
}
new SeleniumJSEnv(options, SeleniumJSEnv.Config().withDriverFactory(factory))
}
}
)
)
lazy val frontroute =
project
.in(file("modules/frontroute"))
.enablePlugins(ScalaJSPlugin)
.settings(
name := "frontroute-calico",
libraryDependencies ++=
Seq.concat(
Dependencies.calico.value,
Dependencies.`tuplez-apply`.value,
Dependencies.tuplez.value,
Dependencies.scalatest.value,
Dependencies.`scala-js-macrotask-executor`.value.map(_ % Test)
),
Test / parallelExecution := false,
ScalaOptions.fixOptions,
scalacOptions ++= {
val sourcesGithubUrl = s"https://raw.githubusercontent.com/tulz-app/frontroute-calico/${git.gitHeadCommit.value.get}/"
val sourcesOptionName = CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, _)) => "-P:scalajs:mapSourceURI"
case Some((3, _)) => "-scalajs-mapSourceURI"
case _ => throw new RuntimeException(s"unexpected scalaVersion: ${scalaVersion.value}")
}
val moduleSourceRoot = file("").toURI.toString
Seq(
s"$sourcesOptionName:$moduleSourceRoot->$sourcesGithubUrl"
)
}
)
lazy val parser = Parser.builder.build
lazy val renderer = HtmlRenderer.builder.build
lazy val frontrouteSiteVersion: String = IO.read(file("website/.frontroute-version")).trim
lazy val thisVersionSitePrefix = s"/v/$frontrouteSiteVersion/"
lazy val vars = Seq(
"frontrouteVersion" -> "0.17.0-M3",
"calicoVersion" -> "0.2.0-RC2",
"scalajsVersion" -> "1.13.0",
"scala3version" -> "3.2.1",
)
def templateVars(s: String): String =
vars.foldLeft(s) { case (acc, (varName, varValue)) =>
acc.replace(s"{{${varName}}}", varValue)
}
lazy val website = project
.in(file("website"))
.enablePlugins(ScalaJSPlugin, EmbeddedFilesPlugin, BuildInfoPlugin)
.settings(ScalaOptions.fixOptions)
.settings(noPublish)
.settings(
githubWorkflowTargetTags := Seq.empty,
publish / skip := true,
buildInfoKeys := Seq[BuildInfoKey](
version,
scalaVersion,
BuildInfoKey(
"frontrouteSiteVersion" -> frontrouteSiteVersion
)
),
buildInfoPackage := "frontroute",
Compile / fastLinkJS / scalaJSLinkerConfig ~= { _.withModuleKind(ModuleKind.ESModule) },
Compile / fullLinkJS / scalaJSLinkerConfig ~= { _.withModuleKind(ModuleKind.CommonJSModule) },
scalaJSLinkerConfig ~= { _.withESFeatures(_.withESVersion(ESVersion.ES5_1)) },
Compile / scalaJSLinkerConfig ~= { _.withSourceMap(true) },
scalaJSUseMainModuleInitializer := true,
// scalaJSLinkerConfig ~= (_.withModuleSplitStyle(org.scalajs.linker.interface.ModuleSplitStyle.FewestModules)),
libraryDependencies ++= Seq.concat(
Dependencies.calico.value,
Dependencies.`embedded-files-macro`.value,
Dependencies.sourcecode.value
),
embedTextGlobs := Seq("**/*.md"),
embedDirectories ++= (Compile / unmanagedSourceDirectories).value,
embedTransform := Seq(
TransformConfig(
when = _.getFileName.toString.endsWith(".md"),
transform = { s =>
templateVars(renderer.render(parser.parse(s)))
.replace(
"""<a href="/""",
s"""<a href="${thisVersionSitePrefix}"""
)
}
)
),
(Compile / sourceGenerators) += embedFiles
)
.dependsOn(
frontroute
)
lazy val noPublish = Seq(
publishLocal / skip := true,
publish / skip := true,
publishTo := Some(Resolver.file("Unused transient repository", file("target/unusedrepo")))
)
lazy val root = project
.in(file("."))
.settings(noPublish)
.settings(
name := "frontroute-root"
)
.aggregate(
frontroute
)