Skip to content

Code Quality and Coverage

Nick Podopryhora edited this page Nov 18, 2020 · 3 revisions

Table of Contents

Tools

The following tools are used for code coverage and static code analysis:

Scheme

Running and publishing reports to SonarCloud from local machine

Configuration:

Make sure that Gradle task sonarqube in build.gradle file is correctly configured:

The credentials can be obtained from Vitalii Kulinsky

Publishing reports:

In order to push coverage and other code analysis data you need to run Gradle task sonarqube:

  1. From IntelliJ IDEA select the Gradle tab and run sonarqube task
  1. After completion you will find report data in your SonarCloud(SonarQube) UI.

Running SonarCloud analysis using GitHub Actions

SonarCloud setup

The credentials and instructions for GitHub Actions can be found in the SonarCloud account in the Administration -> Analysis Method section:

GitHub setup

Sonar token obtained from the previous step should be added to the GitHub repository settings in the Secrets section:

Gradle setup

sonarqube {
	tasks['sonarqube'].dependsOn jacocoTestReport
	properties {
		property "sonar.host.url", "https://sonarcloud.io"
		property "sonar.projectKey", "ita-social-projects_dokazovi-be"
		property "sonar.organization", "ita-social-projects"
		property "sonar.jacoco.reportPaths", "$buildDir/reports/jacoco/test/jacocoTestReport.xml"
		property "sonar.coverage.exclusions", "**/*.sql," +
				"src/main/java/com/softserveinc/dokazovi/entity/**," +
				"src/main/java/com/softserveinc/dokazovi/dto/**," +
				"src/main/java/com/softserveinc/dokazovi/config/**"
	}
}

sonarqube task depends on jacocoTestReport task since it generates coverage reports used by the Sonar scanner. In turn jacocoTestReport depends on test task.

Actions setup

Workflow for SonarCloud Code Analysis is located in develop/.github/workflows/Build_and_Test.yml file.

The action is triggered when new code is pushed to the develop branch or when Pull-request is created or changed.

Example

As a result of workflow SonarCloud status bar will be reflected in the pull request: