Skip to content

Commit 9609081

Browse files
#153 - Add code coverage support improve (#154)
* #153 - Add code coverage support improve - Used Absa fork of JaCoCo solution - with scala method filtering. - Added support for code coverage GitHub action check as part of PR.
1 parent 1be976b commit 9609081

File tree

3 files changed

+101
-5
lines changed

3 files changed

+101
-5
lines changed

.github/workflows/jacoco_check.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#
2+
# Copyright 2022 ABSA Group Limited
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
17+
name: JaCoCo report
18+
19+
on:
20+
pull_request:
21+
branches: [ master ]
22+
types: [ opened, edited, synchronize, reopened ]
23+
24+
jobs:
25+
test:
26+
runs-on: ubuntu-latest
27+
strategy:
28+
matrix:
29+
include:
30+
- scala: 2.11.12
31+
scala_short: 2.11
32+
spark: 2.4.8
33+
overall: 0.0
34+
changed: 80.0
35+
- scala: 2.12.15
36+
scala_short: 2.12
37+
spark: 3.2.2
38+
overall: 0.0
39+
changed: 80.0
40+
steps:
41+
- name: Checkout code
42+
uses: actions/checkout@v2
43+
- name: Setup Scala
44+
uses: olafurpg/setup-scala@v10
45+
with:
46+
java-version: "[email protected]"
47+
- name: Build and run tests
48+
run: sbt ++${{matrix.scala}} jacoco
49+
- name: Add coverage to PR
50+
id: jacoco
51+
uses: madrapps/[email protected]
52+
with:
53+
paths: >
54+
${{ github.workspace }}/atum/target/scala-${{ matrix.scala_short }}/jacoco/report/jacoco.xml,
55+
${{ github.workspace }}/atum-s3-sdk-extension/target/scala-${{ matrix.scala_short }}/jacoco/report/jacoco.xml,
56+
${{ github.workspace }}/model/target/scala-${{ matrix.scala_short }}/jacoco/report/jacoco.xml
57+
token: ${{ secrets.GITHUB_TOKEN }}
58+
min-coverage-overall: ${{ matrix.overall }}
59+
min-coverage-changed-files: ${{ matrix.changed }}
60+
title: JaCoCo code coverage report - scala:${{ matrix.scala }}
61+
update-comment: true
62+
- name: Get the Coverage info
63+
run: |
64+
echo "Total coverage ${{ steps.jacoco.outputs.coverage-overall }}"
65+
echo "Changed Files coverage ${{ steps.jacoco.outputs.coverage-changed-files }}"
66+
- name: Fail PR if changed files coverage is less than ${{ matrix.changed }}%
67+
if: ${{ steps.jacoco.outputs.coverage-changed-files < 80.0 }}
68+
uses: actions/github-script@v6
69+
with:
70+
script: |
71+
core.setFailed('Changed files coverage is less than ${{ matrix.changed }}%!')

build.sbt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ lazy val model = project // no need to define file, because path is same as val
6464
mergeStrategy
6565
)
6666
.settings(
67-
jacocoReportSettings := commonJacocoReportSettings.withTitle("atum:model Jacoco Report"),
67+
jacocoReportSettings := commonJacocoReportSettings.withTitle(s"atum:model Jacoco Report - scala:${scalaVersion.value}"),
6868
jacocoExcludes := commonJacocoExcludes ++ Seq(
69-
// "za.co.absa.atum.core.ControlFrameworkState" // extra exclude example
69+
"za.co.absa.atum.core.ControlFrameworkState" // extra exclude example
7070
)
7171
)
7272

