Skip to content

Commit 3532081

Browse files
committed
Enable code coverage report
1 parent f889d54 commit 3532081

File tree

3 files changed

+244
-2
lines changed

3 files changed

+244
-2
lines changed

.github/workflows/build-sonar.yml

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
# Copyright © 2020 Cask Data, Inc.
2+
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
3+
# use this file except in compliance with the License. You may obtain a copy of
4+
# the License at
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
# Unless required by applicable law or agreed to in writing, software
7+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
8+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
9+
# License for the specific language governing permissions and limitations under
10+
# the License.
11+
12+
# This workflow will build a Java project with Maven
13+
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
14+
# Note: Any changes to this workflow would be used only after merging into develop
15+
name: Build with test coverage and Sonar
16+
17+
on:
18+
workflow_run:
19+
workflows:
20+
- Trigger build
21+
types:
22+
- completed
23+
24+
jobs:
25+
build:
26+
runs-on: k8s-runner-build
27+
28+
if: ${{ github.event.workflow_run.conclusion != 'skipped' }}
29+
30+
steps:
31+
# Pinned 1.0.0 version
32+
- uses: haya14busa/action-workflow_run-status@967ed83efa565c257675ed70cfe5231f062ddd94
33+
34+
- uses: actions/checkout@v3
35+
with:
36+
ref: ${{ github.event.workflow_run.head_sha }}
37+
submodules: recursive
38+
39+
- name: Cache
40+
uses: actions/cache@v3
41+
with:
42+
path: ~/.m2/repository11
43+
key: ${{ runner.os }}-maven-${{ github.workflow }}-${{ hashFiles('**/pom.xml') }}
44+
restore-keys: |
45+
${{ runner.os }}-maven-${{ github.workflow }}
46+
47+
- name: Cache SonarCloud packages
48+
uses: actions/cache@v3
49+
with:
50+
path: ~/.sonar/cache
51+
key: ${{ runner.os }}-sonar
52+
restore-keys: ${{ runner.os }}-sonar
53+
54+
- name: Build with Maven
55+
run: >-
56+
mvn clean verify -fae -T 2 -B -V -Dmaven.test.failure.ignore
57+
-Dmaven.repo.local=$HOME/.m2/repository11
58+
-DcloudBuild
59+
-Pcoverage
60+
-Dmaven.wagon.http.retryHandler.count=3
61+
-Dmaven.wagon.httpconnectionManager.ttlSeconds=25
62+
63+
- name: Archive build artifacts
64+
uses: actions/upload-artifact@v3
65+
if: always()
66+
with:
67+
name: Build debug files
68+
path: |
69+
**/target/rat.txt
70+
**/target/surefire-reports/*
71+
72+
- name: Validate PR
73+
id: validate_pr
74+
# For whatever reason we get PR 69 for develop branch with both head and base as develop.
75+
if: ${{ github.event.workflow_run.pull_requests[0].head.ref != github.event.workflow_run.pull_requests[0].base.ref }}
76+
run: |
77+
echo ":set-output pr-key=${{ github.event.workflow_run.pull_requests[0].number }}"
78+
echo ":set-output pr-branch=${{ github.event.workflow_run.pull_requests[0].head.ref }}"
79+
echo ":set-output pr-base=${{ github.event.workflow_run.pull_requests[0].base.ref }}"
80+
81+
- name: Sonar report
82+
env:
83+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
84+
JAVA_HOME: /usr/lib/jvm/java-11-openjdk-amd64
85+
run: >-
86+
mvn org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -fae -T 2 -B -V
87+
-Dmaven.repo.local=$HOME/.m2/repository11
88+
-DcloudBuild
89+
-Pcoverage
90+
-Dmaven.wagon.http.retryHandler.count=3
91+
-Dmaven.wagon.httpconnectionManager.ttlSeconds=25
92+
-Dsonar.pullrequest.key=${{ steps.validate_pr.outputs.pr-key }}
93+
-Dsonar.pullrequest.branch=${{ steps.validate_pr.outputs.pr-branch }}
94+
-Dsonar.pullrequest.base=${{ steps.validate_pr.outputs.pr-base }}
95+
-Dsonar.branch.name=${{ github.event.workflow_run.head_branch }}
96+
97+
- name: Archive build artifacts
98+
uses: actions/upload-artifact@v3
99+
if: always()
100+
with:
101+
name: Build debug files
102+
path: |
103+
**/target/rat.txt
104+
**/target/surefire-reports/*
105+
106+
- name: Surefire Report
107+
# Pinned 3.5.2 version
108+
uses: mikepenz/action-junit-report@16a9560bd02f11e7e3bf6b3e2ef6bba6c9d07c32
109+
if: always()
110+
with:
111+
report_paths: '**/target/surefire-reports/TEST-*.xml'
112+
github_token: ${{ secrets.GITHUB_TOKEN }}
113+
detailed_summary: true
114+
commit: ${{ github.event.workflow_run.head_sha }}
115+
check_name: Sonar Build Test Report

