From 32ac13d8d7d326d6cccc2a3a5525105debbf641b Mon Sep 17 00:00:00 2001 From: Yu Sun Date: Mon, 2 Nov 2020 17:02:17 -0800 Subject: [PATCH 1/8] add jacoco for code coverage --- build.gradle | 45 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index 780c5c83..01475162 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,44 @@ tasks.withType(JavaCompile) { options.warnings = false } +jacoco { + toolVersion = "0.8.5" +} + +jacocoTestReport { + reports { + xml.enabled false + csv.enabled false + html.destination file("${buildDir}/jacocoHtml") + } +} + +jacocoTestCoverageVerification { + violationRules { + rule { + limit { + minimum = 0.8 + } + } + + rule { + enabled = false + element = 'CLASS' + includes = ['org.gradle.*'] + + limit { + counter = 'LINE' + value = 'TOTALCOUNT' + maximum = 0.3 + } + } + } +} + +// 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 +369,6 @@ afterEvaluate { } task buildPackages(type: GradleBuild) { - tasks = ['build', 'buildRpm', 'buildDeb'] + tasks = ['build', 'buildRpm', 'buildDeb'] } } From 45c04684845b4473c937ab87e12b025a07321f21 Mon Sep 17 00:00:00 2001 From: Yu Sun Date: Mon, 2 Nov 2020 17:23:51 -0800 Subject: [PATCH 2/8] update codecov report uploader action --- .github/workflows/gradle.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index b9c7f4da..f679b0af 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 From 2062a4c4678058cb20bfaaf9a72927376f79d16a Mon Sep 17 00:00:00 2001 From: Yu Sun Date: Mon, 2 Nov 2020 17:53:53 -0800 Subject: [PATCH 3/8] clean code --- .github/workflows/gradle.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index f679b0af..e412aaa8 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -57,5 +57,5 @@ jobs: - name: Upload coverage report working-directory: ./tmp/pa env: - CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + CODECOV_TOKEN: ${{secrets.CODECOV_TOKEN}} run: bash <(curl -s https://codecov.io/bash) -f ./build/reports/jacoco/test/jacocoTestReport.xml From 6b8cc91e6414338ebc35523a501e93f4779a43be Mon Sep 17 00:00:00 2001 From: Yu Sun Date: Mon, 2 Nov 2020 18:08:55 -0800 Subject: [PATCH 4/8] clean code --- .github/workflows/gradle.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index e412aaa8..e96ce1cb 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -57,5 +57,5 @@ jobs: - name: Upload coverage report working-directory: ./tmp/pa env: - CODECOV_TOKEN: ${{secrets.CODECOV_TOKEN}} + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} run: bash <(curl -s https://codecov.io/bash) -f ./build/reports/jacoco/test/jacocoTestReport.xml From 592b53e05884d1d3abe00ab02af47a3c0ab87be3 Mon Sep 17 00:00:00 2001 From: Yu Sun Date: Mon, 2 Nov 2020 18:14:38 -0800 Subject: [PATCH 5/8] change jacoco limit threshold to 0.0 to --- build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 01475162..d438c2f0 100644 --- a/build.gradle +++ b/build.gradle @@ -139,7 +139,7 @@ jacocoTestCoverageVerification { violationRules { rule { limit { - minimum = 0.8 + minimum = 0.0 } } @@ -151,7 +151,7 @@ jacocoTestCoverageVerification { limit { counter = 'LINE' value = 'TOTALCOUNT' - maximum = 0.3 + maximum = 0.0 } } } From 8aa0dc00fdb9806a8b0c40aad365adec96c5eaf4 Mon Sep 17 00:00:00 2001 From: Yu Sun Date: Mon, 2 Nov 2020 18:48:19 -0800 Subject: [PATCH 6/8] integrate Codecov with Github Actions pipeline --- .github/workflows/gradle.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index e96ce1cb..e21c79b5 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -55,7 +55,6 @@ jobs: 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 + uses: codecov/codecov-action@v1 + with: + token: ${{ secrets.CODECOV_TOKEN }} From 14239c353fb2a4e59103dd1d75e7f83219f4fa28 Mon Sep 17 00:00:00 2001 From: Yu Sun Date: Tue, 3 Nov 2020 10:48:12 -0800 Subject: [PATCH 7/8] upload jacoco report to codecov --- .github/workflows/gradle.yml | 7 ++++--- build.gradle | 38 +++++++++++++++++++++++------------- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index e21c79b5..e96ce1cb 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -55,6 +55,7 @@ jobs: working-directory: ./tmp/pa run: ./gradlew jacocoTestReport - name: Upload coverage report - uses: codecov/codecov-action@v1 - with: - token: ${{ secrets.CODECOV_TOKEN }} + 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/build.gradle b/build.gradle index d438c2f0..7931b7da 100644 --- a/build.gradle +++ b/build.gradle @@ -129,34 +129,44 @@ jacoco { jacocoTestReport { reports { - xml.enabled false + xml.enabled true + html.enabled true csv.enabled false - html.destination file("${buildDir}/jacocoHtml") } + 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 } } - - rule { - enabled = false - element = 'CLASS' - includes = ['org.gradle.*'] - - limit { - counter = 'LINE' - value = 'TOTALCOUNT' - maximum = 0.0 - } - } } } + // to run coverage verification during the build (and fail when appropriate) check.dependsOn jacocoTestCoverageVerification From 5936dea149d7d8fd27656955ed791b15a3ec63cc Mon Sep 17 00:00:00 2001 From: Yu Sun Date: Tue, 3 Nov 2020 11:03:53 -0800 Subject: [PATCH 8/8] update README.md to show codecov badge --- README.md | 1 + 1 file changed, 1 insertion(+) 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)