diff --git a/.circleci/config.yml b/.circleci/config.yml index a749b8639..1aa7f37f3 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -272,6 +272,12 @@ jobs: scala: "2.12" jdk: "11" use_jdk11: "true" + - run: + name: Move Jacoco results to unique folder + command: | + UNIQUE_ID="${CIRCLE_WORKFLOW_ID}-${CIRCLE_JOB}-${CIRCLE_NODE_INDEX}" + echo "Unique ID: $UNIQUE_ID" + ./scripts/get-jacoco-results.sh "jacoco-results/${UNIQUE_ID}" - store_artifacts: path: build/test-reports @@ -284,6 +290,11 @@ jobs: - store_test_results: path: build/test-reports + - persist_to_workspace: + root: ./jacoco-results + paths: + - "**/*" + int-spark3-2_12-jdk11: parallelism: 8 docker: @@ -300,6 +311,12 @@ jobs: scala: "2.12" jdk: "11" use_jdk11: "true" + - run: + name: Move Jacoco results to unique folder + command: | + UNIQUE_ID="${CIRCLE_WORKFLOW_ID}-${CIRCLE_JOB}-${CIRCLE_NODE_INDEX}" + echo "Unique ID: $UNIQUE_ID" + ./scripts/get-jacoco-results.sh "jacoco-results/${UNIQUE_ID}" - store_artifacts: path: build/test-reports @@ -316,6 +333,11 @@ jobs: - store_test_results: path: build/test-reports + - persist_to_workspace: + root: ./jacoco-results + paths: + - "**/*" + spark3-2_13-jdk11: docker: - image: cimg/openjdk:11.0 @@ -330,6 +352,12 @@ jobs: scala: "2.13" jdk: "11" use_jdk11: "true" + - run: + name: Move Jacoco results to unique folder + command: | + UNIQUE_ID="${CIRCLE_WORKFLOW_ID}-${CIRCLE_JOB}-${CIRCLE_NODE_INDEX}" + echo "Unique ID: $UNIQUE_ID" + ./scripts/get-jacoco-results.sh "jacoco-results/${UNIQUE_ID}" - store_artifacts: path: build/test-reports @@ -342,6 +370,11 @@ jobs: - store_test_results: path: build/test-reports + - persist_to_workspace: + root: ./jacoco-results + paths: + - "**/*" + int-spark3-2_13-jdk11: parallelism: 8 docker: @@ -358,6 +391,12 @@ jobs: scala: "2.13" jdk: "11" use_jdk11: "true" + - run: + name: Move Jacoco results to unique folder + command: | + UNIQUE_ID="${CIRCLE_WORKFLOW_ID}-${CIRCLE_JOB}-${CIRCLE_NODE_INDEX}" + echo "Unique ID: $UNIQUE_ID" + ./scripts/get-jacoco-results.sh "jacoco-results/${UNIQUE_ID}" - store_artifacts: path: build/test-reports @@ -370,6 +409,22 @@ jobs: - store_test_results: path: build/test-reports + - persist_to_workspace: + root: ./jacoco-results + paths: + - "**/*" + + # Delta coverage plugin requires java 11 so we only validate in java 11 builds + validate_delta_coverage: + docker: + - image: cimg/openjdk:11.0 + steps: + - install_common + - checkout + - attach_workspace: + at: jacoco-results + - run: ./gradlew --info deltaCoverage + workflows: version: 2 build-and-test: @@ -400,3 +455,9 @@ workflows: - int-spark3-2_13-jdk11: requires: - build-deps-jdk11 + - validate_delta_coverage: + requires: + - spark3-2_12-jdk11 + - spark3-2_13-jdk11 + - int-spark3-2_12-jdk11 + - int-spark3-2_13-jdk11 \ No newline at end of file diff --git a/CHANGES.txt b/CHANGES.txt index 557f8280a..14a814995 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,5 @@ 1.0.0 + * Integrate delta-coverage-plugin plugin (CASSANALYTICS-1) * CEP-44 Kafka integration for Cassandra CDC using Sidecar (CASSANDRA-19962) * Expose detailed bulk write failure message for better insight (CASSANDRA-20066) * Add dataTransferApi and TwoPhaseImportCoordinator for coordinated write (CASSANDRA-19994) diff --git a/build.gradle b/build.gradle index d5bc95cac..d7b3f6415 100644 --- a/build.gradle +++ b/build.gradle @@ -29,6 +29,8 @@ plugins { // Release Audit Tool (RAT) plugin for checking project licenses id("org.nosphere.apache.rat") version "0.8.1" + id("io.github.surpsg.delta-coverage") version "2.4.0" + id("jacoco") } repositories { @@ -255,4 +257,27 @@ subprojects { println() println(version) } + + deltaCoverageReport { + diffSource { + git.compareWith("refs/remotes/origin/trunk") + git.useNativeGit.set(true) + } + + coverageBinaryFiles = fileTree(".") { include("**/*.exec") } + + violationRules { + failOnViolation.set(true) + rule(io.github.surpsg.deltacoverage.gradle.CoverageEntity.LINE) { + minCoverageRatio.set(0.9d) + } + rule(io.github.surpsg.deltacoverage.gradle.CoverageEntity.BRANCH) { + minCoverageRatio.set(0.7d) + } + } + + reports { + html.set(true) + } + } } diff --git a/cassandra-analytics-cdc/build.gradle b/cassandra-analytics-cdc/build.gradle index d8b30e522..d94ee22e2 100644 --- a/cassandra-analytics-cdc/build.gradle +++ b/cassandra-analytics-cdc/build.gradle @@ -22,6 +22,7 @@ import java.nio.file.Paths plugins { id('java-library') id('maven-publish') + id('jacoco') } configurations { diff --git a/cassandra-analytics-common/build.gradle b/cassandra-analytics-common/build.gradle index f350e3c5e..3acf278e9 100644 --- a/cassandra-analytics-common/build.gradle +++ b/cassandra-analytics-common/build.gradle @@ -22,6 +22,7 @@ import java.nio.file.Paths plugins { id('java-library') id('maven-publish') + id('jacoco') } java { diff --git a/scripts/get-jacoco-results.sh b/scripts/get-jacoco-results.sh new file mode 100755 index 000000000..8304ddcd7 --- /dev/null +++ b/scripts/get-jacoco-results.sh @@ -0,0 +1,32 @@ +#!/bin/bash +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. +# + +search_dir="." + +target_folder="${1}" + +mkdir -p $target_folder + +find "$search_dir" -type d -path "*/build/jacoco" -print0 | while IFS= read -r -d '' dir; do + destination_path="$target_folder/${dir:2}" + mkdir -p "$destination_path" + cp -r $dir "$destination_path" + echo "Copied folder $dir to $destination_path" +done +