Skip to content

Commit 783ed50

Browse files
authored
ATLAS-5054: Introduce JaCoCo plugin and generate Code Coverage results with CI (#387)
* ATLAS-5054: Introduce JaCoCo plugin and generate Code Coverage results with CI * ATLAS-5054: refactor coverage.sh execution in atlas-build.sh * ATLAS-5054: add unzip command in Dockerfile.atlas-build * ATLAS-5054: move coverage artifacts to dist directory for upload later * ATLAS-5054: use host relative path for upload * ATLAS-5054: debug coverage files * ATLAS-5054: debug coverage files 2 * ATLAS-5054: debug coverage files 3 * ATLAS-5054: debug coverage files 4 * ATLAS-5054: revert all testing changes and make PR ready for review
1 parent 3eb4d0a commit 783ed50

File tree

5 files changed

+96
-2
lines changed

5 files changed

+96
-2
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ jobs:
7979
exit 1
8080
fi
8181
82+
- name: Upload Code Coverage Results
83+
uses: actions/upload-artifact@v4
84+
with:
85+
name: coverage
86+
path: dev-support/atlas-docker/dist/coverage/*
87+
8288
- name: Cache downloaded archives
8389
if: success()
8490
uses: actions/cache@v4

dev-support/atlas-docker/Dockerfile.atlas-build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ ARG ATLAS_BUILD_JAVA_VERSION
2020
ARG TARGETARCH
2121

2222
# Install necessary packages to build Atlas
23-
RUN apt-get update && apt-get -y install git maven
23+
RUN apt-get update && apt-get -y install git maven unzip
2424

2525
# Set environment variables
2626
ENV JAVA_HOME=/usr/lib/jvm/java-${ATLAS_BUILD_JAVA_VERSION}-openjdk-${TARGETARCH}

dev-support/atlas-docker/scripts/atlas-build.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,11 @@ mv -f distro/target/apache-atlas-${ATLAS_VERSION}-server.tar.gz /home/atlas/
9292
mv -f distro/target/apache-atlas-${ATLAS_VERSION}-hive-hook.tar.gz /home/atlas/dist/
9393
mv -f distro/target/apache-atlas-${ATLAS_VERSION}-hbase-hook.tar.gz /home/atlas/dist/
9494
mv -f distro/target/apache-atlas-${ATLAS_VERSION}-kafka-hook.tar.gz /home/atlas/dist/
95+
96+
# Run code coverage and generate reports
97+
./dev-support/checks/coverage.sh
98+
status=$?
99+
100+
# save coverage reports to the dist directory before container shutdown
101+
mv -f target/coverage /home/atlas/dist/
102+
exit $status

dev-support/checks/coverage.sh

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env bash
2+
# Licensed to the Apache Software Foundation (ASF) under one or more
3+
# contributor license agreements. See the NOTICE file distributed with
4+
# this work for additional information regarding copyright ownership.
5+
# The ASF licenses this file to You under the Apache License, Version 2.0
6+
# (the "License"); you may not use this file except in compliance with
7+
# the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# This script merges the jacoco exec files and generates a report in HTML and XML formats
18+
19+
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
20+
cd "$DIR/../.." || exit 1
21+
22+
set -ex
23+
24+
REPORT_DIR="$DIR/../../target/coverage"
25+
26+
mkdir -p "$REPORT_DIR"
27+
28+
JACOCO_VERSION=$(mvn help:evaluate -Dexpression=jacoco.version -q -DforceStdout -Dscan=false)
29+
30+
# Install jacoco cli
31+
mvn --non-recursive --no-transfer-progress -Dscan=false \
32+
org.apache.maven.plugins:maven-dependency-plugin:copy \
33+
-Dartifact=org.jacoco:org.jacoco.cli:${JACOCO_VERSION}:jar:nodeps
34+
35+
jacoco() {
36+
java -jar target/dependency/org.jacoco.cli-${JACOCO_VERSION}-nodeps.jar "$@"
37+
}
38+
39+
# Merge all the jacoco.exec files
40+
jacoco merge $(find **/target -name jacoco.exec) --destfile "$REPORT_DIR/jacoco-all.exec"
41+
42+
rm -rf target/coverage-classes || true
43+
mkdir -p target/coverage-classes
44+
45+
# Unzip all the classes from the last build
46+
{ find */target/ -name 'atlas-*.jar'; find addons/**/target/*.jar -name '*-bridge-*.jar'; } | grep -v 'tests' | xargs -n1 unzip -o -q -d target/coverage-classes
47+
48+
# get all source file paths
49+
src=$(find . -path '*/src/main/java' -o -path './target' -prune | sed 's/^/--sourcefiles /g' | xargs echo)
50+
51+
# generate the reports
52+
jacoco report "$REPORT_DIR/jacoco-all.exec" $src --classfiles target/coverage-classes --html "$REPORT_DIR/all" --xml "$REPORT_DIR/all.xml"

pom.xml

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@
129129
<ivy.version>2.5.2</ivy.version>
130130
<jackson.databind.version>2.12.7</jackson.databind.version>
131131
<jackson.version>2.12.7</jackson.version>
132+
<jacoco.version>0.8.13</jacoco.version>
132133
<janusgraph.cassandra.version>0.5.3</janusgraph.cassandra.version>
133134
<janusgraph.version>1.0.0</janusgraph.version>
134135
<java.version.required>1.8</java.version.required>
@@ -905,6 +906,12 @@
905906
<version>3.0.0</version>
906907
</dependency>
907908

909+
<dependency>
910+
<groupId>org.jacoco</groupId>
911+
<artifactId>jacoco-maven-plugin</artifactId>
912+
<version>${jacoco.version}</version>
913+
</dependency>
914+
908915
<dependency>
909916
<groupId>org.slf4j</groupId>
910917
<artifactId>jul-to-slf4j</artifactId>
@@ -1334,7 +1341,7 @@
13341341
<forkCount>${surefire.forkCount}</forkCount>
13351342
<reuseForks>false</reuseForks>
13361343
<redirectTestOutputToFile>true</redirectTestOutputToFile>
1337-
<argLine>-Djava.awt.headless=true -Dproject.version=${project.version}
1344+
<argLine>${argLine} -Djava.awt.headless=true -Dproject.version=${project.version}
13381345
-Dhadoop.tmp.dir="${project.build.directory}/tmp-hadoop-${user.name}"
13391346
-Xmx1024m -Djava.net.preferIPv4Stack=true ${atlas.surefire.options}</argLine>
13401347
<skip>${skipUTs}</skip>
@@ -1567,6 +1574,27 @@
15671574
<artifactId>javancss-maven-plugin</artifactId>
15681575
</plugin>
15691576

1577+
<plugin>
1578+
<groupId>org.jacoco</groupId>
1579+
<artifactId>jacoco-maven-plugin</artifactId>
1580+
<version>${jacoco.version}</version>
1581+
<executions>
1582+
<execution>
1583+
<id>jacoco-initialize</id>
1584+
<goals>
1585+
<goal>prepare-agent</goal>
1586+
</goals>
1587+
</execution>
1588+
<execution>
1589+
<id>jacoco-site</id>
1590+
<goals>
1591+
<goal>report</goal>
1592+
</goals>
1593+
<phase>package</phase>
1594+
</execution>
1595+
</executions>
1596+
</plugin>
1597+
15701598
<plugin>
15711599
<artifactId>maven-clean-plugin</artifactId>
15721600
<configuration>

0 commit comments

Comments
 (0)