This is an automated email from the ASF dual-hosted git repository. abhi pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/ranger.git
The following commit(s) were added to refs/heads/master by this push: new 89b7130fc RANGER-5229: CI - Generate Code Coverage Report with JaCoCo (#590) 89b7130fc is described below commit 89b7130fcc99f14a69a87829dd3c758d93e666e1 Author: Abhishek Kumar <abhishekkumar100...@gmail.com> AuthorDate: Fri Jun 20 12:01:41 2025 -0700 RANGER-5229: CI - Generate Code Coverage Report with JaCoCo (#590) --- .github/workflows/{maven.yml => ci.yml} | 12 +++++++ dev-support/checks/coverage.sh | 56 +++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/.github/workflows/maven.yml b/.github/workflows/ci.yml similarity index 95% rename from .github/workflows/maven.yml rename to .github/workflows/ci.yml index 94cc5c32b..34dae302d 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/ci.yml @@ -54,6 +54,18 @@ jobs: distribution: 'temurin' - name: build (8) run: mvn -T 8 clean verify --no-transfer-progress -B -V + + - name: run code coverage + run: | + cd dev-support/checks + chmod +x coverage.sh && ./coverage.sh + + - name: upload coverage results + uses: actions/upload-artifact@v4 + with: + name: jacoco + path: target/coverage/all/* + - name: Upload artifacts uses: actions/upload-artifact@v4 with: diff --git a/dev-support/checks/coverage.sh b/dev-support/checks/coverage.sh new file mode 100755 index 000000000..eabf0a4a3 --- /dev/null +++ b/dev-support/checks/coverage.sh @@ -0,0 +1,56 @@ +#!/usr/bin/env 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. + +# This script merges the jacoco exec files and generates a report in HTML and XML formats + +DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)" +cd "$DIR/../.." || exit 1 + +set -ex + +REPORT_DIR="$DIR/../../target/coverage" + +mkdir -p "$REPORT_DIR" + +JACOCO_VERSION=$(mvn help:evaluate -Dexpression=jacoco.version -q -DforceStdout -Dscan=false) + +# Install jacoco cli +mvn --non-recursive --no-transfer-progress -Dscan=false \ + org.apache.maven.plugins:maven-dependency-plugin:copy \ + -Dartifact=org.jacoco:org.jacoco.cli:${JACOCO_VERSION}:jar:nodeps + +jacoco() { + java -jar target/dependency/org.jacoco.cli-${JACOCO_VERSION}-nodeps.jar "$@" +} + +# Merge all the jacoco.exec files +jacoco merge $(find **/target -name jacoco.exec) --destfile "$REPORT_DIR/jacoco-all.exec" + +rm -rf target/coverage-classes || true +mkdir -p target/coverage-classes + +# Unzip all the classes from the last build +# exclude certain paths - shims with no tests interfere with the coverage report +find . -type d -name 'target' -prune -exec find {} -type f \( -name 'ranger-*.jar' -or -name 'embeddedwebserver-*.jar' -or -name 'credentialbuilder-*.jar' -or -name 'unix*.jar' \) \; \ +-or -path './security-admin' -prune \ +-or -name '*shim*' -prune \ +| xargs -n1 unzip -o -q -d target/coverage-classes + +# get all source file paths +src=$(find . -path '*/src/main/java' -o -path './target' -prune | sed 's/^/--sourcefiles /g' | xargs echo) + +# generate the reports +jacoco report "$REPORT_DIR/jacoco-all.exec" $src --classfiles target/coverage-classes --html "$REPORT_DIR/all" --xml "$REPORT_DIR/all.xml"