Skip to content

Commit 4f6a7e8

Browse files
Introduce JaCoCo (#20)
* Initial introduction of JaCoCo.
1 parent d8cfae9 commit 4f6a7e8

File tree

4 files changed

+77
-3
lines changed

4 files changed

+77
-3
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: CI check JaCoCo code-coverage
2+
3+
on:
4+
pull_request:
5+
branches: [ main ]
6+
7+
jobs:
8+
code_coverage:
9+
name: CI check JaCoCo code-coverage
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout code
13+
uses: actions/[email protected]
14+
- name: Setup Scala
15+
uses: olafurpg/setup-scala@v14
16+
with:
17+
java-version: "[email protected]"
18+
- name: Build, run tests, and generate Jacoco code coverage report
19+
run: sbt ++2.12.18 jacoco
20+
- name: Add coverage to PR
21+
id: jacoco
22+
uses: madrapps/[email protected]
23+
with:
24+
paths: >
25+
${{ github.workspace }}/target/scala-2.12/jacoco/report/jacoco.xml
26+
token: ${{ secrets.GITHUB_TOKEN }}
27+
min-coverage-overall: 0.0
28+
min-coverage-changed-files: 80.0
29+
title: JaCoCo code coverage report - springdoc-openapi-scala
30+
update-comment: true
31+
debug-mode: true
32+
- name: Get the Coverage info
33+
run: |
34+
echo "Total coverage ${{ steps.jacoco.outputs.coverage-overall }}"
35+
echo "Changed Files coverage ${{ steps.jacoco.outputs.coverage-changed-files }}"
36+
- name: Fail PR if changed files coverage is less than 80%
37+
if: ${{ steps.jacoco.outputs.coverage-changed-files < 80.0 }}
38+
uses: actions/[email protected]
39+
with:
40+
script: |
41+
core.setFailed('Changed files coverage is less than 80%!')

.github/workflows/ci_tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ jobs:
3030
name: Scala ${{matrix.scala}}
3131
steps:
3232
- name: Checkout code
33-
uses: actions/checkout@v4
33+
uses: actions/checkout@v4.1.1
3434
- uses: coursier/cache-action@v6
3535
- name: Setup Scala
36-
uses: olafurpg/setup-scala@v11
36+
uses: olafurpg/setup-scala@v14
3737
with:
3838
java-version: "[email protected]"
3939
- name: Build and run tests

build.sbt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,29 @@
1515
*/
1616

1717
import Dependencies._
18+
import com.github.sbt.jacoco.report.JacocoReportSettings
1819

1920
ThisBuild / organization := "za.co.absa"
2021
ThisBuild / scalaVersion := Versions.scala212
2122
ThisBuild / versionScheme := Some("early-semver")
2223

2324
lazy val supportedScalaVersions = List(Versions.scala212, Versions.scala213)
2425

26+
lazy val commonJacocoReportSettings: JacocoReportSettings = JacocoReportSettings(
27+
formats = Seq(JacocoReportFormats.HTML, JacocoReportFormats.XML)
28+
)
29+
30+
lazy val commonJacocoExcludes: Seq[String] = Seq(
31+
// "za.co.absa.springdocopenapiscala.*"
32+
)
33+
2534
lazy val root = (project in file("."))
2635
.settings(
2736
name := "springdoc-openapi-scala",
2837
libraryDependencies ++= libraryDependencyList(scalaVersion.value),
29-
crossScalaVersions := supportedScalaVersions
38+
crossScalaVersions := supportedScalaVersions,
39+
jacocoReportSettings := commonJacocoReportSettings.withTitle(s"SpringDoc OpenApi - scala:${scalaVersion.value}"),
40+
jacocoExcludes := commonJacocoExcludes
3041
)
3142

3243
lazy val simpleExample = (project in file("examples/simple"))

project/plugins.sbt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,25 @@
1616

1717
addSbtPlugin("org.jetbrains.scala" % "sbt-ide-settings" % "1.1.1")
1818
addSbtPlugin("com.earldouglas" % "xsbt-web-plugin" % "4.2.4")
19+
20+
// sbt-jacoco - workaround related dependencies required to download
21+
lazy val ow2Version = "9.5"
22+
lazy val jacocoVersion = "0.8.11-absa.1"
23+
val sbtJacocoVersion = "3.4.1-absa.4"
24+
val scalaArmVersion = "2.0"
25+
26+
def jacocoUrl(artifactName: String): String = s"https://github.com/AbsaOSS/jacoco/releases/download/$jacocoVersion/org.jacoco.$artifactName-$jacocoVersion.jar"
27+
def ow2Url(artifactName: String): String = s"https://repo1.maven.org/maven2/org/ow2/asm/$artifactName/$ow2Version/$artifactName-$ow2Version.jar"
28+
def armUrl(scalaMajor: String): String = s"https://repo1.maven.org/maven2/com/jsuereth/scala-arm_$scalaMajor/$scalaArmVersion/scala-arm_$scalaMajor-$scalaArmVersion.jar"
29+
30+
addSbtPlugin("com.jsuereth" %% "scala-arm" % scalaArmVersion from armUrl("2.11"))
31+
addSbtPlugin("com.jsuereth" %% "scala-arm" % scalaArmVersion from armUrl("2.12"))
32+
33+
addSbtPlugin("za.co.absa.jacoco" % "report" % jacocoVersion from jacocoUrl("report"))
34+
addSbtPlugin("za.co.absa.jacoco" % "core" % jacocoVersion from jacocoUrl("core"))
35+
addSbtPlugin("za.co.absa.jacoco" % "agent" % jacocoVersion from jacocoUrl("agent"))
36+
addSbtPlugin("org.ow2.asm" % "asm" % ow2Version from ow2Url("asm"))
37+
addSbtPlugin("org.ow2.asm" % "asm-commons" % ow2Version from ow2Url("asm-commons"))
38+
addSbtPlugin("org.ow2.asm" % "asm-tree" % ow2Version from ow2Url("asm-tree"))
39+
40+
addSbtPlugin("za.co.absa.sbt" % "sbt-jacoco" % sbtJacocoVersion from s"https://github.com/AbsaOSS/sbt-jacoco/releases/download/$sbtJacocoVersion/sbt-jacoco-$sbtJacocoVersion.jar")

0 commit comments

Comments
 (0)