Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
set up jacoco for code coverage (#234)
Browse files Browse the repository at this point in the history
* add jacoco for code coverage

* update codecov report uploader action

* clean code

* clean code

* change jacoco limit threshold to 0.0 to

* integrate Codecov with Github Actions pipeline

* upload jacoco report to codecov

* update README.md to show codecov badge
  • Loading branch information
yu-sun-77 authored Nov 4, 2020
1 parent b66011b commit 2b9ef9c
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 3 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,11 @@ jobs:
- name: Run Integration Tests
working-directory: ./tmp/pa
run: ./gradlew integTest -Dtests.enableIT=true -Dtests.useDockerCluster=true
- name: Generate Jacoco coverage report
working-directory: ./tmp/pa
run: ./gradlew jacocoTestReport
- name: Upload coverage report
working-directory: ./tmp/pa
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
run: bash <(curl -s https://codecov.io/bash) -f ./build/reports/jacoco/test/jacocoTestReport.xml
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[![Java CI](https://github.com/opendistro-for-elasticsearch/performance-analyzer/workflows/Java%20CI/badge.svg)](https://github.com/opendistro-for-elasticsearch/performance-analyzer/actions?query=workflow%3A%22Java+CI%22)
[![CD](https://github.com/opendistro-for-elasticsearch/performance-analyzer/workflows/CD/badge.svg)](https://github.com/opendistro-for-elasticsearch/performance-analyzer/actions?query=workflow%3ACD)
[![codecov](https://codecov.io/gh/opendistro-for-elasticsearch/performance-analyzer/branch/master/graph/badge.svg)](https://codecov.io/gh/opendistro-for-elasticsearch/performance-analyzer)
[![Documentation](https://img.shields.io/badge/api-reference-blue.svg)](https://opendistro.github.io/for-elasticsearch-docs/docs/pa/)
[![Chat](https://img.shields.io/badge/chat-on%20forums-blue)](https://discuss.opendistrocommunity.dev/c/performance-analyzer/)
![PRs welcome!](https://img.shields.io/badge/PRs-welcome!-success)
Expand Down
55 changes: 52 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ plugins {
id 'java'
id 'nebula.ospackage' version "8.2.0"
id 'com.github.spotbugs' version '4.0.0'
id 'jacoco'
}

spotbugsMain {
Expand Down Expand Up @@ -91,8 +92,8 @@ compileJava {
}
}

javadoc {
options.addStringOption("-add-exports", "jdk.attach/sun.tools.attach=ALL-UNNAMED")
javadoc {
options.addStringOption("-add-exports", "jdk.attach/sun.tools.attach=ALL-UNNAMED")
}

project.afterEvaluate {
Expand Down Expand Up @@ -122,6 +123,54 @@ tasks.withType(JavaCompile) {
options.warnings = false
}

jacoco {
toolVersion = "0.8.5"
}

jacocoTestReport {
reports {
xml.enabled true
html.enabled true
csv.enabled false
}
afterEvaluate {
classDirectories.from = files(classDirectories.files.collect {
fileTree(dir: it,
include: [
'**/com/amazon/opendistro/elasticsearch/performanceanalyzer/**',
],
exclude: [
])
})
}

}

jacocoTestCoverageVerification {
afterEvaluate {
classDirectories.from = files(classDirectories.files.collect {
fileTree(dir: it,
include: [
'**/com/amazon/opendistro/elasticsearch/performanceanalyzer/**',
],
exclude: [
])
})
}
violationRules {
rule {
limit {
minimum = 0.0
}
}
}
}


// to run coverage verification during the build (and fail when appropriate)
check.dependsOn jacocoTestCoverageVerification


dependencies {
if (JavaVersion.current() <= JavaVersion.VERSION_1_8) {
compile files("${System.properties['java.home']}/../lib/tools.jar")
Expand Down Expand Up @@ -330,6 +379,6 @@ afterEvaluate {
}

task buildPackages(type: GradleBuild) {
tasks = ['build', 'buildRpm', 'buildDeb']
tasks = ['build', 'buildRpm', 'buildDeb']
}
}

0 comments on commit 2b9ef9c

Please sign in to comment.