delta-coverage/pom.xml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Copyright © 2022 Cask Data, Inc.
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License"); you may not
6+
~ use this file except in compliance with the License. You may obtain a copy of
7+
~ 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, WITHOUT
13+
~ WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14+
~ License for the specific language governing permissions and limitations under
15+
~ the License.
16+
-->
17+
<project xmlns="http://maven.apache.org/POM/4.0.0"
18+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
20+
<parent>
21+
<groupId>io.cdap.delta</groupId>
22+
<artifactId>delta</artifactId>
23+
<version>0.8.0-SNAPSHOT</version>
24+
</parent>
25+
<modelVersion>4.0.0</modelVersion>
26+
27+
<artifactId>delta-coverage</artifactId>
28+
<name>Delta Code Coverage</name>
29+
30+
<dependencies>
31+
<dependency>
32+
<groupId>io.cdap.delta</groupId>
33+
<artifactId>delta-api</artifactId>
34+
<version>${project.version}</version>
35+
</dependency>
36+
<dependency>
37+
<groupId>io.cdap.delta</groupId>
38+
<artifactId>delta-proto</artifactId>
39+
<version>${project.version}</version>
40+
</dependency>
41+
<dependency>
42+
<groupId>io.cdap.delta</groupId>
43+
<artifactId>delta-test</artifactId>
44+
<version>${project.version}</version>
45+
</dependency>
46+
<dependency>
47+
<groupId>io.cdap.delta</groupId>
48+
<artifactId>delta-app</artifactId>
49+
<version>${project.version}</version>
50+
</dependency>
51+
</dependencies>
52+
<profiles>
53+
<profile>
54+
<id>coverage</id>
55+
<build>
56+
<plugins>
57+
<plugin>
58+
<groupId>org.jacoco</groupId>
59+
<artifactId>jacoco-maven-plugin</artifactId>
60+
<version>${jacoco.version}</version>
61+
<executions>
62+
<execution>
63+
<id>report</id>
64+
<goals>
65+
<goal>report-aggregate</goal>
66+
</goals>
67+
<phase>verify</phase>
68+
</execution>
69+
</executions>
70+
</plugin>
71+
</plugins>
72+
</build>
73+
</profile>
74+
</profiles>
75+
</project>

pom.xml

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,18 @@
6262
<guava.version>13.0.1</guava.version>
6363
<junit.version>4.12</junit.version>
6464
<slf4j.version>1.7.25</slf4j.version>
65+
<jacoco.version>0.8.8</jacoco.version>
66+
67+
<sonar.organization>data-integrations</sonar.organization>
68+
<sonar.projectKey>data-integrations_${project.artifactId}</sonar.projectKey>
69+
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
70+
<sonar.coverage.jacoco.xmlReportPaths>${maven.multiModuleProjectDirectory}/delta-coverage/target/site/jacoco
71+
-aggregate/jacoco.xml</sonar.coverage.jacoco.xmlReportPaths>
72+
<!-- We need next line to ensure generated classes are analyzed -->
73+
<sonar.scm.exclusions.disabled>true</sonar.scm.exclusions.disabled>
74+
75+
<!-- Need default value when coverage is not collected -->
76+
<argLine />
6577
</properties>
6678

6779
<repositories>
@@ -155,9 +167,9 @@
155167
<plugin>
156168
<groupId>org.apache.maven.plugins</groupId>
157169
<artifactId>maven-surefire-plugin</artifactId>
158-
<version>2.14.1</version>
170+
<version>2.17</version>
159171
<configuration>
160-
<argLine>-Xmx512m</argLine>
172+
<argLine>@{argLine} -Xmx512m</argLine>
161173
<systemPropertyVariables>
162174
<java.io.tmpdir>${project.build.directory}</java.io.tmpdir>
163175
</systemPropertyVariables>
@@ -363,6 +375,46 @@
363375
</plugins>
364376
</build>
365377
</profile>
378+
<profile>
379+
<id>coverage</id>
380+
<modules>
381+
<module>delta-coverage</module>
382+
</modules>
383+
<build>
384+
<plugins>
385+
<plugin>
386+
<groupId>org.apache.maven.plugins</groupId>
387+
<artifactId>maven-site-plugin</artifactId>
388+
<version>3.7.1</version>
389+
</plugin>
390+
<plugin>
391+
<groupId>org.jacoco</groupId>
392+
<artifactId>jacoco-maven-plugin</artifactId>
393+
<version>${jacoco.version}</version>
394+
<executions>
395+
<execution>
396+
<id>prepare-agent</id>
397+
<goals>
398+
<goal>prepare-agent</goal>
399+
</goals>
400+
</execution>
401+
<execution>
402+
<id>report</id>
403+
<goals>
404+
<goal>report</goal>
405+
</goals>
406+
<configuration>
407+
<formats>
408+
<format>XML</format>
409+
<format>HTML</format>
410+
</formats>
411+
</configuration>
412+
</execution>
413+
</executions>
414+
</plugin>
415+
</plugins>
416+
</build>
417+
</profile>
366418
</profiles>
367419

368420
</project>

0 commit comments

Comments
 (0)