From 2b9ef9cb80b6e42d06a546c90cfab0326daeae27 Mon Sep 17 00:00:00 2001 From: Yu Sun <11154022+yu-sun-77@users.noreply.github.com> Date: Tue, 3 Nov 2020 16:44:57 -0800 Subject: [PATCH] set up jacoco for code coverage (#234) * 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 --- .github/workflows/gradle.yml | 8 ++++++ README.md | 1 + build.gradle | 55 ++++++++++++++++++++++++++++++++++-- 3 files changed, 61 insertions(+), 3 deletions(-) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index b9c7f4da..e96ce1cb 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -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 diff --git a/README.md b/README.md index 43d17a95..81483696 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/build.gradle b/build.gradle index 780c5c83..7931b7da 100644 --- a/build.gradle +++ b/build.gradle @@ -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 { @@ -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 { @@ -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") @@ -330,6 +379,6 @@ afterEvaluate { } task buildPackages(type: GradleBuild) { - tasks = ['build', 'buildRpm', 'buildDeb'] + tasks = ['build', 'buildRpm', 'buildDeb'] } }