Skip to content

Commit

Permalink
Add codecove and sonarcloud configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
Xenowa committed Apr 16, 2024
1 parent 87d1cd1 commit 695d9b3
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 17 deletions.
25 changes: 24 additions & 1 deletion .github/workflows/full_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,29 @@ jobs:
packagePAT: ${{ secrets.GITHUB_TOKEN }}
run: ./gradlew build

- name: Generate Jacoco report
run: ./gradlew createCodeCoverageReport

- name: Generate Codecov Report
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./.jacoco/reports/jacoco/report.xml

- name: Cache SonarCloud packages for faster analysis
uses: actions/cache@v3
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar

- name: Generate SonarCloud Report
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
if: "${{ env.SONAR_TOKEN != '' }}"
run: ./gradlew sonar --info

windows_build:
name: Build
runs-on: windows-latest
Expand All @@ -65,4 +88,4 @@ jobs:
env:
packageUser: ${{ github.actor }}
packagePAT: ${{ secrets.GITHUB_TOKEN }}
run: ./gradlew.bat build
run: ./gradlew build
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ build/

# IntelliJ IDEA
.idea/

# Coverage reports
.jacoco/
70 changes: 60 additions & 10 deletions ScanCommand/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ plugins {
id 'application'
id 'java-library'
id 'checkstyle'
id "com.github.spotbugs" version "${spotbugsPluginVersion}"
id "de.undercouch.download" version "${downloadPluginVersion}"
id 'jacoco'
id 'com.github.spotbugs'
id 'de.undercouch.download'
id 'org.sonarqube'
}

group = "${group}"
Expand Down Expand Up @@ -57,11 +59,15 @@ dependencies {
implementation group: 'org.ballerinalang', name: 'jballerina-tools', version: "${ballerinaLangVersion}"
implementation group: 'org.ballerinalang', name: 'ballerina-cli', version: "${ballerinaLangVersion}"

checkstyle group: 'com.puppycrawl.tools', name: 'checkstyle', version: "${puppycrawlCheckstyleVersion}"

// Required for determining the platform a java process is running on
implementation group: 'org.apache.commons', name: 'commons-lang3', version: "${apacheCommonsLang3Version}"

// Required dependencies for jacoco
implementation group: 'org.jacoco', name: 'org.jacoco.core', version: "${jacocoVersion}"
implementation group: 'org.jacoco', name: 'org.jacoco.report', version: "${jacocoVersion}"

checkstyle group: 'com.puppycrawl.tools', name: 'checkstyle', version: "${puppycrawlCheckstyleVersion}"

// Required dependencies for running scan tool tests
testImplementation group: 'org.testng', name: 'testng', version: "${testngVersion}"
}
Expand Down Expand Up @@ -153,12 +159,6 @@ task validateSpotbugs() {

spotbugsMain.finalizedBy validateSpotbugs

tasks.test {
useTestNG() {
suites 'src/test/resources/testng.xml'
}
}

// Configurations to automatically build and deploy scan tool
def packageName = "tool_scan"
def tomlVersion = "${project.scanToolVersion}"
Expand Down Expand Up @@ -268,3 +268,53 @@ build {
dependsOn createBallerinaToolConfigFile
dependsOn buildScanTool
}

// Configuring tests
tasks.test {
useTestNG() {
suites 'src/test/resources/testng.xml'
}
}

// Codecove configurations
def execFile;
def classFileArray = []
task copyExecFilesAndJavaClassFiles {
execFile = new File("${buildDir}/jacoco/test.exec")
if (execFile.exists()) {
fileTree("${buildDir}/classes").matching {
exclude '**/test/*'
exclude '**/module-info.class'
}.each { file -> classFileArray.push(file) }
}
}

task createCodeCoverageReport(type: JacocoReport) {
executionData file(execFile)
additionalClassDirs files(classFileArray)

reports {
xml.required = true
html.required = true
xml.destination new File("${rootDir}/.jacoco/reports/jacoco/report.xml")
html.destination new File("${rootDir}/.jacoco/reports/jacoco/report.html")
}
onlyIf = {
true
}
}

createCodeCoverageReport.dependsOn(copyExecFilesAndJavaClassFiles)

// SonarCloud Configurations
sonar {
properties {
property "sonar.projectKey", "ballerina-platform_static-code-analysis-tool"
property "sonar.organization", "ballerina-platform"
property "sonar.host.url", "https://sonarcloud.io"

// Additional properties
// To Add test coverage
property "sonar.coverage.jacoco.xmlReportPaths", "${rootDir}/.jacoco/reports/jacoco/*.xml"
}
}
2 changes: 1 addition & 1 deletion ScanCommand/src/main/java/io/ballerina/scan/ScanCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public class ScanCmd implements BLauncherCmd {
private boolean scanReport;

@CommandLine.Option(names = "--list-rules",
description = "List the rules available in the Ballerina scan tool.")
description = "List the rules available in the Ballerina scan tool")
private boolean listRules;

@CommandLine.Option(names = "--include-rules",
Expand Down
4 changes: 0 additions & 4 deletions ScanCommand/src/main/java/io/ballerina/scan/Severity.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@

/**
* Represents the kind of severity of a {@link Rule} instance.
* <p>
* There are three known kinds of severities at the moment: {@link #CODE_SMELL}, {@link #BUG}
* and {@link #VULNERABILITY}.
* </p>
*
* @since 0.1.0
*/
Expand Down
6 changes: 5 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
group=io.ballerina.scan
scanToolVersion=0.1.0

# Dependency versions
# Plugin versions
spotbugsPluginVersion=5.0.14
downloadPluginVersion=5.4.0
sonarqubeGradlePluginVersion=4.0.0.2929

# Dependency versions
picoCLIVersion=4.7.5
gsonVersion=2.10.1
ballerinaLangVersion=2201.8.6
puppycrawlCheckstyleVersion=10.12.1
apacheCommonsLang3Version=3.0
testngVersion=7.6.1
jacocoVersion=0.8.10
13 changes: 13 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,18 @@
* under the License.
*/

pluginManagement {
plugins {
id 'java'
id 'application'
id 'java-library'
id 'checkstyle'
id 'jacoco'
id 'com.github.spotbugs' version "${spotbugsPluginVersion}"
id 'de.undercouch.download' version "${downloadPluginVersion}"
id 'org.sonarqube' version "${sonarqubeGradlePluginVersion}"
}
}

rootProject.name = 'static-code-analysis-tool'
include 'ScanCommand'

0 comments on commit 695d9b3

Please sign in to comment.