Skip to content

Commit 75f10ef

Browse files
#35 - Add code coverage support improve (#39)
- Added support for code coverage GitHub action check as part of PR. - Used Absa fork of JaCoCo solution - with scala method filtering.
1 parent 5191a22 commit 75f10ef

File tree

4 files changed

+97
-4
lines changed

4 files changed

+97
-4
lines changed

.github/workflows/jacoco_check.yml

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

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ import za.co.absa.spark.hats.Extensions._
4141
```
4242

4343
### How to generate Code coverage report
44-
```sbt
45-
sbt jacoco
44+
```
45+
sbt ++{matrix.scala} jacoco -DSPARK_VERSION={matrix.spark}
4646
```
4747
Code coverage will be generated on path:
4848
```

project/build.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
# limitations under the License.
1414
#
1515

16-
sbt.version=1.4.5
16+
sbt.version=1.6.2

project/plugins.sbt

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,22 @@
1717
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "2.0.0")
1818
addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.12")
1919
addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.6.0")
20-
addSbtPlugin("com.github.sbt" % "sbt-jacoco" % "3.4.0")
2120

21+
// sbt-jacoco - workaround related dependencies required to download
22+
lazy val ow2Version = "9.5"
23+
lazy val jacocoVersion = "0.8.9-absa.1"
24+
25+
def jacocoUrl(artifactName: String): String = s"https://github.com/AbsaOSS/jacoco/releases/download/$jacocoVersion/org.jacoco.$artifactName-$jacocoVersion.jar"
26+
def ow2Url(artifactName: String): String = s"https://repo1.maven.org/maven2/org/ow2/asm/$artifactName/$ow2Version/$artifactName-$ow2Version.jar"
27+
28+
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")
29+
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")
30+
31+
addSbtPlugin("za.co.absa.jacoco" % "report" % jacocoVersion from jacocoUrl("report"))
32+
addSbtPlugin("za.co.absa.jacoco" % "core" % jacocoVersion from jacocoUrl("core"))
33+
addSbtPlugin("za.co.absa.jacoco" % "agent" % jacocoVersion from jacocoUrl("agent"))
34+
addSbtPlugin("org.ow2.asm" % "asm" % ow2Version from ow2Url("asm"))
35+
addSbtPlugin("org.ow2.asm" % "asm-commons" % ow2Version from ow2Url("asm-commons"))
36+
addSbtPlugin("org.ow2.asm" % "asm-tree" % ow2Version from ow2Url("asm-tree"))
37+
38+
addSbtPlugin("za.co.absa.sbt" % "sbt-jacoco" % "3.4.1-absa.2" from "https://github.com/AbsaOSS/sbt-jacoco/releases/download/3.4.1-absa.2/sbt-jacoco-3.4.1-absa.2.jar")

0 commit comments

Comments
 (0)