@@ -80,7 +80,7 @@ lazy val core = (project in file("atum"))
8080
populateBuildInfoTemplate // to get correct replacements for ${project.artifactId} and ${project.version} in atum_build.properties,
8181
)
8282
.settings(
83-
jacocoReportSettings := commonJacocoReportSettings.withTitle("atum:core Jacoco Report"),
83+
jacocoReportSettings := commonJacocoReportSettings.withTitle(s"atum:core Jacoco Report - scala:${scalaVersion.value}"),
8484
jacocoExcludes := commonJacocoExcludes
8585
)
8686
.dependsOn(model)
@@ -95,7 +95,7 @@ lazy val s3sdkExtension = (project in file("atum-s3-sdk-extension"))
9595
mergeStrategy
9696
)
9797
.settings(
98-
jacocoReportSettings := commonJacocoReportSettings.withTitle("atum:s3sdkExtension Jacoco Report"),
98+
jacocoReportSettings := commonJacocoReportSettings.withTitle(s"atum:s3sdkExtension Jacoco Report - scala:${scalaVersion.value}"),
9999
jacocoExcludes := commonJacocoExcludes
100100
)
101101
.dependsOn(core)
@@ -109,6 +109,10 @@ lazy val examples = (project in file("examples"))
109109
(Compile / compile) := ((Compile / compile) dependsOn printSparkScalaVersion).value, // printSparkScalaVersion is run with compile
110110
mergeStrategy
111111
)
112+
.settings(
113+
jacocoReportSettings := commonJacocoReportSettings.withTitle(s"atum:examples Jacoco Report - scala:${scalaVersion.value}"),
114+
jacocoExcludes := commonJacocoExcludes
115+
)
112116
.dependsOn(core)
113117

114118
lazy val s3sdkExamples = (project in file("examples-s3-sdk-extension"))
@@ -120,6 +124,10 @@ lazy val s3sdkExamples = (project in file("examples-s3-sdk-extension"))
120124
(Compile / compile) := ((Compile / compile) dependsOn printSparkScalaVersion).value, // printSparkScalaVersion is run with compile
121125
mergeStrategy,
122126
)
127+
.settings(
128+
jacocoReportSettings := commonJacocoReportSettings.withTitle(s"atum:s3sdkExamples Jacoco Report - scala:${scalaVersion.value}"),
129+
jacocoExcludes := commonJacocoExcludes
130+
)
123131
.dependsOn(s3sdkExtension, examples)
124132

125133
val mergeStrategy: Def.SettingsDefinition = assembly / assemblyMergeStrategy := {

project/plugins.sbt

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,23 @@ addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.6.0")
1919

2020
addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.1.2") // formerly known as com.jsuereth:sbt-pgp
2121

22-
addSbtPlugin("com.github.sbt" % "sbt-jacoco" % "3.4.0")
22+
// sbt-jacoco - workaround related dependencies required to download
23+
lazy val ow2Version = "9.5"
24+
lazy val jacocoVersion = "0.8.10-absa.1"
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+
29+
addSbtPlugin("com.jsuereth" %% "scala-arm" % "2.0" from "https://repo1.maven.org/maven2/com/jsuereth/scala-arm_2.11/2.0/scala-arm_2.11-2.0.jar")
30+
addSbtPlugin("com.jsuereth" %% "scala-arm" % "2.0" from "https://repo1.maven.org/maven2/com/jsuereth/scala-arm_2.12/2.0/scala-arm_2.12-2.0.jar")
31+
32+
addSbtPlugin("za.co.absa.jacoco" % "report" % jacocoVersion from jacocoUrl("report"))
33+
addSbtPlugin("za.co.absa.jacoco" % "core" % jacocoVersion from jacocoUrl("core"))
34+
addSbtPlugin("za.co.absa.jacoco" % "agent" % jacocoVersion from jacocoUrl("agent"))
35+
addSbtPlugin("org.ow2.asm" % "asm" % ow2Version from ow2Url("asm"))
36+
addSbtPlugin("org.ow2.asm" % "asm-commons" % ow2Version from ow2Url("asm-commons"))
37+
addSbtPlugin("org.ow2.asm" % "asm-tree" % ow2Version from ow2Url("asm-tree"))
38+
39+
addSbtPlugin("za.co.absa.sbt" % "sbt-jacoco" % "3.4.1-absa.3" from "https://github.com/AbsaOSS/sbt-jacoco/releases/download/3.4.1-absa.3/sbt-jacoco-3.4.1-absa.3.jar")
2340

2441
addDependencyTreePlugin

0 commit comments

Comments
 (0)