-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathbuild.sbt
188 lines (153 loc) · 7.32 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
/*
* Copyright 2021 Scala.js (https://www.scala-js.org/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.openqa.selenium.WebDriver
import org.openqa.selenium.chrome.{ChromeDriver, ChromeOptions}
import org.openqa.selenium.firefox.{FirefoxOptions, FirefoxProfile}
import org.openqa.selenium.safari.{SafariOptions, SafariDriver}
import org.openqa.selenium.remote.server.{DriverFactory, DriverProvider}
import org.scalajs.jsenv.jsdomnodejs.JSDOMNodeJSEnv
import org.scalajs.jsenv.selenium.SeleniumJSEnv
import java.util.concurrent.TimeUnit
val MUnitFramework = new TestFramework("munit.Framework")
val MUnitVersion = "0.7.29"
ThisBuild / baseVersion := "1.0"
ThisBuild / organization := "org.scala-js"
ThisBuild / organizationName := "Scala.js (https://www.scala-js.org/)"
ThisBuild / developers := List(
Developer("djspiewak", "Daniel Spiewak", "@djspiewak", url("https://github.com/djspiewak")),
Developer("armanbilge", "Arman Bilge", "@armanbilge", url("https://github.com/armanbilge")))
ThisBuild / homepage := Some(url("https://github.com/scala-js/scala-js-macrotask-executor"))
ThisBuild / scmInfo := Some(
ScmInfo(
url("https://github.com/scala-js/scala-js-macrotask-executor"),
"[email protected]:scala-js/scala-js-macrotask-executor.git"))
// build and matrix configuration
ThisBuild / crossScalaVersions := Seq("2.11.12", "2.12.15", "2.13.7", "3.0.2")
val PrimaryOS = "ubuntu-latest"
val MacOS = "macos-latest"
ThisBuild / githubWorkflowOSes := Seq(PrimaryOS, MacOS)
ThisBuild / githubWorkflowBuildPreamble ++= Seq(
WorkflowStep.Use(
UseRef.Public("actions", "setup-node", "v2.1.2"),
name = Some("Setup NodeJS v14 LTS"),
params = Map("node-version" -> "14"),
cond = Some("matrix.ci == 'ciNode' || matrix.ci == 'ciJSDOMNodeJS'")),
WorkflowStep.Run(
List("npm install"),
name = Some("Install jsdom"),
cond = Some("matrix.ci == 'ciJSDOMNodeJS'")))
val ciVariants = List("ciNode", "ciFirefox", "ciChrome", "ciSafari", "ciJSDOMNodeJS")
ThisBuild / githubWorkflowBuildMatrixExclusions += MatrixExclude(Map("ci" -> "ciSafari", "os" -> PrimaryOS))
ThisBuild / githubWorkflowBuildMatrixExclusions ++= ciVariants.filter(_ != "ciSafari")
.map(ci => MatrixExclude(Map("ci" -> ci, "os" -> MacOS)))
ThisBuild / githubWorkflowBuildMatrixAdditions += "ci" -> ciVariants
ThisBuild / githubWorkflowBuild := Seq(WorkflowStep.Sbt(List("${{ matrix.ci }}")))
replaceCommandAlias("ci", ciVariants.mkString("; ", "; ", ""))
addCommandAlias("ciNode", "; set Global / useJSEnv := JSEnv.NodeJS; test; core/doc")
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("ciSafari", "; set Global / useJSEnv := JSEnv.Safari; core / test; set Global / useJSEnv := JSEnv.NodeJS")
addCommandAlias("ciJSDOMNodeJS", "; set Global / useJSEnv := JSEnv.JSDOMNodeJS; test; set Global / useJSEnv := JSEnv.NodeJS")
// release configuration
enablePlugins(SonatypeCiReleasePlugin)
ThisBuild / spiewakMainBranches := Seq("main")
ThisBuild / githubWorkflowArtifactUpload := false
// we can remove this once we have a non-password-protected key in the secrets
ThisBuild / githubWorkflowPublishPreamble := Seq(
WorkflowStep.Run(
List(
"echo \"$PGP_SECRET\" | base64 -d > /tmp/signing-key.gpg",
"echo \"$PGP_PASSPHRASE\" | gpg --pinentry-mode loopback --passphrase-fd 0 --import /tmp/signing-key.gpg"),
name = Some("Import signing key"),
env = Map("PGP_PASSPHRASE" -> "${{ secrets.PGP_PASSPHRASE }}")),
WorkflowStep.Run(
List("(echo \"$PGP_PASSPHRASE\"; echo; echo) | gpg --command-fd 0 --pinentry-mode loopback --change-passphrase 5EBC14B0F6C55083"),
name = Some("Strip passphrase from signing key"),
env = Map("PGP_PASSPHRASE" -> "${{ secrets.PGP_PASSPHRASE }}")))
// environments
lazy val useJSEnv =
settingKey[JSEnv]("Use Node.js or a headless browser for running Scala.js tests")
Global / useJSEnv := JSEnv.NodeJS
def commonSettings(disableSafari: Boolean = false) = Seq(
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))
case Safari if !disableSafari =>
println("DEBUG DEBUG DEBUG DEBUG")
val options = new SafariOptions()
new SeleniumJSEnv(options, SeleniumJSEnv.Config())
case _ => old
}
}
)
ThisBuild / parallelExecution := false
Global / concurrentRestrictions += Tags.limit(Tags.Test, 1)
ThisBuild / Test / testOptions += Tests.Argument(MUnitFramework, "+l")
// project structure
lazy val root = project
.aggregate(core, webworker)
.enablePlugins(NoPublishPlugin)
lazy val core = project
.in(file("core"))
.settings(
name := "scala-js-macrotask-executor",
libraryDependencies += "org.scalameta" %%% "munit" % MUnitVersion % Test,
)
.settings(commonSettings())
.enablePlugins(ScalaJSPlugin)
// this project solely exists for testing purposes
lazy val webworker = project
.in(file("webworker"))
.dependsOn(core % "compile->test")
.settings(
name := "scala-js-macrotask-executor-webworker",
scalaJSUseMainModuleInitializer := true,
libraryDependencies ++= Seq(
"org.scala-js" %%% "scalajs-dom" % "2.0.0",
"org.scalameta" %%% "munit" % MUnitVersion % Test,
),
(Test / test) := (Test / test).dependsOn(Compile / fastOptJS).value,
buildInfoKeys := Seq(scalaVersion, baseDirectory, BuildInfoKey("isBrowser" -> useJSEnv.value.isBrowser)),
buildInfoPackage := "org.scalajs.macrotaskexecutor"
)
.settings(commonSettings(disableSafari = true)) // bugged
.enablePlugins(ScalaJSPlugin, BuildInfoPlugin, NoPublishPlugin)