diff --git a/.github/workflows/sonar-cloud.yml b/.github/workflows/sonar-cloud.yml new file mode 100644 index 00000000000000..a8f7e0697a8c4e --- /dev/null +++ b/.github/workflows/sonar-cloud.yml @@ -0,0 +1,37 @@ +name: SonarCloud +on: + push: + branches: + - master + pull_request: + types: [opened, synchronize, reopened] +jobs: + build: + name: Build and analyze + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: 17 + distribution: 'zulu' # Alternative distribution options are available + - name: Cache SonarCloud packages + uses: actions/cache@v3 + with: + path: ~/.sonar/cache + key: ${{ runner.os }}-sonar + restore-keys: ${{ runner.os }}-sonar + - name: Cache Gradle packages + uses: actions/cache@v3 + with: + path: ~/.gradle/caches + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }} + restore-keys: ${{ runner.os }}-gradle + - name: Build and analyze + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + run: ./gradlew test sonar --info diff --git a/build.gradle b/build.gradle index da6c5923390636..f57459be07d47a 100644 --- a/build.gradle +++ b/build.gradle @@ -81,6 +81,7 @@ plugins { id "com.diffplug.spotless" version "6.23.3" id 'jacoco-report-aggregation' id 'io.github.surpsg.delta-coverage' version "2.5.0" + id 'org.sonarqube' version "5.1.0.4882" // id "io.github.gw-kit.delta-coverage" version "3.0.0-RC1" // TODO id "org.gradlex.java-ecosystem-capabilities" version "1.0" @@ -282,6 +283,18 @@ project.ext.externalDependency = [ 'mustache': 'com.github.spullara.mustache.java:compiler:0.9.14' ] +sonarqube { + properties { + property "sonar.sourceEncoding", "UTF-8" + property "sonar.projectKey", "datahub-project_datahub" + property "sonar.organization", "datahub-project" + property "sonar.host.url", "https://sonarcloud.io" + property "sonar.coverage.jacoco.xmlReportPaths", "$projectDir.parentFile.path/build/reports/jacoco/test/jacocoTestReport.xml" + + property "sonar.python.coverage.reportPaths", "https://sonarcloud.io" + } +} + allprojects { apply plugin: 'idea' apply plugin: 'eclipse' @@ -379,6 +392,7 @@ subprojects { apply plugin: 'com.gorylenko.gradle-git-properties' apply plugin: 'com.diffplug.spotless' apply plugin: 'jacoco' + apply plugin: 'org.sonarqube' if (!project.name.contains('docker') && !project.name.contains('web-react') @@ -472,6 +486,13 @@ subprojects { } } + sonarqube { + properties { + property "sonar.coverage.jacoco.xmlReportPaths", "$projectDir.parentFile.path/build/reports/jacoco/test/jacocoTestReport.xml" + p + } + } + if (project.plugins.hasPlugin('pegasus')) { dependencies { dataTemplateCompile spec.product.pegasus.data diff --git a/sonar-project.properties b/sonar-project.properties new file mode 100644 index 00000000000000..07e11330106f43 --- /dev/null +++ b/sonar-project.properties @@ -0,0 +1,4 @@ +sonar.projectKey=datahub-project_datahub +sonar.sources=. +sonar.organization=datahub-project +sonar.host.url=https://sonarcloud.io