From fb61b663c6255e7752c0e48217160790401f7e24 Mon Sep 17 00:00:00 2001 From: miroslavpojer <109138042+miroslavpojer@users.noreply.github.com> Date: Thu, 20 Apr 2023 09:30:42 +0200 Subject: [PATCH] #602 - Add GitHub action for code-coverage check (#603) * #602 - Add GitHub action for code-coverage check - Update of plugins file to support current Absa-JaCoCo workaround. - New yml file for server side check. --- .github/workflows/jacoco_check.yml | 75 ++++++++++++++++++++++++++++++ build.sbt | 9 ++-- project/plugins.sbt | 20 +++++++- 3 files changed, 99 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/jacoco_check.yml diff --git a/.github/workflows/jacoco_check.yml b/.github/workflows/jacoco_check.yml new file mode 100644 index 00000000..4206009c --- /dev/null +++ b/.github/workflows/jacoco_check.yml @@ -0,0 +1,75 @@ +# +# Copyright 2022 ABSA Group Limited +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +name: JaCoCo report + +on: + pull_request: + branches: [ master ] + types: [ opened, edited, synchronize, reopened ] + +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + include: + - scala: 2.11.12 + scalaShort: "2.11" + spark: 2.4.8 + overall: 0.0 + changed: 80.0 + - scala: 2.12.17 + scalaShort: "2.12" + spark: 3.2.3 + overall: 0.0 + changed: 80.0 + - scala: 2.13.10 + scalaShort: "2.13" + spark: 3.3.2 + overall: 0.0 + changed: 80.0 + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Setup Scala + uses: olafurpg/setup-scala@v10 + with: + java-version: "adopt@1.8" + - name: Build and run tests + run: sbt ++${{matrix.scala}} jacoco -DSPARK_VERSION=${{matrix.spark}} + - name: Add coverage to PR + id: jacoco + uses: madrapps/jacoco-report@v1.3 + with: + paths: > + ${{ github.workspace }}/cobol-parser/target/scala-${{ matrix.scalaShort }}/jacoco/report/jacoco.xml, + ${{ github.workspace }}/spark-cobol/target/scala-${{ matrix.scalaShort }}/jacoco/report/jacoco.xml + token: ${{ secrets.GITHUB_TOKEN }} + min-coverage-overall: ${{ matrix.overall }} + min-coverage-changed-files: ${{ matrix.changed }} + title: JaCoCo code coverage report - scala ${{ matrix.scala }} - spark ${{ matrix.spark }} + update-comment: true + - name: Get the Coverage info + run: | + echo "Total coverage ${{ steps.jacoco.outputs.coverage-overall }}" + echo "Changed Files coverage ${{ steps.jacoco.outputs.coverage-changed-files }}" + - name: Fail PR if changed files coverage is less than ${{ matrix.changed }}% + if: ${{ steps.jacoco.outputs.coverage-changed-files < 80.0 }} + uses: actions/github-script@v6 + with: + script: | + core.setFailed('Changed files coverage is less than ${{ matrix.changed }}%!') diff --git a/build.sbt b/build.sbt index a2f487cd..c4e407c6 100644 --- a/build.sbt +++ b/build.sbt @@ -80,10 +80,12 @@ lazy val cobolConverters = (project in file("cobol-converters")) // No need to publish this artifact since it has test only at the moment publishArtifact := false, publish := {}, - publishLocal := {}, + publishLocal := {} + ).dependsOn(cobolParser) + .settings( jacocoReportSettings := commonJacocoReportSettings.withTitle("cobrix:cobol-converters Jacoco Report"), jacocoExcludes := commonJacocoExcludes - ).dependsOn(cobolParser) + ) .enablePlugins(AutomateHeaderPlugin) lazy val sparkCobol = (project in file("spark-cobol")) @@ -101,12 +103,11 @@ lazy val sparkCobol = (project in file("spark-cobol")) populateBuildInfoTemplate, releasePublishArtifactsAction := PgpKeys.publishSigned.value, assemblySettings - ) + ).dependsOn(cobolParser) .settings( jacocoReportSettings := commonJacocoReportSettings.withTitle("cobrix:spark-cobol Jacoco Report"), jacocoExcludes := commonJacocoExcludes ) - .dependsOn(cobolParser) .enablePlugins(AutomateHeaderPlugin) // scoverage settings diff --git a/project/plugins.sbt b/project/plugins.sbt index 84507c2d..66d55f90 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -3,4 +3,22 @@ addSbtPlugin("com.github.sbt" % "sbt-release" % "1.1.0") addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.6.0") addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.2.0") addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.15.0") -addSbtPlugin("com.github.sbt" % "sbt-jacoco" % "3.4.0") + +// sbt-jacoco - workaround related dependencies required to download +lazy val ow2Version = "9.5" +lazy val jacocoVersion = "0.8.9-absa.1" + +def jacocoUrl(artifactName: String): String = s"https://github.com/AbsaOSS/jacoco/releases/download/$jacocoVersion/org.jacoco.$artifactName-$jacocoVersion.jar" +def ow2Url(artifactName: String): String = s"https://repo1.maven.org/maven2/org/ow2/asm/$artifactName/$ow2Version/$artifactName-$ow2Version.jar" + +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") +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") + +addSbtPlugin("za.co.absa.jacoco" % "report" % jacocoVersion from jacocoUrl("report")) +addSbtPlugin("za.co.absa.jacoco" % "core" % jacocoVersion from jacocoUrl("core")) +addSbtPlugin("za.co.absa.jacoco" % "agent" % jacocoVersion from jacocoUrl("agent")) +addSbtPlugin("org.ow2.asm" % "asm" % ow2Version from ow2Url("asm")) +addSbtPlugin("org.ow2.asm" % "asm-commons" % ow2Version from ow2Url("asm-commons")) +addSbtPlugin("org.ow2.asm" % "asm-tree" % ow2Version from ow2Url("asm-tree")) + +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")