diff --git a/.github/workflows/post-commit.yml b/.github/workflows/post-commit.yml index 7aee48a1d1..55785624b1 100644 --- a/.github/workflows/post-commit.yml +++ b/.github/workflows/post-commit.yml @@ -114,6 +114,47 @@ jobs: - name: Delete temporary build artifacts run: rm -rf ~/.m2/repository/org/apache/ratis if: always() + coverity: + name: coverity + runs-on: ubuntu-18.04 + if: (github.repository == 'apache/ratis' || github.repository == 'apache/incubator-ratis') && github.event_name != 'pull_request' + strategy: + matrix: + profile: + - grpc + - server + - misc + steps: + - uses: actions/checkout@master + - name: Cache for maven dependencies + uses: actions/cache@v2 + with: + path: ~/.m2/repository + key: maven-repo-${{ hashFiles('**/pom.xml') }}-${{ github.job }} + restore-keys: | + maven-repo-${{ hashFiles('**/pom.xml') }} + maven-repo- + - run: >- + ./dev-support/checks/unit.sh -P${{ matrix.profile }}-tests + -Dmaven.test.failure.ignore=true + -Djacoco.skip=false + -Dsurefire.rerunFailingTestsCount=3 + continue-on-error: true + - name: Merge JaCoCo results + run: mvn -DskipTests -Djacoco.skip=false verify + - name: Copy JaCoCo XML report to artifacts + run: cp ./ratis-coverage/target/site/jacoco-aggregate/jacoco.xml ./target/unit + - name: Summary of failures + run: cat target/unit/summary.txt + if: ${{ !cancelled() }} + - uses: actions/upload-artifact@master + if: ${{ !cancelled() }} + with: + name: coverity-${{ matrix.profile }} + path: target/unit + - name: Delete temporary build artifacts + run: rm -rf ~/.m2/repository/org/apache/ratis + if: always() checkstyle: name: checkstyle runs-on: ubuntu-18.04 @@ -161,9 +202,12 @@ jobs: sonar: name: sonar runs-on: ubuntu-18.04 + needs: [coverity] if: (github.repository == 'apache/ratis' || github.repository == 'apache/incubator-ratis') && github.event_name != 'pull_request' steps: - - uses: actions/checkout@master + - uses: actions/checkout@v2 + with: + fetch-depth: 0 - name: Cache for maven dependencies uses: actions/cache@v2 with: @@ -172,6 +216,9 @@ jobs: restore-keys: | maven-repo-${{ hashFiles('**/pom.xml') }} maven-repo- + - name: Download test artifacts for coverity analysis + uses: actions/download-artifact@v2 + if: always() - name: Setup java 11 uses: actions/setup-java@v1 with: @@ -182,4 +229,4 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Delete temporary build artifacts run: rm -rf ~/.m2/repository/org/apache/ratis - if: always() + if: always() \ No newline at end of file diff --git a/dev-support/checks/sonar.sh b/dev-support/checks/sonar.sh index a1f9dbe601..1a6e2cc0c0 100755 --- a/dev-support/checks/sonar.sh +++ b/dev-support/checks/sonar.sh @@ -20,4 +20,7 @@ if [ ! "$SONAR_TOKEN" ]; then echo "SONAR_TOKEN environment variable should be set" exit 1 fi -mvn -B verify -DskipShade -DskipTests org.sonarsource.scanner.maven:sonar-maven-plugin:3.6.0.1398:sonar -Dsonar.host.url=https://sonarcloud.io -Dsonar.organization=apache -Dsonar.projectKey=apache-ratis +mvn -B verify -DskipShade -DskipTests org.sonarsource.scanner.maven:sonar-maven-plugin:3.6.0.1398:sonar \ +-Dsonar.host.url=https://sonarcloud.io \ +-Dsonar.coverage.jacoco.xmlReportPaths=$(find "$(pwd)" -path '*jacoco.xml' | tr '\n' ',') \ +-Dsonar.organization=apache -Dsonar.projectKey=apache-ratis diff --git a/pom.xml b/pom.xml index bd9b95fcac..72f8be5db0 100644 --- a/pom.xml +++ b/pom.xml @@ -78,6 +78,7 @@ ratis-resource-bundle ratis-grpc ratis-netty + ratis-coverage ratis-hadoop ratis-test @@ -249,6 +250,8 @@ 1.2.17 + + true @@ -703,7 +706,7 @@ false false 600 - -Xmx2048m -XX:+HeapDumpOnOutOfMemoryError + @{argLine} -Xmx2048m -XX:+HeapDumpOnOutOfMemoryError ${project.build.directory}/log ${project.build.directory}/tmp @@ -907,6 +910,18 @@ + + org.jacoco + jacoco-maven-plugin + 0.8.6 + + + + prepare-agent + + + + diff --git a/ratis-common/src/main/java/org/apache/ratis/conf/ConfUtils.java b/ratis-common/src/main/java/org/apache/ratis/conf/ConfUtils.java index b662dffdd0..9546109dd3 100644 --- a/ratis-common/src/main/java/org/apache/ratis/conf/ConfUtils.java +++ b/ratis-common/src/main/java/org/apache/ratis/conf/ConfUtils.java @@ -266,6 +266,10 @@ static void printAll(Class confClass, Consumer out) { static void printField(Class confClass, Consumer out, Field f) { final int modifiers = f.getModifiers(); + // Ignore synthetic fields. Required by JaCoCo coverity reports + if (f.isSynthetic()) { + return; + } if (!Modifier.isStatic(modifiers)) { throw new IllegalStateException("Found non-static field " + f); } diff --git a/ratis-coverage/pom.xml b/ratis-coverage/pom.xml new file mode 100644 index 0000000000..588c49e11a --- /dev/null +++ b/ratis-coverage/pom.xml @@ -0,0 +1,171 @@ + + + + 4.0.0 + + ratis + org.apache.ratis + 2.1.0-SNAPSHOT + + + report + Apache Ratis Coverity Report + + + + + + org.apache.ratis + ratis-thirdparty-misc + + + org.apache.ratis + ratis-resource-bundle + ${project.version} + true + + + ratis-docs + org.apache.ratis + + + ratis-proto + org.apache.ratis + + + ratis-common + org.apache.ratis + + + ratis-common + org.apache.ratis + test-jar + + + + ratis-client + org.apache.ratis + + + ratis-client + org.apache.ratis + test-jar + + + ratis-server + org.apache.ratis + + + ratis-server + org.apache.ratis + test-jar + + + + ratis-grpc + org.apache.ratis + + + ratis-grpc + org.apache.ratis + test-jar + + + + ratis-netty + org.apache.ratis + + + ratis-netty + org.apache.ratis + test-jar + + + + ratis-hadoop + org.apache.ratis + + + ratis-hadoop + org.apache.ratis + test-jar + + + + ratis-test + org.apache.ratis + + + ratis-test + org.apache.ratis + test-jar + + + + ratis-examples + org.apache.ratis + + + ratis-examples + org.apache.ratis + test-jar + + + + ratis-replicated-map + org.apache.ratis + + + ratis-replicated-map + org.apache.ratis + test-jar + + + + ratis-logservice + org.apache.ratis + + + ratis-logservice + org.apache.ratis + test-jar + + + org.apache.ratis + ratis-metrics + + + org.apache.ratis + ratis-tools + + + + + + + org.jacoco + jacoco-maven-plugin + + + report + verify + + report-aggregate + + + + + + + + \ No newline at end of file