Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add chrome to CI matrix #2150

Merged
merged 11 commits into from
Jul 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- [email protected]
- [email protected]
- [email protected]
ci: [ciJVM, ciJS, ciFirefox]
ci: [ciJVM, ciJS, ciFirefox, ciChrome]
exclude:
- ci: ciJS
java: [email protected]
Expand All @@ -54,6 +54,18 @@ jobs:
scala: 2.12.14
- os: windows-latest
ci: ciFirefox
- ci: ciChrome
java: [email protected]
- ci: ciChrome
java: [email protected]
- ci: ciChrome
java: [email protected]
- os: windows-latest
scala: 3.0.1
- os: windows-latest
scala: 2.12.14
- os: windows-latest
ci: ciChrome
- java: [email protected]
os: windows-latest
runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -93,22 +105,22 @@ jobs:

- name: Check that workflows are up to date
shell: bash
run: sbt --client '++${{ matrix.scala }}; githubWorkflowCheck'
run: sbt ++${{ matrix.scala }} githubWorkflowCheck

- shell: bash
run: sbt --client '++${{ matrix.scala }}; ${{ matrix.ci }}'
run: sbt ++${{ matrix.scala }} '${{ matrix.ci }}'

- if: (matrix.scala == '2.13.6' || matrix.scala == '3.0.1') && matrix.ci == 'ciJVM'
shell: bash
run: sbt --client '++${{ matrix.scala }}; docs/mdoc'
run: sbt ++${{ matrix.scala }} docs/mdoc

- if: matrix.ci == 'ciJVM' && matrix.os == 'ubuntu-latest'
shell: bash
run: sbt --client '++${{ matrix.scala }}; exampleJVM/compile'
run: sbt ++${{ matrix.scala }} exampleJVM/compile

- if: matrix.ci == 'ciJS' && matrix.os == 'ubuntu-latest'
shell: bash
run: sbt --client '++${{ matrix.scala }}; exampleJS/compile'
run: sbt ++${{ matrix.scala }} exampleJS/compile

- name: Test Example JVM App Within Sbt
if: matrix.ci == 'ciJVM' && matrix.os == 'ubuntu-latest'
Expand Down
64 changes: 45 additions & 19 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,20 @@
*/

import java.io.File
import java.util.concurrent.TimeUnit

import com.typesafe.tools.mima.core._
import org.openqa.selenium.WebDriver
import org.openqa.selenium.remote.server.DriverFactory
import org.openqa.selenium.remote.server.DriverProvider
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.scalajs.jsenv.selenium.SeleniumJSEnv

import JSEnv._

ThisBuild / baseVersion := "3.2"

ThisBuild / organization := "org.typelevel"
Expand Down Expand Up @@ -51,6 +59,7 @@ val Scala3 = "3.0.1"

ThisBuild / crossScalaVersions := Seq(Scala3, "2.12.14", Scala213)

ThisBuild / githubWorkflowUseSbtThinClient := false
ThisBuild / githubWorkflowTargetBranches := Seq("series/3.x")

val LTSJava = "[email protected]"
Expand Down Expand Up @@ -97,7 +106,8 @@ ThisBuild / githubWorkflowBuild := Seq(
)
)

val ciVariants = List("ciJVM", "ciJS", "ciFirefox")
val ciVariants = List("ciJVM", "ciJS", "ciFirefox", "ciChrome")
val jsCiVariants = ciVariants.tail
ThisBuild / githubWorkflowBuildMatrixAdditions += "ci" -> ciVariants

ThisBuild / githubWorkflowBuildMatrixExclusions ++= {
Expand All @@ -106,7 +116,7 @@ ThisBuild / githubWorkflowBuildMatrixExclusions ++= {
MatrixExclude(Map("os" -> Windows, "scala" -> scala))
}

Seq("ciJS", "ciFirefox").flatMap { ci =>
jsCiVariants.flatMap { ci =>
val javaFilters =
(ThisBuild / githubWorkflowJavaVersions).value.filterNot(Set(ScalaJSJava)).map { java =>
MatrixExclude(Map("ci" -> ci, "java" -> java))
Expand All @@ -122,22 +132,38 @@ ThisBuild / githubWorkflowBuildMatrixExclusions ++= Seq(

lazy val unidoc213 = taskKey[Seq[File]]("Run unidoc but only on Scala 2.13")

lazy val useFirefoxEnv =
settingKey[Boolean]("Use headless Firefox (via geckodriver) for running tests")
Global / useFirefoxEnv := false
lazy val useJSEnv =
settingKey[JSEnv]("Use Node.js or a headless browser for running Scala.js tests")
Global / useJSEnv := NodeJS

ThisBuild / Test / jsEnv := {
val old = (Test / jsEnv).value

if (useFirefoxEnv.value) {
val profile = new FirefoxProfile()
profile.setPreference("privacy.file_unique_origin", false)
val options = new FirefoxOptions()
options.setProfile(profile)
options.addArguments("-headless")
new SeleniumJSEnv(options)
} else {
old
useJSEnv.value match {
case NodeJS => old
case Firefox =>
val profile = new FirefoxProfile()
profile.setPreference("privacy.file_unique_origin", false)
vasilmkd marked this conversation as resolved.
Show resolved Hide resolved
val options = new FirefoxOptions()
options.setProfile(profile)
options.addArguments("-headless")
new SeleniumJSEnv(options)
case Chrome =>
val options = new ChromeOptions()
options.setHeadless(true)
options.addArguments("--allow-file-access-from-files")
vasilmkd marked this conversation as resolved.
Show resolved Hide resolved
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))
}
}

Expand Down Expand Up @@ -168,11 +194,11 @@ addCommandAlias(
"; project rootJVM; headerCheck; scalafmtCheck; clean; test; mimaReportBinaryIssues; root/unidoc213")
addCommandAlias("ciJS", "; project rootJS; headerCheck; scalafmtCheck; clean; test")

// we do the firefox ci *only* on core because we're only really interested in IO here
addCommandAlias(
"ciFirefox",
"; set Global / useFirefoxEnv := true; project rootJS; headerCheck; scalafmtCheck; clean; testsJS/test; webWorkerTests/test; set Global / useFirefoxEnv := false"
)
// we do the browser ci *only* on core because we're only really interested in IO here
def browserCiCommand(browser: JSEnv) =
s"; set Global / useJSEnv := JSEnv.$browser; project rootJS; headerCheck; scalafmtCheck; clean; testsJS/test; webWorkerTests/test; set Global / useJSEnv := JSEnv.NodeJS"
addCommandAlias("ciFirefox", browserCiCommand(Firefox))
addCommandAlias("ciChrome", browserCiCommand(Chrome))

addCommandAlias("prePR", "; root/clean; scalafmtSbt; +root/scalafmtAll; +root/headerCreate")

Expand Down
6 changes: 6 additions & 0 deletions project/JSEnv.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
sealed abstract class JSEnv
object JSEnv {
case object Chrome extends JSEnv
case object Firefox extends JSEnv
case object NodeJS extends JSEnv
}