Skip to content

Commit 21499a5

Browse files
authored
Merge pull request #34 from buntec/topic/coverage
Setup scoverage
2 parents dc802bb + 6bccc7e commit 21499a5

File tree

9 files changed

+1133
-1
lines changed

9 files changed

+1133
-1
lines changed

.github/workflows/ci.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,3 +181,49 @@ jobs:
181181
182182
- name: Publish
183183
run: sbt '++${{ matrix.scala }}' tlRelease
184+
185+
coverage:
186+
name: Generate coverage report
187+
strategy:
188+
matrix:
189+
os: [ubuntu-latest]
190+
scala: [2.13.8]
191+
java: [temurin@8]
192+
runs-on: ${{ matrix.os }}
193+
steps:
194+
- name: Checkout current branch (fast)
195+
uses: actions/checkout@v2
196+
197+
- name: Download Java (temurin@8)
198+
id: download-java-temurin-8
199+
if: matrix.java == 'temurin@8'
200+
uses: typelevel/download-java@v1
201+
with:
202+
distribution: temurin
203+
java-version: 8
204+
205+
- name: Setup Java (temurin@8)
206+
if: matrix.java == 'temurin@8'
207+
uses: actions/setup-java@v2
208+
with:
209+
distribution: jdkfile
210+
java-version: 8
211+
jdkFile: ${{ steps.download-java-temurin-8.outputs.jdkFile }}
212+
213+
- name: Cache sbt
214+
uses: actions/cache@v2
215+
with:
216+
path: |
217+
~/.sbt
218+
~/.ivy2/cache
219+
~/.coursier/cache/v1
220+
~/.cache/coursier/v1
221+
~/AppData/Local/Coursier/Cache/v1
222+
~/Library/Caches/Coursier/v1
223+
key: ${{ runner.os }}-sbt-cache-v2-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }}
224+
225+
- run: npm install
226+
227+
- run: 'sbt ''++${{ matrix.scala }}'' ''set Global / useJSEnv := JSEnv.JSDOM'' coverage test coverageAggregate'
228+
229+
- run: 'bash <(curl -s https://codecov.io/bash)'

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ metals.sbt
55
target/
66
.vscode/
77
.DS_Store
8+
node_modules/

build.sbt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,38 @@ ThisBuild / githubWorkflowBuildMatrixAdditions += "browser" -> List(
1818
"Firefox"
1919
)
2020
ThisBuild / githubWorkflowBuildSbtStepPreamble += s"set Global / useJSEnv := JSEnv.$${{ matrix.browser }}"
21+
22+
ThisBuild / coverageScalacPluginVersion := "2.0.0-M6"
23+
ThisBuild / githubWorkflowAddedJobs +=
24+
WorkflowJob(
25+
id = "coverage",
26+
name = "Generate coverage report",
27+
scalas = List(scala213),
28+
javas = githubWorkflowJavaVersions.value.toList,
29+
steps = List(WorkflowStep.Checkout)
30+
++ WorkflowStep.SetupJava(githubWorkflowJavaVersions.value.toList)
31+
++ githubWorkflowGeneratedCacheSteps.value
32+
++ List(
33+
WorkflowStep.Run(List("npm install")),
34+
WorkflowStep.Sbt(
35+
List(
36+
"set Global / useJSEnv := JSEnv.JSDOM",
37+
"coverage",
38+
"test",
39+
"coverageAggregate"
40+
)
41+
),
42+
WorkflowStep.Run(List("bash <(curl -s https://codecov.io/bash)"))
43+
)
44+
)
45+
2146
lazy val useJSEnv = settingKey[JSEnv]("Browser for running Scala.js tests")
2247
Global / useJSEnv := JSEnv.Chrome
2348
ThisBuild / Test / jsEnv := {
2449
import org.openqa.selenium.chrome.ChromeOptions
2550
import org.openqa.selenium.firefox.FirefoxOptions
2651
import org.scalajs.jsenv.selenium.SeleniumJSEnv
52+
import org.scalajs.jsenv.jsdomnodejs.JSDOMNodeJSEnv
2753
useJSEnv.value match {
2854
case JSEnv.Chrome =>
2955
val options = new ChromeOptions()
@@ -33,6 +59,8 @@ ThisBuild / Test / jsEnv := {
3359
val options = new FirefoxOptions()
3460
options.setHeadless(true)
3561
new SeleniumJSEnv(options)
62+
case JSEnv.JSDOM =>
63+
new JSDOMNodeJSEnv()
3664
}
3765
}
3866

0 commit comments

Comments
 (0)