Skip to content

Commit

Permalink
Add JaCoCo coverity tests to Github actions
Browse files Browse the repository at this point in the history
- Add support for JaCoCo coverity tests
- Run coverity tests automatically in CI
- Upload coverity results to SonarCloud
  • Loading branch information
softgitron committed Apr 17, 2021
1 parent bd3f36b commit a067be9
Show file tree
Hide file tree
Showing 5 changed files with 259 additions and 22 deletions.
84 changes: 64 additions & 20 deletions .github/workflows/post-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ jobs:
restore-keys: |
maven-repo-${{ hashFiles('**/pom.xml') }}
maven-repo-
- name: Delete temporary build artifacts
run: rm -rf ~/.m2/repository/org/apache/ratis
if: always()
- name: Setup java
uses: actions/setup-java@v1
with:
java-version: ${{ matrix.java }}
- name: Run a full build
run: ./dev-support/checks/build.sh
- name: Delete temporary build artifacts
run: rm -rf ~/.m2/repository/org/apache/ratis
if: always()
rat:
name: rat
runs-on: ubuntu-18.04
Expand All @@ -57,15 +57,15 @@ jobs:
restore-keys: |
maven-repo-${{ hashFiles('**/pom.xml') }}
maven-repo-
- name: Delete temporary build artifacts
run: rm -rf ~/.m2/repository/org/apache/ratis
if: always()
- run: ./dev-support/checks/rat.sh
- uses: actions/upload-artifact@master
if: always()
with:
name: rat
path: target/rat
- name: Delete temporary build artifacts
run: rm -rf ~/.m2/repository/org/apache/ratis
if: always()
author:
name: author
runs-on: ubuntu-18.04
Expand Down Expand Up @@ -97,18 +97,57 @@ jobs:
restore-keys: |
maven-repo-${{ hashFiles('**/pom.xml') }}
maven-repo-
- name: Delete temporary build artifacts
run: rm -rf ~/.m2/repository/org/apache/ratis
if: always()
- run: ./dev-support/checks/unit.sh -P${{ matrix.profile }}-tests
- name: Summary of failures
run: cat target/${{ github.job }}/summary.txt
run: cat target/unit/summary.txt
if: ${{ !cancelled() }}
- uses: actions/upload-artifact@master
if: ${{ !cancelled() }}
with:
name: unit-${{ matrix.profile }}
path: target/unit
- name: Delete temporary build artifacts
run: rm -rf ~/.m2/repository/org/apache/ratis
if: always()
coverity:
name: coverity
runs-on: ubuntu-18.04
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-
- name: Delete temporary build artifacts
run: rm -rf ~/.m2/repository/org/apache/ratis
if: always()
- run: >-
./dev-support/checks/unit.sh -P${{ matrix.profile }}-tests
-Dmaven.test.failure.ignore=true
-Djacoco.skip=false
-Dsurefire.rerunFailingTestsCount=3
- 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
checkstyle:
name: checkstyle
runs-on: ubuntu-18.04
Expand All @@ -122,15 +161,15 @@ jobs:
restore-keys: |
maven-repo-${{ hashFiles('**/pom.xml') }}
maven-repo-
- name: Delete temporary build artifacts
run: rm -rf ~/.m2/repository/org/apache/ratis
if: always()
- run: ./dev-support/checks/checkstyle.sh
- uses: actions/upload-artifact@master
if: always()
with:
name: checkstyle
path: target/checkstyle
- name: Delete temporary build artifacts
run: rm -rf ~/.m2/repository/org/apache/ratis
if: always()
findbugs:
name: findbugs
runs-on: ubuntu-18.04
Expand All @@ -144,21 +183,24 @@ jobs:
restore-keys: |
maven-repo-${{ hashFiles('**/pom.xml') }}
maven-repo-
- name: Delete temporary build artifacts
run: rm -rf ~/.m2/repository/org/apache/ratis
if: always()
- run: ./dev-support/checks/findbugs.sh
- uses: actions/upload-artifact@master
if: always()
with:
name: findbugs
path: target/findbugs
- name: Delete temporary build artifacts
run: rm -rf ~/.m2/repository/org/apache/ratis
if: always()
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:
Expand All @@ -167,6 +209,11 @@ jobs:
restore-keys: |
maven-repo-${{ hashFiles('**/pom.xml') }}
maven-repo-
- name: Delete temporary build artifacts
run: rm -rf ~/.m2/repository/org/apache/ratis
- name: Download test artifacts for coverity analysis
uses: actions/download-artifact@v2
if: always()
- name: Setup java 11
uses: actions/setup-java@v1
with:
Expand All @@ -175,6 +222,3 @@ jobs:
env:
SONAR_TOKEN: ${{ secrets.SONARCLOUD_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Delete temporary build artifacts
run: rm -rf ~/.m2/repository/org/apache/ratis
if: always()
5 changes: 4 additions & 1 deletion dev-support/checks/sonar.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 16 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
<module>ratis-resource-bundle</module>
<module>ratis-grpc</module>
<module>ratis-netty</module>
<module>ratis-coverage</module>
<module>ratis-hadoop</module>

<module>ratis-test</module>
Expand Down Expand Up @@ -249,6 +250,8 @@
<!-- LOG4J version -->
<log4j.version>1.2.17</log4j.version>

<!-- Skip JaCoCo coverity reports by default -->
<jacoco.skip>true</jacoco.skip>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -703,7 +706,7 @@
<reuseForks>false</reuseForks>
<trimStackTrace>false</trimStackTrace>
<forkedProcessTimeoutInSeconds>600</forkedProcessTimeoutInSeconds>
<argLine>-Xmx2048m -XX:+HeapDumpOnOutOfMemoryError</argLine>
<argLine>@{argLine} -Xmx2048m -XX:+HeapDumpOnOutOfMemoryError</argLine>
<systemPropertyVariables>
<ratis.log.dir>${project.build.directory}/log</ratis.log.dir>
<ratis.tmp.dir>${project.build.directory}/tmp</ratis.tmp.dir>
Expand Down Expand Up @@ -907,6 +910,18 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.6</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,10 @@ static void printAll(Class<?> confClass, Consumer<Object> out) {

static void printField(Class<?> confClass, Consumer<Object> 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);
}
Expand Down
Loading

0 comments on commit a067be9

Please sign in to comment.